Skip to content

Commit c6845e7

Browse files
committed
Allow save-only/restore-only cache runs
Add an option to restore a cache without creating a new one, or to create a cache without restoring an old one. This is useful in the scenario where the action is called multiple times in a run, as it allows the cache to only be restored on the first call, and for a new cache to only be written on the last call. This option replaces the `package-cache-key` option; as discussed in cygwin#6 that option isn't very useful. Additionally, add some more scopes to the cache name. Without this change, a second attempt to create a cache in the same action run (e.g. because one step installs some packages, then another step installs some more) will fail because of the cache name collision. Also update the README and tests, although the tests are only getting a very quick update for this function, as I'm going to do a much more comprehensive test update separately.
1 parent 149b61d commit c6845e7

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

.github/workflows/test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ jobs:
241241
uses: ./
242242
with:
243243
packages: bash-completion
244-
package-cache-key: testing-cache
244+
cache: enabled
245245
add-to-path: false
246246
- name: Delete Cygwin installation and cache
247247
run: |
@@ -250,7 +250,7 @@ jobs:
250250
- name: Reinstall Cygwin only
251251
uses: ./
252252
with:
253-
package-cache-key: testing-cache
253+
cache: enabled
254254
add-to-path: false
255255
- name: Find bash-completion in the package cache
256256
shell: C:\cygwin\bin\bash.exe --noprofile --norc -e -o pipefail -o igncr {0}

README.md

+22-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Parameters
2626
| site | http://mirrors.kernel.org/sourceware/cygwin/ | Mirror site to install from
2727
| check-sig | true | Whether to check the setup.ini signature
2828
| add-to-path | true | Whether to add Cygwin's `/bin` directory to the system `PATH`
29-
| package-cache-key | '' | The key to use for caching downloaded packages.
29+
| cache | disabled | Whether to cache the package downloads
3030

3131
Line endings
3232
------------
@@ -91,9 +91,8 @@ Caching
9191

9292
If you're likely to do regular builds, you might want to store the packages
9393
locally rather than needing to download them from the Cygwin mirrors on every
94-
build. Set `package-cache-key` to some string (e.g. `cygwin-package-cache`),
95-
and the action will use [GitHub's dependency caching][0] to store downloaded
96-
package files between runs.
94+
build. Set `cache` to `enabled` and the action will use [GitHub's dependency
95+
caching][0] to store downloaded package files between runs.
9796

9897
[0]: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows
9998

@@ -102,6 +101,25 @@ expense of taking slightly longer before and after the installation to check
102101
and potentially update the cache. The installer will still check for updated
103102
packages, and will download new packages if the cached ones are out of date
104103

104+
In certain circumstances you might want to ignore any existing caches but still
105+
store a new one, or restore a cache but not write one. Do this by setting
106+
`cache` to `saveonly` or `restoreonly` as appropriate. This is particularly
107+
useful when calling the action multiple times in the same run, where you
108+
probably want to restore the cache the first time the action is called, then
109+
save it the last time it is called.
110+
111+
You should make sure to clear these caches every so often. This action, like
112+
the underlying Cygwin installer, doesn't remove old package files from its
113+
download directory, so if you don't clear the caches occasionally (and you run
114+
builds often enough that GitHub doesn't do it for you automatically) you'll
115+
find the caches keep getting larger as they gain more and more outdated and
116+
unused packages. Either [delete them manually][1], [use a separate action or
117+
API call][2], or do occasional runs with `saveonly` to create a fresher small
118+
cache.
119+
120+
[1]: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#deleting-cache-entries
121+
[2]: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#deleting-cache-entries
122+
105123
Mirrors and signatures
106124
----------------------
107125

action.yml

+12-10
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ inputs:
2626
description: Should Cygwin's bin directory be added to the system PATH?
2727
required: false
2828
default: true
29-
package-cache-key:
30-
description: Key prefix to use for package caches
29+
cache:
30+
description: Cache package downloads for speed
3131
required: false
32-
default: ''
32+
default: disabled
3333

3434
runs:
3535
using: "composite"
@@ -40,15 +40,17 @@ runs:
4040
run: Write-Output "GIT_BASH_PATH=$($(Get-Command git).Source)" >> $Env:GITHUB_ENV
4141

4242
- uses: actions/cache/restore@v3
43-
if: inputs.package-cache-key != ''
43+
if: inputs.cache == 'enabled' || inputs.cache == 'restoreonly'
4444
with:
45-
key: ${{ inputs.package-cache-key }}-${{ github.run_id }}-${{ github.run_attempt }}
45+
key: cygwin-install-action-packages-${{ github.run_id }}-${{ github.run_attempt }}-${{ github.job }}-${{ github.action }}
4646
path: C:\cygwin-packages
4747
restore-keys:
48-
${{ inputs.package-cache-key }}-${{ github.run_id }}-
49-
${{ inputs.package-cache-key }}-
48+
cygwin-install-action-packages-${{ github.run_id }}-${{ github.job }}-${{ github.run_attempt }}-
49+
cygwin-install-action-packages-${{ github.run_id }}-${{ github.job }}-
50+
cygwin-install-action-packages-${{ github.run_id }}-
51+
cygwin-install-action-packages-
5052

51-
- if: inputs.package-cache-key != ''
53+
- if: inputs.cache == 'enabled' || inputs.cache == 'restoreonly'
5254
working-directory: C:\
5355
shell: ${{ env.GIT_BASH_PATH }} --noprofile --norc -eo pipefail {0}
5456
run: |
@@ -110,7 +112,7 @@ runs:
110112
& C:\setup.exe $args | Out-Default
111113
shell: powershell
112114
113-
- if: inputs.package-cache-key != ''
115+
- if: inputs.cache == 'enabled' || inputs.cache == 'saveonly'
114116
id: refresh-cache
115117
working-directory: C:\
116118
shell: ${{ env.GIT_BASH_PATH }} --noprofile --norc -eo pipefail {0}
@@ -127,7 +129,7 @@ runs:
127129
- if: steps.refresh-cache.outputs.update_package_cache != ''
128130
uses: actions/cache/save@v3
129131
with:
130-
key: ${{ inputs.package-cache-key }}-${{ github.run_id }}-${{ github.run_attempt }}
132+
key: cygwin-install-action-packages-${{ github.run_id }}-${{ github.run_attempt }}-${{ github.job }}-${{ github.action }}
131133
path: C:\cygwin-packages
132134

133135
- if: ${{ inputs.add-to-path == 'true' }}

0 commit comments

Comments
 (0)