Skip to content

Commit c71f0b0

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 1d43a6b commit c71f0b0

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,24 +26,26 @@ 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"
3636
steps:
3737
- uses: actions/cache/restore@v3
38-
if: inputs.package-cache-key != ''
38+
if: inputs.cache == 'enabled' || inputs.cache == 'restoreonly'
3939
with:
40-
key: ${{ inputs.package-cache-key }}-${{ github.run_id }}-${{ github.run_attempt }}
40+
key: cygwin-install-action-packages-${{ github.run_id }}-${{ github.run_attempt }}-${{ github.job }}-${{ github.action }}
4141
path: C:\cygwin-packages
4242
restore-keys:
43-
${{ inputs.package-cache-key }}-${{ github.run_id }}-
44-
${{ inputs.package-cache-key }}-
43+
cygwin-install-action-packages-${{ github.run_id }}-${{ github.job }}-${{ github.run_attempt }}-
44+
cygwin-install-action-packages-${{ github.run_id }}-${{ github.job }}-
45+
cygwin-install-action-packages-${{ github.run_id }}-
46+
cygwin-install-action-packages-
4547

46-
- if: inputs.package-cache-key != ''
48+
- if: inputs.cache == 'enabled' || inputs.cache == 'restoreonly'
4749
working-directory: C:\
4850
shell: bash
4951
run: |
@@ -105,7 +107,7 @@ runs:
105107
& C:\setup.exe $args | Out-Default
106108
shell: powershell
107109
108-
- if: inputs.package-cache-key != ''
110+
- if: inputs.cache == 'enabled' || inputs.cache == 'saveonly'
109111
id: refresh-cache
110112
working-directory: C:\
111113
shell: bash
@@ -122,7 +124,7 @@ runs:
122124
- if: steps.refresh-cache.outputs.update_package_cache != ''
123125
uses: actions/cache/save@v3
124126
with:
125-
key: ${{ inputs.package-cache-key }}-${{ github.run_id }}-${{ github.run_attempt }}
127+
key: cygwin-install-action-packages-${{ github.run_id }}-${{ github.run_attempt }}-${{ github.job }}-${{ github.action }}
126128
path: C:\cygwin-packages
127129

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

0 commit comments

Comments
 (0)