Skip to content

Commit 726f61d

Browse files
authored
Merge pull request #2508 from norio-nomura/ci-use-digest-of-image-in-template-as-key-for-cache
test.yml: use image cache with parameters created from template
2 parents b3067dc + 5058106 commit 726f61d

File tree

5 files changed

+659
-40
lines changed

5 files changed

+659
-40
lines changed

Diff for: .github/actions/setup_cache_for_template/action.yml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: 'setup cache for template'
2+
description: 'setup cache for template'
3+
inputs:
4+
arch:
5+
description: arch to setup cache for
6+
required: false
7+
template:
8+
description: template yaml file
9+
required: true
10+
runs:
11+
using: "composite"
12+
steps:
13+
- name: "detect platform for download directory"
14+
id: detect-platform
15+
run: |
16+
if [[ "$(uname)" == "Darwin" ]]; then
17+
download_dir=~/Library/Caches/lima/download
18+
else
19+
download_dir=~/.cache/lima/download
20+
fi
21+
echo "download-dir=$download_dir" >> "$GITHUB_OUTPUT"
22+
shell: bash
23+
- name: "create cache parameters from template"
24+
if: always()
25+
id: cache-params-from-template
26+
run: |
27+
set -eux
28+
source hack/cache-common-inc.sh
29+
print_cache_informations_from_template "${{ inputs.template }}" "${{ inputs.arch }}" >> "$GITHUB_OUTPUT"
30+
shell: bash
31+
32+
- name: "Cache ${{ steps.cache-params-from-template.outputs.image-path }}"
33+
if: ${{ steps.cache-params-from-template.outputs.image-key != '' }}
34+
# avoid using `~` in path that will be expanded to platform specific home directory
35+
uses: actions/cache@v4
36+
with:
37+
path: ${{ steps.cache-params-from-template.outputs.image-path }}
38+
key: ${{ steps.cache-params-from-template.outputs.image-key }}
39+
enableCrossOsArchive: true
40+
41+
- name: "Cache ${{ steps.cache-params-from-template.outputs.kernel-path }}"
42+
if: ${{ steps.cache-params-from-template.outputs.kernel-key != '' }}
43+
# avoid using `~` in path that will be expanded to platform specific home directory
44+
uses: actions/cache@v4
45+
with:
46+
path: ${{ steps.cache-params-from-template.outputs.kernel-path }}
47+
key: ${{ steps.cache-params-from-template.outputs.kernel-key }}
48+
enableCrossOsArchive: true
49+
50+
- name: "Cache ${{ steps.cache-params-from-template.outputs.initrd-path }}"
51+
if: ${{ steps.cache-params-from-template.outputs.initrd-key != '' }}
52+
# avoid using `~` in path that will be expanded to platform specific home directory
53+
uses: actions/cache@v4
54+
with:
55+
path: ${{ steps.cache-params-from-template.outputs.initrd-path }}
56+
key: ${{ steps.cache-params-from-template.outputs.initrd-key }}
57+
enableCrossOsArchive: true
58+
59+
- name: "Cache ${{ steps.cache-params-from-template.outputs.containerd-key }}"
60+
if: ${{ steps.cache-params-from-template.outputs.containerd-key != '' }}
61+
uses: actions/cache@v4
62+
with:
63+
path: ${{ steps.cache-params-from-template.outputs.containerd-path }}
64+
key: ${{ steps.cache-params-from-template.outputs.containerd-key }}
65+
enableCrossOsArchive: true
66+
67+
- name: "Create symbolic link named ${{ steps.detect-platform.outputs.download-dir }} pointing to .download"
68+
run: |
69+
set -eux
70+
[ -d .download ] || mkdir -p .download
71+
path_to_cache=${{ steps.detect-platform.outputs.download-dir }}
72+
mkdir -p "$(dirname "$path_to_cache")"
73+
ln -sfn "$PWD/.download" "$path_to_cache"
74+
shell: bash

Diff for: .github/workflows/test.yml

+24-39
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,6 @@ jobs:
158158
- uses: actions/setup-go@v5
159159
with:
160160
go-version: 1.23.x
161-
- name: Cache ~/Library/Caches/lima/download
162-
uses: actions/cache@v4
163-
with:
164-
path: ~/Library/Caches/lima/download
165-
# hashFiles do not seem to support symlinks
166-
key: ${{ runner.os }}-${{ hashFiles('templates/default.yaml') }}
167161
- name: Unit tests
168162
run: go test -v ./...
169163
- name: Make
@@ -183,11 +177,15 @@ jobs:
183177
# GitHub runners seem to have lima installed by brew already; we don't want/need it
184178
time brew uninstall --ignore-dependencies lima colima
185179
time brew install qemu bash coreutils curl jq
186-
- name: "Show cache"
187-
run: ./hack/debug-cache.sh
188180
- name: "Inject `no_timer_check` to kernel cmdline"
189181
# workaround to https://github.com/lima-vm/lima/issues/84
190182
run: ./hack/inject-cmdline-to-template.sh templates/default.yaml no_timer_check
183+
- name: Cache image used by default.yaml
184+
uses: ./.github/actions/setup_cache_for_template
185+
with:
186+
template: templates/default.yaml
187+
- name: "Show cache"
188+
run: ./hack/debug-cache.sh
191189
- name: "Test default.yaml"
192190
uses: nick-invision/retry@v3
193191
with:
@@ -231,19 +229,14 @@ jobs:
231229
- uses: actions/setup-go@v5
232230
with:
233231
go-version: 1.23.x
234-
- id: path_for_hashFiles
235-
# It seems that `hashFiles` cannot use `..` as a path component, so generate a normalized path here.
236-
run: echo "NORMALIZED=$(realpath --relative-to=$PWD examples/${{ matrix.template }})" >> "$GITHUB_OUTPUT"
237-
- uses: actions/cache@v4
238-
with:
239-
path: ~/.cache/lima/download
240-
# hashFiles do not seem to support symlinks
241-
# TODO: more fine-grained cache
242-
key: ${{ runner.os }}-${{ hashFiles(steps.path_for_hashFiles.outputs.NORMALIZED) }}
243232
- name: Make
244233
run: make
245234
- name: Install
246235
run: sudo make install
236+
- name: Cache image used by templates/${{ matrix.template }}
237+
uses: ./.github/actions/setup_cache_for_template
238+
with:
239+
template: templates/${{ matrix.template }}
247240
- name: Install test dependencies
248241
run: |
249242
sudo apt-get update
@@ -332,16 +325,17 @@ jobs:
332325
- uses: actions/setup-go@v5
333326
with:
334327
go-version: 1.23.x
335-
- name: Cache ~/Library/Caches/lima/download
336-
uses: actions/cache@v4
337-
with:
338-
path: ~/Library/Caches/lima/download
339-
# hashFiles do not seem to support symlinks
340-
key: ${{ runner.os }}-${{ hashFiles('examples/vmnet.yaml') }}
341328
- name: Make
342329
run: make
343330
- name: Install
344331
run: make install
332+
- name: "Inject `no_timer_check` to kernel cmdline"
333+
# workaround to https://github.com/lima-vm/lima/issues/84
334+
run: ./hack/inject-cmdline-to-template.sh templates/vmnet.yaml no_timer_check
335+
- name: Cache image used by vmnet.yaml
336+
uses: ./.github/actions/setup_cache_for_template
337+
with:
338+
template: templates/vmnet.yaml
345339
- name: Install test dependencies
346340
run: brew install qemu bash coreutils iperf3
347341
- name: Install socket_vmnet
@@ -360,9 +354,6 @@ jobs:
360354
- name: Unit test (pkg/networks) with socket_vmnet
361355
# Set -count=1 to disable cache
362356
run: go test -v -count=1 ./pkg/networks/...
363-
- name: "Inject `no_timer_check` to kernel cmdline"
364-
# workaround to https://github.com/lima-vm/lima/issues/84
365-
run: ./hack/inject-cmdline-to-template.sh templates/vmnet.yaml no_timer_check
366357
- name: Test socket_vmnet
367358
uses: nick-invision/retry@v3
368359
with:
@@ -387,11 +378,10 @@ jobs:
387378
- uses: actions/setup-go@v5
388379
with:
389380
go-version: 1.23.x
390-
- name: Cache ~/Library/Caches/lima/download
391-
uses: actions/cache@v4
381+
- name: Cache image used by ${{ matrix.oldver }}/examples/ubuntu-lts.yaml
382+
uses: ./.github/actions/setup_cache_for_template
392383
with:
393-
path: ~/Library/Caches/lima/download
394-
key: ${{ runner.os }}-upgrade-${{ matrix.oldver }}
384+
template: https://raw.githubusercontent.com/lima-vm/lima/${{ matrix.oldver }}/examples/ubuntu-lts.yaml
395385
- name: Install test dependencies
396386
run: brew install qemu bash coreutils
397387
- name: Test
@@ -422,19 +412,14 @@ jobs:
422412
- uses: actions/setup-go@v5
423413
with:
424414
go-version: 1.23.x
425-
- id: path_for_hashFiles
426-
# It seems that `hashFiles` cannot use `..` as a path component, so generate a normalized path here.
427-
run: echo "NORMALIZED=$(realpath examples/${{ matrix.template }})" >> "$GITHUB_OUTPUT"
428-
- name: Cache ~/Library/Caches/lima/download
429-
uses: actions/cache@v4
430-
with:
431-
path: ~/Library/Caches/lima/download
432-
# hashFiles do not seem to support symlinks
433-
key: ${{ runner.os }}-${{ hashFiles(steps.path_for_hashFiles.outputs.NORMALIZED) }}
434415
- name: Make
435416
run: make
436417
- name: Install
437418
run: make install
419+
- name: Cache image used by templates/${{ matrix.template }}
420+
uses: ./.github/actions/setup_cache_for_template
421+
with:
422+
template: templates/${{ matrix.template }}
438423
- name: Install test dependencies
439424
run: brew install bash coreutils jq
440425
- name: Uninstall qemu

0 commit comments

Comments
 (0)