Skip to content

Commit 1d43a6b

Browse files
committed
Add package caching
To speed up Cygwin installations, allow users to store the downloaded packages using GitHub's caching, rather than needing the packages to be downloaded from the Cygwin mirrors on every run. This speeds up the installation when there's a good cache hit, at the expense of adding some additional complexity, and using the limited cache space (although with 10GB assigned to every repository on GitHub, I can't imagine most folk are getting close to the limit!). To avoid unnecessary cache churn, the new steps check if the cache has actually meaningfully changed before storing a new cache. This uses b2sum for speed, since we're just checking for unexpected changes in the cache, and we don't need cryptographic security.
1 parent db47559 commit 1d43a6b

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

.github/workflows/test.yml

+31
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,34 @@ jobs:
228228
shell: bash
229229
env:
230230
SHELLOPTS: igncr
231+
232+
caching:
233+
runs-on: windows-latest
234+
235+
name: 'Test use of the cache'
236+
237+
steps:
238+
- run: git config --global core.autocrlf input
239+
- uses: actions/checkout@v2
240+
- name: Install Cygwin and bash-completion
241+
uses: ./
242+
with:
243+
packages: bash-completion
244+
package-cache-key: testing-cache
245+
add-to-path: false
246+
- name: Delete Cygwin installation and cache
247+
run: |
248+
Remove-Item -Force -Recurse C:\cygwin
249+
Remove-Item -Force -Recurse C:\cygwin-packages
250+
- name: Reinstall Cygwin only
251+
uses: ./
252+
with:
253+
package-cache-key: testing-cache
254+
add-to-path: false
255+
- name: Find bash-completion in the package cache
256+
shell: C:\cygwin\bin\bash.exe --noprofile --norc -e -o pipefail -o igncr {0}
257+
run: |
258+
for file in /cygdrive/c/cygwin-packages/*/*/*/bash-completion/bash-completion-*.tar.*; do
259+
[[ -f "$file" ]] && exit 0 # File actually exists
260+
done
261+
exit 1 # No such downloaded file

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -26,6 +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.
2930

3031
Line endings
3132
------------
@@ -85,6 +86,22 @@ those executables directly in a `run:` in your workflow. Execute them via
8586
Alternatively, putting e.g. `CYGWIN=winsymlinks:native` into the workflow's
8687
environment works, since setup now honours that.
8788

89+
Caching
90+
-------
91+
92+
If you're likely to do regular builds, you might want to store the packages
93+
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.
97+
98+
[0]: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows
99+
100+
This has the effect of speeding up the run of the installation itself, at the
101+
expense of taking slightly longer before and after the installation to check
102+
and potentially update the cache. The installer will still check for updated
103+
packages, and will download new packages if the cached ones are out of date
104+
88105
Mirrors and signatures
89106
----------------------
90107

action.yml

+43
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,33 @@ 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
31+
required: false
32+
default: ''
2933

3034
runs:
3135
using: "composite"
3236
steps:
37+
- uses: actions/cache/restore@v3
38+
if: inputs.package-cache-key != ''
39+
with:
40+
key: ${{ inputs.package-cache-key }}-${{ github.run_id }}-${{ github.run_attempt }}
41+
path: C:\cygwin-packages
42+
restore-keys:
43+
${{ inputs.package-cache-key }}-${{ github.run_id }}-
44+
${{ inputs.package-cache-key }}-
45+
46+
- if: inputs.package-cache-key != ''
47+
working-directory: C:\
48+
shell: bash
49+
run: |
50+
if [[ -d cygwin-packages ]]; then
51+
find cygwin-packages -type f ! -name setup.ini -print0 |
52+
sort -z |
53+
xargs -0 b2sum >cygwin-packages-checksum.old
54+
fi
55+
3356
- run: |
3457
$platform = '${{ inputs.platform }}'
3558
$platform = $platform -replace '^(x64|amd64)$', 'x86_64'
@@ -82,6 +105,26 @@ runs:
82105
& C:\setup.exe $args | Out-Default
83106
shell: powershell
84107
108+
- if: inputs.package-cache-key != ''
109+
id: refresh-cache
110+
working-directory: C:\
111+
shell: bash
112+
run: |
113+
if [[ -d cygwin-packages ]]; then
114+
find cygwin-packages -type f ! -name setup.ini -print0 |
115+
sort -z |
116+
xargs -0 b2sum >cygwin-packages-checksum.new
117+
if ! diff cygwin-packages-checksum.old cygwin-packages-checksum.new; then
118+
printf 'update_package_cache=YesPlease\n' >>"$GITHUB_OUTPUT"
119+
fi
120+
fi
121+
122+
- if: steps.refresh-cache.outputs.update_package_cache != ''
123+
uses: actions/cache/save@v3
124+
with:
125+
key: ${{ inputs.package-cache-key }}-${{ github.run_id }}-${{ github.run_attempt }}
126+
path: C:\cygwin-packages
127+
85128
- if: ${{ inputs.add-to-path == 'true' }}
86129
run: echo "${{ inputs.install-dir }}\bin" >> $env:GITHUB_PATH
87130
shell: powershell

0 commit comments

Comments
 (0)