Skip to content

Commit

Permalink
Merge pull request #2508 from norio-nomura/ci-use-digest-of-image-in-…
Browse files Browse the repository at this point in the history
…template-as-key-for-cache

test.yml: use image cache with parameters created from template
  • Loading branch information
AkihiroSuda authored Aug 30, 2024
2 parents b3067dc + 5058106 commit 726f61d
Show file tree
Hide file tree
Showing 5 changed files with 659 additions and 40 deletions.
74 changes: 74 additions & 0 deletions .github/actions/setup_cache_for_template/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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: "create cache parameters from template"
if: always()
id: cache-params-from-template
run: |
set -eux
source hack/cache-common-inc.sh
print_cache_informations_from_template "${{ inputs.template }}" "${{ inputs.arch }}" >> "$GITHUB_OUTPUT"
shell: bash

- name: "Cache ${{ steps.cache-params-from-template.outputs.image-path }}"
if: ${{ steps.cache-params-from-template.outputs.image-key != '' }}
# avoid using `~` in path that will be expanded to platform specific home directory
uses: actions/cache@v4
with:
path: ${{ steps.cache-params-from-template.outputs.image-path }}
key: ${{ steps.cache-params-from-template.outputs.image-key }}
enableCrossOsArchive: true

- name: "Cache ${{ steps.cache-params-from-template.outputs.kernel-path }}"
if: ${{ steps.cache-params-from-template.outputs.kernel-key != '' }}
# avoid using `~` in path that will be expanded to platform specific home directory
uses: actions/cache@v4
with:
path: ${{ steps.cache-params-from-template.outputs.kernel-path }}
key: ${{ steps.cache-params-from-template.outputs.kernel-key }}
enableCrossOsArchive: true

- name: "Cache ${{ steps.cache-params-from-template.outputs.initrd-path }}"
if: ${{ steps.cache-params-from-template.outputs.initrd-key != '' }}
# avoid using `~` in path that will be expanded to platform specific home directory
uses: actions/cache@v4
with:
path: ${{ steps.cache-params-from-template.outputs.initrd-path }}
key: ${{ steps.cache-params-from-template.outputs.initrd-key }}
enableCrossOsArchive: true

- name: "Cache ${{ steps.cache-params-from-template.outputs.containerd-key }}"
if: ${{ steps.cache-params-from-template.outputs.containerd-key != '' }}
uses: actions/cache@v4
with:
path: ${{ steps.cache-params-from-template.outputs.containerd-path }}
key: ${{ steps.cache-params-from-template.outputs.containerd-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
63 changes: 24 additions & 39 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,6 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: 1.23.x
- name: Cache ~/Library/Caches/lima/download
uses: actions/cache@v4
with:
path: ~/Library/Caches/lima/download
# hashFiles do not seem to support symlinks
key: ${{ runner.os }}-${{ hashFiles('templates/default.yaml') }}
- name: Unit tests
run: go test -v ./...
- name: Make
Expand All @@ -183,11 +177,15 @@ jobs:
# GitHub runners seem to have lima installed by brew already; we don't want/need it
time brew uninstall --ignore-dependencies lima colima
time brew install qemu bash coreutils curl jq
- name: "Show cache"
run: ./hack/debug-cache.sh
- name: "Inject `no_timer_check` to kernel cmdline"
# workaround to https://github.com/lima-vm/lima/issues/84
run: ./hack/inject-cmdline-to-template.sh templates/default.yaml no_timer_check
- name: Cache image used by default.yaml
uses: ./.github/actions/setup_cache_for_template
with:
template: templates/default.yaml
- name: "Show cache"
run: ./hack/debug-cache.sh
- name: "Test default.yaml"
uses: nick-invision/retry@v3
with:
Expand Down Expand Up @@ -231,19 +229,14 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: 1.23.x
- id: path_for_hashFiles
# It seems that `hashFiles` cannot use `..` as a path component, so generate a normalized path here.
run: echo "NORMALIZED=$(realpath --relative-to=$PWD examples/${{ matrix.template }})" >> "$GITHUB_OUTPUT"
- uses: actions/cache@v4
with:
path: ~/.cache/lima/download
# hashFiles do not seem to support symlinks
# TODO: more fine-grained cache
key: ${{ runner.os }}-${{ hashFiles(steps.path_for_hashFiles.outputs.NORMALIZED) }}
- name: Make
run: make
- name: Install
run: sudo make install
- name: Cache image used by templates/${{ matrix.template }}
uses: ./.github/actions/setup_cache_for_template
with:
template: templates/${{ matrix.template }}
- name: Install test dependencies
run: |
sudo apt-get update
Expand Down Expand Up @@ -332,16 +325,17 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: 1.23.x
- name: Cache ~/Library/Caches/lima/download
uses: actions/cache@v4
with:
path: ~/Library/Caches/lima/download
# hashFiles do not seem to support symlinks
key: ${{ runner.os }}-${{ hashFiles('examples/vmnet.yaml') }}
- name: Make
run: make
- name: Install
run: make install
- name: "Inject `no_timer_check` to kernel cmdline"
# workaround to https://github.com/lima-vm/lima/issues/84
run: ./hack/inject-cmdline-to-template.sh templates/vmnet.yaml no_timer_check
- name: Cache image used by vmnet.yaml
uses: ./.github/actions/setup_cache_for_template
with:
template: templates/vmnet.yaml
- name: Install test dependencies
run: brew install qemu bash coreutils iperf3
- name: Install socket_vmnet
Expand All @@ -360,9 +354,6 @@ jobs:
- name: Unit test (pkg/networks) with socket_vmnet
# Set -count=1 to disable cache
run: go test -v -count=1 ./pkg/networks/...
- name: "Inject `no_timer_check` to kernel cmdline"
# workaround to https://github.com/lima-vm/lima/issues/84
run: ./hack/inject-cmdline-to-template.sh templates/vmnet.yaml no_timer_check
- name: Test socket_vmnet
uses: nick-invision/retry@v3
with:
Expand All @@ -387,11 +378,10 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: 1.23.x
- name: Cache ~/Library/Caches/lima/download
uses: actions/cache@v4
- name: Cache image used by ${{ matrix.oldver }}/examples/ubuntu-lts.yaml
uses: ./.github/actions/setup_cache_for_template
with:
path: ~/Library/Caches/lima/download
key: ${{ runner.os }}-upgrade-${{ matrix.oldver }}
template: https://raw.githubusercontent.com/lima-vm/lima/${{ matrix.oldver }}/examples/ubuntu-lts.yaml
- name: Install test dependencies
run: brew install qemu bash coreutils
- name: Test
Expand Down Expand Up @@ -422,19 +412,14 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: 1.23.x
- id: path_for_hashFiles
# It seems that `hashFiles` cannot use `..` as a path component, so generate a normalized path here.
run: echo "NORMALIZED=$(realpath examples/${{ matrix.template }})" >> "$GITHUB_OUTPUT"
- name: Cache ~/Library/Caches/lima/download
uses: actions/cache@v4
with:
path: ~/Library/Caches/lima/download
# hashFiles do not seem to support symlinks
key: ${{ runner.os }}-${{ hashFiles(steps.path_for_hashFiles.outputs.NORMALIZED) }}
- name: Make
run: make
- name: Install
run: make install
- name: Cache image used by templates/${{ matrix.template }}
uses: ./.github/actions/setup_cache_for_template
with:
template: templates/${{ matrix.template }}
- name: Install test dependencies
run: brew install bash coreutils jq
- name: Uninstall qemu
Expand Down
Loading

0 comments on commit 726f61d

Please sign in to comment.