-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test.yml: use a digest of image in template as key for cache
This should reduce the cache size used by the CI. Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
- Loading branch information
1 parent
3075bd9
commit ec43bfb
Showing
3 changed files
with
81 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: 'setup cache for template' | ||
description: 'setup cache for template' | ||
inputs: | ||
arch: | ||
description: arch to setup cache for | ||
required: false | ||
template: | ||
description: template yaml file | ||
required: true | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: "detect platform for download directory" | ||
id: detect-platform | ||
run: | | ||
if [[ "$(uname)" == "Darwin" ]]; then | ||
download_dir=~/Library/Caches/lima/download | ||
else | ||
download_dir=~/.cache/lima/download | ||
fi | ||
echo "download-dir=$download_dir" >> "$GITHUB_OUTPUT" | ||
shell: bash | ||
- name: "extract key from template" | ||
if: always() | ||
id: extract-key-from-template | ||
run: | | ||
set -eux | ||
arch="${{ inputs.arch }}" | ||
template="${{ inputs.template }}" | ||
test -f "$template" || exit 1 | ||
# detect arch from template if not provided | ||
arch="${arch:-$(yq '.arch // ""' "$template")}" | ||
arch="${arch:-$(uname -m)}" | ||
# normalize arch. amd64 -> x86_64, arm64 -> aarch64 | ||
case "$arch" in | ||
amd64) arch=x86_64 ;; | ||
arm64) arch=aarch64 ;; | ||
esac | ||
# extract digest from template using arch | ||
digest="$(yq ".images | map(select(.arch == \"$arch\")) | .[0].digest // \"\"" "$template")" | ||
# fallback to os and hash of template file if digest not found | ||
key="${digest:+image-$digest}" | ||
key="${key:-${{ runner.os }}-${{ hashFiles(inputs.template) }}}" | ||
echo "key=$key" >> "$GITHUB_OUTPUT" | ||
shell: bash | ||
- name: "Cache .download" | ||
# avoid using `~` in path that will be expanded to platform specific home directory | ||
uses: actions/cache@v4 | ||
with: | ||
path: .download | ||
key: ${{ steps.extract-key-from-template.outputs.key }} | ||
enableCrossOsArchive: true | ||
- name: "Create symbolic link named ${{ steps.detect-platform.outputs.download-dir }} pointing to .download" | ||
run: | | ||
set -eux | ||
[ -d .download ] || mkdir -p .download | ||
path_to_cache=${{ steps.detect-platform.outputs.download-dir }} | ||
mkdir -p $(dirname $path_to_cache) | ||
ln -sfn $PWD/.download $path_to_cache | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters