Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
box

GitHub Action

Cache PHP Extensions

1.6.1

Cache PHP Extensions

box

Cache PHP Extensions

Cache PHP Extensions in GitHub Actions

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Cache PHP Extensions

uses: shivammathur/[email protected]

Learn more about this action in shivammathur/cache-extensions

Choose a version

Cache PHP extensions in GitHub Actions

GitHub Actions status Codecov Code Coverage LICENSE PHP Versions Supported

Cache PHP extensions in GitHub Actions. This action has to be used along with shivammathur/setup-php and actions/cache GitHub Actions. It configures the environment required to cache PHP extensions. Refer to Usage section for details and example workflow.

Contents

๐ŸŽ‰ PHP Support

PHP Version Stability Release Support
5.3 Stable End of life
5.4 Stable End of life
5.5 Stable End of life
5.6 Stable End of life
7.0 Stable End of life
7.1 Stable End of life
7.2 Stable End of life
7.3 Stable Security fixes only
7.4 Stable Active
8.0 Stable Active
8.1 Nightly In development
8.2 Nightly In development

โ˜๏ธ OS/Platform Support

Virtual environment YAML workflow label
Ubuntu 20.04 ubuntu-latest or ubuntu-20.04
Ubuntu 18.04 ubuntu-18.04
Ubuntu 16.04 ubuntu-16.04
Windows Server 2022 windows-2022
Windows Server 2019 windows-latest or windows-2019
macOS Catalina 10.15 macos-latest or macOS-10.15
macOS Big Sur 11.x macOS-11

๐Ÿ“ Usage

Use this GitHub Action when the extensions you are adding in setup-php are installed and take a long time to set up. If you are using extensions which have the result Installed and enabled in the logs like pecl extensions on Ubuntu or extensions which have custom support, it is recommended to use this action to cache your extensions.

Inputs

php-version (required)

  • Specify the PHP version you want to set up.
  • Accepts a string. For example '8.0'.
  • Accepts latest to set up the latest stable PHP version.
  • Accepts nightly to set up a nightly build from the master branch of PHP.
  • Accepts the format d.x, where d is the major version. For example 5.x, 7.x and 8.x.
  • See PHP support for supported PHP versions.

extensions (required)

  • Specify the extensions you want to set up.
  • Accepts a string in csv-format. For example mbstring, xdebug, :opcache.
  • Extensions prefixed with : are ignored in output cache key.

key (required)

  • Specify the key to identify the cache version.
  • Accepts any string. For example cache-v1.
  • Changing this would reset the cache.

See action.yml and usage below for more info.

Workflow

Cache extensions in a PHP workflow

jobs:
  run:
    runs-on: ${{ matrix.operating-system }}
    strategy:
      matrix:
        operating-system: [ubuntu-latest, windows-latest, macos-latest]
        php-versions: ['7.2', '7.3', '7.4']
    name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
    env:
      extensions: intl, pcov
      key: cache-v1 # can be any string, change to clear the extension cache.
    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: Setup cache environment
      id: extcache
      uses: shivammathur/cache-extensions@v1
      with:
        php-version: ${{ matrix.php-versions }}
        extensions: ${{ env.extensions }}
        key: ${{ env.key }}

    - name: Cache extensions
      uses: actions/cache@v2
      with:
        path: ${{ steps.extcache.outputs.dir }}
        key: ${{ steps.extcache.outputs.key }}
        restore-keys: ${{ steps.extcache.outputs.key }}

    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: ${{ matrix.php-versions }}
        extensions: ${{ env.extensions }}

Thread Safe Setup

If you set up both TS and NTS PHP versions on Windows in your workflow, please add ${{ env.phpts }} to key and restore-keys inputs in actions/cache step in the above workflow to avoid a conflicting cache.

- name: Cache extensions
  uses: actions/cache@v2
  with:
    path: ${{ steps.extcache.outputs.dir }}
    key: ${{ steps.extcache.outputs.key }}-${{ env.phpts }}
    restore-keys: ${{ steps.extcache.outputs.key }}-${{ env.phpts }}

๐Ÿ“œ License

The scripts and documentation in this project are under the MIT License. This project has multiple dependencies. Their licenses can be found in their respective repositories.

๐Ÿ‘ Contributions

Contributions are welcome! See Contributor's Guide. If you face any issues while using this or want to suggest a feature/improvement, create an issue here.

๐Ÿ’– Support This Project

If this action helped you.

  • Please star the project and share it. If you blog, please share your experience of using this action.
  • Please consider supporting our work by sponsoring using GitHub sponsors.

๐Ÿ“ฆ Dependencies