Skip to content

Commit e619b63

Browse files
authored
GH Actions: bust the cache semi-regularly (#284)
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 Co-authored-by: jrfnl <jrfnl@users.noreply.github.com>
1 parent 0691145 commit e619b63

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

.github/workflows/csqa.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ jobs:
4343
# @link https://github.com/marketplace/actions/install-composer-dependencies
4444
- name: Install Composer dependencies
4545
uses: "ramsey/composer-install@v2"
46+
with:
47+
# Bust the cache at least once a month - output format: YYYY-MM-DD.
48+
custom-cache-suffix: $(date -u -d "-0 month -$(($(date +%d)-1)) days" "+%F")
4649

4750
- name: Install xmllint
4851
run: |
@@ -90,6 +93,9 @@ jobs:
9093
# @link https://github.com/marketplace/actions/install-composer-dependencies
9194
- name: Install Composer dependencies
9295
uses: "ramsey/composer-install@v2"
96+
with:
97+
# Bust the cache at least once a month - output format: YYYY-MM-DD.
98+
custom-cache-suffix: $(date -u -d "-0 month -$(($(date +%d)-1)) days" "+%F")
9399

94100
- name: Run Static Analysis
95101
run: composer static-analysis

.github/workflows/test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,17 @@ jobs:
8989
- name: Install Composer dependencies - normal
9090
if: ${{ matrix.php != '8.2' }}
9191
uses: "ramsey/composer-install@v2"
92+
with:
93+
# Bust the cache at least once a month - output format: YYYY-MM-DD.
94+
custom-cache-suffix: $(date -u -d "-0 month -$(($(date +%d)-1)) days" "+%F")
9295

9396
# For the PHP "nightly", we need to install with ignore platform reqs as not all dependencies allow it yet.
9497
- name: Install Composer dependencies - with ignore platform
9598
if: ${{ matrix.php == '8.2' }}
9699
uses: "ramsey/composer-install@v2"
97100
with:
98101
composer-options: --ignore-platform-req=php
102+
custom-cache-suffix: $(date -u -d "-0 month -$(($(date +%d)-1)) days" "+%F")
99103

100104
- name: Run the unit tests
101105
run: composer test
@@ -153,6 +157,9 @@ jobs:
153157
154158
- name: Install Composer dependencies
155159
uses: "ramsey/composer-install@v2"
160+
with:
161+
# Bust the cache at least once a month - output format: YYYY-MM-DD.
162+
custom-cache-suffix: $(date -u -d "-0 month -$(($(date +%d)-1)) days" "+%F")
156163

157164
- name: Grab PHPUnit version
158165
id: phpunit_version

0 commit comments

Comments
 (0)