Skip to content

Commit

Permalink
ci: save images in separate workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyLewen committed Sep 30, 2024
1 parent d648031 commit 0394220
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 25 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/cache-test-images.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Cache test images
on:
workflow_dispatch:

env:
GO_VERSION: '1.22'
jobs:
test-images:
name: Cache test images
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4.1.6

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

- name: Install tools
uses: aquaproj/aqua-installer@v3.0.1
with:
aqua_version: v1.25.0

- name: Download test images
if: github.ref == 'refs/heads/main'
run: mage test:fixtureContainerImages

- name: Generate image list digest
if: github.ref == 'refs/heads/main'
id: image-digest
run: |
IMAGE_LIST=$(skopeo list-tags docker://ghcr.io/aquasecurity/trivy-test-images)
DIGEST=$(echo "$IMAGE_LIST" | sha256sum | cut -d' ' -f1)
echo "digest=$DIGEST" >> $GITHUB_OUTPUT
## We need to save test image cache only for main branch
- name: Save test images from cache
if: github.ref == 'refs/heads/main'
uses: actions/cache/save@v4
with:
path: integration/testdata/fixtures/images
key: cache-test-images-${{ steps.image-digest.outputs.digest }}

test-vm-images:
name: Cache test VM images
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4.1.6

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

- name: Install tools
uses: aquaproj/aqua-installer@v3.0.1
with:
aqua_version: v1.25.0

- name: Download test VM images
if: github.ref == 'refs/heads/main'
run: mage test:fixtureVMImages

- name: Generate image list digest
if: github.ref == 'refs/heads/main'
id: image-digest
run: |
IMAGE_LIST=$(skopeo list-tags docker://ghcr.io/aquasecurity/trivy-test-vm-images)
DIGEST=$(echo "$IMAGE_LIST" | sha256sum | cut -d' ' -f1)
echo "digest=$DIGEST" >> $GITHUB_OUTPUT
## We need to save test VM image cache only for main branch
- name: Save test VM images from cache
if: github.ref == 'refs/heads/main'
uses: actions/cache/save@v4
with:
path: integration/testdata/fixtures/images
key: cache-test-vm-images-${{ steps.image-digest.outputs.digest }}
25 changes: 0 additions & 25 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,6 @@ jobs:
restore-keys:
cache-test-images-

## We need to save test image cache only for main branch
- name: Save test images from cache
if: github.ref_name == 'main'
uses: actions/cache/save@v4
with:
path: integration/testdata/fixtures/images
key: cache-test-images-${{ steps.image-digest.outputs.digest }}

- name: Run integration tests
run: mage test:integration

Expand Down Expand Up @@ -162,15 +154,6 @@ jobs:
restore-keys:
cache-test-images-


## We need to save test image cache only for main branch
- name: Save test images from cache
if: github.ref_name == 'main'
uses: actions/cache/save@v4
with:
path: integration/testdata/fixtures/images
key: cache-test-images-${{ steps.image-digest.outputs.digest }}

- name: Run module integration tests
shell: bash
run: |
Expand Down Expand Up @@ -207,14 +190,6 @@ jobs:
restore-keys:
cache-test-vm-images-

## We need to save test VM image cache only for main branch
- name: Save test VM images from cache
if: github.ref_name == 'main'
uses: actions/cache/save@v4
with:
path: integration/testdata/fixtures/images
key: cache-test-vm-images-${{ steps.image-digest.outputs.digest }}

- name: Run vm integration tests
run: |
mage test:vm
Expand Down

0 comments on commit 0394220

Please sign in to comment.