From 48af24f35371f42b75c87b1a54fe6ae3826642bb Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 4 Nov 2022 19:51:20 +0100 Subject: [PATCH] GH Actions: bust the cache semi-regularly Caches used in GH Actions do not get updated, they can only be replaced by a different cache with a different cache key. Now the predefined Composer install action this repo is using already creates a pretty comprehensive cache key: > `ramsey/composer-install` will auto-generate a cache key which is composed of the following elements: > * The OS image name, like `ubuntu-latest`. > * The exact PHP version, like `8.1.11`. > * The options passed via `composer-options`. > * The dependency version setting as per `dependency-versions`. > * The working directory as per `working-directory`. > * A hash of the `composer.json` and/or `composer.lock` files. This means that aside from other factors, the cache will always be busted when changes are made to the (committed) `composer.json` or the `composer.lock` file (if the latter exists in the repo). For packages running on recent versions of PHP, it also means that the cache will automatically be busted once a month when a new PHP version comes out. ### The problem For runs on older PHP versions which don't receive updates anymore, the cache will not be busted via new PHP version releases, so effectively, the cache will only be busted when a change is made to the `composer.json`/`composer.lock` file - which may not happen that frequently on low-traffic repos. But... packages _in use_ on those older PHP versions - especially dependencies of declared dependencies - may still release new versions and those new versions will not exist in the cache and will need to be downloaded each time the action is run and over time the cache gets less and less relevant as more and more packages will need to be downloaded for each run. ### The solution To combat this issue, a new `custom-cache-suffix` option has been added to the Composer install action in version 2.2.0. This new option allows for providing some extra information to add to the cache key, which allows for busting the cache based on your own additional criteria. This commit implements the use of this `custom-cache-suffix` option for all relevant workflows in this repo. Refs: * https://github.com/ramsey/composer-install/#custom-cache-suffix * https://github.com/ramsey/composer-install/releases/tag/2.2.0 --- .github/workflows/release.yml | 2 ++ .github/workflows/test.yml | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3079e41..1cb77fb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -39,6 +39,8 @@ jobs: uses: ramsey/composer-install@v2 with: composer-options: "--no-dev" + # Bust the cache at least once a month - output format: YYYY-MM. + custom-cache-suffix: $(date -u "+%Y-%m") # Note: do NOT turn on the requirement checker in the box config as it is no longer # compatible with PHP < 7.2. diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2733fe9..7f7433e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,6 +32,9 @@ jobs: - name: Install Composer dependencies uses: ramsey/composer-install@v2 + with: + # Bust the cache at least once a month - output format: YYYY-MM. + custom-cache-suffix: $(date -u "+%Y-%m") - name: Run code sniffer id: phpcs @@ -63,6 +66,8 @@ jobs: uses: ramsey/composer-install@v2 with: composer-options: "--no-dev" + # Bust the cache at least once a month - output format: YYYY-MM. + custom-cache-suffix: $(date -u "+%Y-%m") # Note: do NOT turn on the requirement checker in the box config as it is no longer # compatible with PHP < 7.2. @@ -126,12 +131,16 @@ jobs: - name: Install Composer dependencies if: ${{ matrix.php != '8.3' }} uses: ramsey/composer-install@v2 + with: + # Bust the cache at least once a month - output format: YYYY-MM. + custom-cache-suffix: $(date -u "+%Y-%m") - name: "Install Composer dependencies (PHP 8.3, ignore PHP reqs)" if: ${{ matrix.php == '8.3' }} uses: ramsey/composer-install@v2 with: composer-options: --ignore-platform-req=php + custom-cache-suffix: $(date -u "+%Y-%m") - name: 'Integration test 1 - linting own code, no colors' continue-on-error: true