Skip to content

Commit

Permalink
Add package caching
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
me-and committed Jan 11, 2023
1 parent db47559 commit 87d0741
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,34 @@ jobs:
shell: bash
env:
SHELLOPTS: igncr

caching:
runs-on: windows-latest

name: 'Test use of the cache'

steps:
- run: git config --global core.autocrlf input
- uses: actions/checkout@v2
- name: Install Cygwin and bash-completion
uses: ./
with:
packages: bash-completion
package-cache-key: testing-cache
add-to-path: false
- name: Delete Cygwin installation and cache
run: |
Remove-Item -Force -Recurse C:\cygwin
Remove-Item -Force -Recurse C:\cygwin-packages
- name: Reinstall Cygwin only
uses: ./
with:
package-cache-key: testing-cache
add-to-path: false
- name: Find bash-completion in the package cache
shell: C:\cygwin\bin\bash.exe --noprofile --norc -e -o pipefail -o igncr {0}
run: |
for file in /cygdrive/c/cygwin-packages/*/*/*/bash-completion/bash-completion-*.tar.*; do
[[ -f "$file" ]] && exit 0 # File actually exists
done
exit 1 # No such downloaded file
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Parameters
| site | http://mirrors.kernel.org/sourceware/cygwin/ | Mirror site to install from
| check-sig | true | Whether to check the setup.ini signature
| add-to-path | true | Whether to add Cygwin's `/bin` directory to the system `PATH`
| package-cache-key | '' | The key to use for caching downloaded packages.

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

Caching
-------

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

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

This has the effect of speeding up the run of the installation itself, at the
expense of taking slightly longer before and after the installation to check
and potentially update the cache. The installer will still check for updated
packages, and will download new packages if the cached ones are out of date

Mirrors and signatures
----------------------

Expand Down
49 changes: 49 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,39 @@ inputs:
description: Should Cygwin's bin directory be added to the system PATH?
required: false
default: true
package-cache-key:
description: Key prefix to use for package caches
required: false
default: ''

runs:
using: "composite"
steps:
# Get the path to Git Bash, so we can confidently run that later
# regardless of whether Cygwin Bash is in the PATH.
- if: inputs.cache != 'disabled'
shell: pwsh
run: Write-Output "GIT_BASH_PATH=$($(Get-Command bash).Source)" >> $Env:GITHUB_ENV

- uses: actions/cache/restore@v3
if: inputs.package-cache-key != ''
with:
key: ${{ inputs.package-cache-key }}-${{ github.run_id }}-${{ github.run_attempt }}
path: C:\cygwin-packages
restore-keys:
${{ inputs.package-cache-key }}-${{ github.run_id }}-
${{ inputs.package-cache-key }}-

- if: inputs.package-cache-key != ''
working-directory: C:\
shell: ${{ env.GIT_BASH_PATH }} --noprofile --norc -eo pipefail {0}
run: |
if [[ -d cygwin-packages ]]; then
find cygwin-packages -type f ! -name setup.ini -print0 |
sort -z |
xargs -0 b2sum >cygwin-packages-checksum.old
fi
- run: |
$platform = '${{ inputs.platform }}'
$platform = $platform -replace '^(x64|amd64)$', 'x86_64'
Expand Down Expand Up @@ -82,6 +111,26 @@ runs:
& C:\setup.exe $args | Out-Default
shell: powershell
- if: inputs.package-cache-key != ''
id: refresh-cache
working-directory: C:\
shell: ${{ env.GIT_BASH_PATH }} --noprofile --norc -eo pipefail {0}
run: |
if [[ -d cygwin-packages ]]; then
find cygwin-packages -type f ! -name setup.ini -print0 |
sort -z |
xargs -0 b2sum >cygwin-packages-checksum.new
if ! diff cygwin-packages-checksum.old cygwin-packages-checksum.new; then
printf 'update_package_cache=YesPlease\n' >>"$GITHUB_OUTPUT"
fi
fi
- if: steps.refresh-cache.outputs.update_package_cache != ''
uses: actions/cache/save@v3
with:
key: ${{ inputs.package-cache-key }}-${{ github.run_id }}-${{ github.run_attempt }}
path: C:\cygwin-packages

- if: ${{ inputs.add-to-path == 'true' }}
run: echo "${{ inputs.install-dir }}\bin" >> $env:GITHUB_PATH
shell: powershell
Expand Down

0 comments on commit 87d0741

Please sign in to comment.