Skip to content

Commit 149b61d

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 149b61d

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-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

+48
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,38 @@ 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+
# Get the path to Git Bash, so we can confidently run that later
38+
# regardless of whether Cygwin Bash is in the PATH.
39+
- if: inputs.cache != 'disabled'
40+
run: Write-Output "GIT_BASH_PATH=$($(Get-Command git).Source)" >> $Env:GITHUB_ENV
41+
42+
- uses: actions/cache/restore@v3
43+
if: inputs.package-cache-key != ''
44+
with:
45+
key: ${{ inputs.package-cache-key }}-${{ github.run_id }}-${{ github.run_attempt }}
46+
path: C:\cygwin-packages
47+
restore-keys:
48+
${{ inputs.package-cache-key }}-${{ github.run_id }}-
49+
${{ inputs.package-cache-key }}-
50+
51+
- if: inputs.package-cache-key != ''
52+
working-directory: C:\
53+
shell: ${{ env.GIT_BASH_PATH }} --noprofile --norc -eo pipefail {0}
54+
run: |
55+
if [[ -d cygwin-packages ]]; then
56+
find cygwin-packages -type f ! -name setup.ini -print0 |
57+
sort -z |
58+
xargs -0 b2sum >cygwin-packages-checksum.old
59+
fi
60+
3361
- run: |
3462
$platform = '${{ inputs.platform }}'
3563
$platform = $platform -replace '^(x64|amd64)$', 'x86_64'
@@ -82,6 +110,26 @@ runs:
82110
& C:\setup.exe $args | Out-Default
83111
shell: powershell
84112
113+
- if: inputs.package-cache-key != ''
114+
id: refresh-cache
115+
working-directory: C:\
116+
shell: ${{ env.GIT_BASH_PATH }} --noprofile --norc -eo pipefail {0}
117+
run: |
118+
if [[ -d cygwin-packages ]]; then
119+
find cygwin-packages -type f ! -name setup.ini -print0 |
120+
sort -z |
121+
xargs -0 b2sum >cygwin-packages-checksum.new
122+
if ! diff cygwin-packages-checksum.old cygwin-packages-checksum.new; then
123+
printf 'update_package_cache=YesPlease\n' >>"$GITHUB_OUTPUT"
124+
fi
125+
fi
126+
127+
- if: steps.refresh-cache.outputs.update_package_cache != ''
128+
uses: actions/cache/save@v3
129+
with:
130+
key: ${{ inputs.package-cache-key }}-${{ github.run_id }}-${{ github.run_attempt }}
131+
path: C:\cygwin-packages
132+
85133
- if: ${{ inputs.add-to-path == 'true' }}
86134
run: echo "${{ inputs.install-dir }}\bin" >> $env:GITHUB_PATH
87135
shell: powershell

0 commit comments

Comments
 (0)