Home

Awesome

<h1 align="center">Cache PHP extensions in GitHub Actions</h1> <p align="center"> <a href="https://github.com/shivammathur/cache-extensions" title="Cache PHP extensions in GitHub Actions"><img alt="GitHub Actions status" src="https://github.com/shivammathur/cache-extensions/workflows/Node%20test%20workflow/badge.svg"></a> <a href="https://codecov.io/gh/shivammathur/cache-extensions" title="Code coverage"><img alt="Codecov Code Coverage" src="https://codecov.io/gh/shivammathur/cache-extensions/branch/master/graph/badge.svg"></a> <a href="https://github.com/shivammathur/cache-extensions/blob/master/LICENSE" title="license"><img alt="LICENSE" src="https://img.shields.io/badge/license-MIT-428f7e.svg?logo=open%20source%20initiative&logoColor=white&labelColor=555555"></a> <a href="#tada-php-support" title="PHP Versions Supported"><img alt="PHP Versions Supported" src="https://img.shields.io/badge/php-5.3%20to%208.4-777bb3.svg?logo=php&logoColor=white&labelColor=555555"></a> </p>

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

:tada: PHP Support

PHP VersionStabilityRelease Support
5.3StableEnd of life
5.4StableEnd of life
5.5StableEnd of life
5.6StableEnd of life
7.0StableEnd of life
7.1StableEnd of life
7.2StableEnd of life
7.3StableEnd of life
7.4StableEnd of life
8.0StableEnd of life
8.1StableSecurity fixes only
8.2StableActive
8.3StableActive
8.4NightlyIn development

:cloud: OS/Platform Support

Virtual environmentYAML workflow label
Ubuntu 24.04ubuntu-24.04
Ubuntu 22.04ubuntu-latest or ubuntu-22.04
Ubuntu 20.04ubuntu-20.04
Windows Server 2022windows-latest or windows-2022
Windows Server 2019windows-2019
macOS Sequoia 15.xmacos-15
macOS Sonoma 14.xmacos-latest or macos-14
macOS Ventura 13.xmacos-13

Note: Support for self-hosted runners for the above operating systems is in beta. If you use this action on a self-hosted runner, please report any issues you find.

:memo: 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 (optional)

php-version-file (optional)

extensions (required)

key (required)

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: ['8.1', '8.2', '8.3']
    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@v4

    - 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@v4
      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 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@v4
  with:
    path: ${{ steps.extcache.outputs.dir }}
    key: ${{ steps.extcache.outputs.key }}-${{ env.phpts }}
    restore-keys: ${{ steps.extcache.outputs.key }}-${{ env.phpts }}

:scroll: License

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

:+1: 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.

:sparkling_heart: Support This Project

This project is generously supported by many users and organisations via GitHub Sponsors.

<a href="https://github.com/sponsors/shivammathur"><img src="https://setup-php.com/sponsors.svg?" alt="Sponsor shivammathur"></a>

:package: Dependencies