Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d463a5e

Browse files
committedJan 11, 2023
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 d463a5e

File tree

3 files changed

+97
-0
lines changed

3 files changed

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

+49
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,39 @@ 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+
shell: pwsh
41+
run: Write-Output "GIT_BASH_PATH=$($(Get-Command git).Source)" >> $Env:GITHUB_ENV
42+
43+
- uses: actions/cache/restore@v3
44+
if: inputs.package-cache-key != ''
45+
with:
46+
key: ${{ inputs.package-cache-key }}-${{ github.run_id }}-${{ github.run_attempt }}
47+
path: C:\cygwin-packages
48+
restore-keys:
49+
${{ inputs.package-cache-key }}-${{ github.run_id }}-
50+
${{ inputs.package-cache-key }}-
51+
52+
- if: inputs.package-cache-key != ''
53+
working-directory: C:\
54+
shell: ${{ env.GIT_BASH_PATH }} --noprofile --norc -eo pipefail {0}
55+
run: |
56+
if [[ -d cygwin-packages ]]; then
57+
find cygwin-packages -type f ! -name setup.ini -print0 |
58+
sort -z |
59+
xargs -0 b2sum >cygwin-packages-checksum.old
60+
fi
61+
3362
- run: |
3463
$platform = '${{ inputs.platform }}'
3564
$platform = $platform -replace '^(x64|amd64)$', 'x86_64'
@@ -82,6 +111,26 @@ runs:
82111
& C:\setup.exe $args | Out-Default
83112
shell: powershell
84113
114+
- if: inputs.package-cache-key != ''
115+
id: refresh-cache
116+
working-directory: C:\
117+
shell: ${{ env.GIT_BASH_PATH }} --noprofile --norc -eo pipefail {0}
118+
run: |
119+
if [[ -d cygwin-packages ]]; then
120+
find cygwin-packages -type f ! -name setup.ini -print0 |
121+
sort -z |
122+
xargs -0 b2sum >cygwin-packages-checksum.new
123+
if ! diff cygwin-packages-checksum.old cygwin-packages-checksum.new; then
124+
printf 'update_package_cache=YesPlease\n' >>"$GITHUB_OUTPUT"
125+
fi
126+
fi
127+
128+
- if: steps.refresh-cache.outputs.update_package_cache != ''
129+
uses: actions/cache/save@v3
130+
with:
131+
key: ${{ inputs.package-cache-key }}-${{ github.run_id }}-${{ github.run_attempt }}
132+
path: C:\cygwin-packages
133+
85134
- if: ${{ inputs.add-to-path == 'true' }}
86135
run: echo "${{ inputs.install-dir }}\bin" >> $env:GITHUB_PATH
87136
shell: powershell

0 commit comments

Comments
 (0)
Please sign in to comment.