Skip to content

Commit 76e04c7

Browse files
jrfnlgrogy
authored andcommitted
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
1 parent 0176c23 commit 76e04c7

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Diff for: .github/workflows/release.yml

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ jobs:
3939
uses: ramsey/composer-install@v2
4040
with:
4141
composer-options: "--no-dev"
42+
# Bust the cache at least once a month - output format: YYYY-MM.
43+
custom-cache-suffix: $(date -u "+%Y-%m")
4244

4345
# Note: do NOT turn on the requirement checker in the box config as it is no longer
4446
# compatible with PHP < 7.2.

Diff for: .github/workflows/test.yml

+9
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ jobs:
3232

3333
- name: Install Composer dependencies
3434
uses: ramsey/composer-install@v2
35+
with:
36+
# Bust the cache at least once a month - output format: YYYY-MM.
37+
custom-cache-suffix: $(date -u "+%Y-%m")
3538

3639
- name: Run code sniffer
3740
id: phpcs
@@ -63,6 +66,8 @@ jobs:
6366
uses: ramsey/composer-install@v2
6467
with:
6568
composer-options: "--no-dev"
69+
# Bust the cache at least once a month - output format: YYYY-MM.
70+
custom-cache-suffix: $(date -u "+%Y-%m")
6671

6772
# Note: do NOT turn on the requirement checker in the box config as it is no longer
6873
# compatible with PHP < 7.2.
@@ -126,12 +131,16 @@ jobs:
126131
- name: Install Composer dependencies
127132
if: ${{ matrix.php != '8.3' }}
128133
uses: ramsey/composer-install@v2
134+
with:
135+
# Bust the cache at least once a month - output format: YYYY-MM.
136+
custom-cache-suffix: $(date -u "+%Y-%m")
129137

130138
- name: "Install Composer dependencies (PHP 8.3, ignore PHP reqs)"
131139
if: ${{ matrix.php == '8.3' }}
132140
uses: ramsey/composer-install@v2
133141
with:
134142
composer-options: --ignore-platform-req=php
143+
custom-cache-suffix: $(date -u "+%Y-%m")
135144

136145
- name: 'Integration test 1 - linting own code, no colors'
137146
continue-on-error: true

0 commit comments

Comments
 (0)