File tree Expand file tree Collapse file tree 6 files changed +97
-3
lines changed
Expand file tree Collapse file tree 6 files changed +97
-3
lines changed Original file line number Diff line number Diff line change @@ -218,6 +218,18 @@ jobs:
218218 dependency-versions : " ${{ matrix.dependency-versions }}"
219219 custom-cache-key : ' my-super-custom-cache-key'
220220
221+ - name : Clean up between tests
222+ run : |
223+ git clean -ffdx && git reset --hard HEAD
224+ composer clear-cache
225+
226+ - name : " Test: custom cache suffix"
227+ uses : ./
228+ with :
229+ working-directory : " ${{ matrix.working-directory }}"
230+ dependency-versions : " ${{ matrix.dependency-versions }}"
231+ custom-cache-suffix : $(/bin/date -u --date='last Mon' "+%F")
232+
221233 run-no-cleanup :
222234 needs : test
223235 name : " Run unclean"
Original file line number Diff line number Diff line change @@ -148,6 +148,32 @@ wish to update the cache.
148148 custom-cache-key: "my-custom-cache-key"
149149` ` `
150150
151+ # ### custom-cache-suffix
152+
153+ ` ramsey/composer-install` will auto-generate a cache key which is composed of
154+ the following elements :
155+ * The OS image name, like `ubuntu-latest`.
156+ * The exact PHP version, like `8.1.11`.
157+ * The options passed via `composer-options`.
158+ * The dependency version setting as per `dependency-versions`.
159+ * The working directory as per `working-directory`.
160+ * A hash of the `composer.json` and/or `composer.lock` files.
161+
162+ If you don't want to generate your own cache key, but do want to make the cache key
163+ even more specific, you can specify a suffix to be added to the cache key via the
164+ ` custom-cache-suffix` parameter.
165+
166+ ` ` ` yaml
167+ # Adds a suffix to the cache key which is equivalent to the full date-time
168+ # of "last Monday 00:00", which means that the cache will be force refreshed
169+ # via the first workflow which is run every Monday.
170+ - uses: "ramsey/composer-install@v2"
171+ with:
172+ custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F")
173+ ` ` `
174+
175+ :warning : Note: specifying a `custom-cache-key` will take precedence over the `custom-cache-suffix`.
176+
151177# ## Matrix Example
152178
153179GitHub Workflows allow you to set up a [job matrix](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix),
Original file line number Diff line number Diff line change @@ -30,6 +30,10 @@ inputs:
3030 description : >-
3131 A custom cache key to use instead of an auto-generated cache key.
3232 required : false
33+ custom-cache-suffix :
34+ description : >-
35+ A custom suffix to add to the auto-generated cache key.
36+ required : false
3337
3438runs :
3539 using : " composite"
6670 "${{ inputs.composer-options }}" \
6771 "${{ hashFiles('**/composer.json', '**/composer.lock') }}" \
6872 "${{ inputs.custom-cache-key }}" \
73+ "${{ inputs.custom-cache-suffix }}" \
6974 "${{ inputs.working-directory }}"
7075
7176 - name : " Cache Composer dependencies"
Original file line number Diff line number Diff line change @@ -25,7 +25,8 @@ dependency_versions="${3:-locked}"
2525composer_options=" ${4} "
2626files_hash=" ${5} "
2727custom_cache_key=" ${6} "
28- working_directory=" ${7} "
28+ custom_cache_suffix=" ${7} "
29+ working_directory=" ${8} "
2930
3031key=()
3132restore_key=()
4142if [ -n " ${custom_cache_key} " ]; then
4243 key+=(" ${custom_cache_key} " )
4344else
44- key+=(" ${runner_os} " " php" " ${php_version} " " composer" " ${composer_options} " " ${dependency_versions} " " ${working_directory} " )
45+ key+=(" ${runner_os} " " php" " ${php_version} " " composer" " ${composer_options} " " ${dependency_versions} " " ${working_directory} " " ${custom_cache_suffix} " )
4546
4647 restore_key=(" $( make_key " ${key[@]} " ) -" )
4748
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ set gitHubOutputFile cache_key_output_06.txt
99set ::env(GITHUB_OUTPUT) $gitHubOutputFile
1010
1111set timeout 3
12- spawn ../../bin/cache_key.sh "Linux" "8.1.1" "" "" "long-files-hash" "" "path/to/working/dir"
12+ spawn ../../bin/cache_key.sh "Linux" "8.1.1" "" "" "long-files-hash" "" "" " path/to/working/dir"
1313match_max 100000
1414
1515expect -exact "::debug::Cache primary key is 'Linux-php-8.1.1-composer-locked-path/to/working/dir-long-files-hash'"
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env -S expect -f
2+
3+ # For testing environment variables written to GITHUB_ENV
4+ set gitHubEnvFile cache_key_08.txt
5+ set ::env(GITHUB_ENV) $gitHubEnvFile
6+
7+ # For testing outputs variables written to GITHUB_OUTPUT
8+ set gitHubOutputFile cache_key_output_08.txt
9+ set ::env(GITHUB_OUTPUT) $gitHubOutputFile
10+
11+ set timeout 3
12+ spawn ../../bin/cache_key.sh "Linux" "8.1.12" "lowest" "--ignore-platform-req=php+" "long-files-hash" "" "suffix"
13+ match_max 100000
14+
15+ expect -exact "::debug::Cache primary key is 'Linux-php-8.1.12-composer---ignore-platform-req=php+-lowest-suffix-long-files-hash'"
16+ expect -exact "::debug::Cache restore keys are 'Linux-php-8.1.12-composer---ignore-platform-req=php+-lowest-suffix-'"
17+ expect eof
18+
19+ # Confirm environment variables.
20+ set fp [open $gitHubEnvFile r]
21+ set fileData [read $fp]
22+ close $fp
23+
24+ set expectedValue "CACHE_RESTORE_KEY<<EOF
25+ Linux-php-8.1.12-composer---ignore-platform-req=php+-lowest-suffix-
26+ EOF
27+ "
28+
29+ if { $expectedValue != $fileData } {
30+ puts "\nExpected environment variable does not match. Received:\n"
31+ puts $fileData
32+ exit 1
33+ }
34+
35+ # Verify output variables have been set correctly.
36+ set fp [open $gitHubOutputFile r]
37+ set fileData [read $fp]
38+ close $fp
39+
40+ set expectedValue "key=Linux-php-8.1.12-composer---ignore-platform-req=php+-lowest-suffix-long-files-hash\n"
41+
42+ if { $expectedValue != $fileData } {
43+ puts "\nExpected output variable does not match. Received:\n"
44+ puts $fileData
45+ exit 1
46+ }
47+
48+ # Clean up
49+ file delete $gitHubEnvFile
50+ file delete $gitHubOutputFile
You can’t perform that action at this time.
0 commit comments