From e05f4898bc1da708c9f8b160fecc975d59a10b8c Mon Sep 17 00:00:00 2001 From: DmitriyLewen Date: Mon, 30 Sep 2024 13:57:26 +0600 Subject: [PATCH 1/3] ci(test): use save/restore actions --- .github/workflows/test.yaml | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index dc7d825af1c8..98f95698e70b 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -92,14 +92,21 @@ jobs: echo "digest=$DIGEST" >> $GITHUB_OUTPUT - name: Restore test images from cache - uses: actions/cache@v4 - id: restore-test-images + uses: actions/cache/restore@v4 with: path: integration/testdata/fixtures/images key: cache-test-images-${{ steps.image-digest.outputs.digest }} 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 @@ -148,14 +155,22 @@ jobs: echo "digest=$DIGEST" >> $GITHUB_OUTPUT - name: Restore test images from cache - uses: actions/cache@v4 - id: restore-test-images + uses: actions/cache/restore@v4 with: path: integration/testdata/fixtures/images key: cache-test-images-${{ steps.image-digest.outputs.digest }} 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: | @@ -185,14 +200,21 @@ jobs: echo "digest=$DIGEST" >> $GITHUB_OUTPUT - name: Restore test VM images from cache - uses: actions/cache@v4 - id: restore-test-vm-images + uses: actions/cache/restore@v4 with: path: integration/testdata/fixtures/vm-images key: cache-test-vm-images-${{ steps.image-digest.outputs.digest }} 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 From 9cbf1e59b8d3d88a61b1376b63a6b8c7fd4a121e Mon Sep 17 00:00:00 2001 From: DmitriyLewen Date: Mon, 30 Sep 2024 14:20:32 +0600 Subject: [PATCH 2/3] ci: save images in separate workflow --- .github/workflows/cache-test-images.yaml | 80 ++++++++++++++++++++++++ .github/workflows/test.yaml | 25 -------- 2 files changed, 80 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/cache-test-images.yaml diff --git a/.github/workflows/cache-test-images.yaml b/.github/workflows/cache-test-images.yaml new file mode 100644 index 000000000000..823206f56e2c --- /dev/null +++ b/.github/workflows/cache-test-images.yaml @@ -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 into 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 into cache + if: github.ref == 'refs/heads/main' + uses: actions/cache/save@v4 + with: + path: integration/testdata/fixtures/vm-images + key: cache-test-vm-images-${{ steps.image-digest.outputs.digest }} \ No newline at end of file diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 98f95698e70b..b423b61699fb 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -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 @@ -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: | @@ -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 From 91a8016b42a752ace91dd904b194d56005931bb4 Mon Sep 17 00:00:00 2001 From: DmitriyLewen Date: Mon, 30 Sep 2024 15:10:45 +0600 Subject: [PATCH 3/3] refactor --- .github/workflows/cache-test-images.yaml | 50 +++++++++++++----------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/.github/workflows/cache-test-images.yaml b/.github/workflows/cache-test-images.yaml index 823206f56e2c..da8aff10cfd2 100644 --- a/.github/workflows/cache-test-images.yaml +++ b/.github/workflows/cache-test-images.yaml @@ -1,9 +1,9 @@ name: Cache test images on: + schedule: + - cron: "0 0 * * *" # Run this workflow every day at 00:00 to avoid cache deletion. workflow_dispatch: -env: - GO_VERSION: '1.22' jobs: test-images: name: Cache test images @@ -15,32 +15,34 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: ${{ env.GO_VERSION }} + go-version-file: go.mod - 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' + if: github.ref_name == '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 into cache - if: github.ref == 'refs/heads/main' - uses: actions/cache/save@v4 + ## We need to work with test image cache only for main branch + - name: Restore and save test images cache + if: github.ref_name == 'main' + uses: actions/cache@v4 with: path: integration/testdata/fixtures/images key: cache-test-images-${{ steps.image-digest.outputs.digest }} + restore-keys: + cache-test-images- + + - name: Download test images + if: github.ref_name == 'main' + run: mage test:fixtureContainerImages test-vm-images: name: Cache test VM images @@ -52,29 +54,31 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: ${{ env.GO_VERSION }} + go-version-file: go.mod - 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' + if: github.ref_name == '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 into cache - if: github.ref == 'refs/heads/main' - uses: actions/cache/save@v4 + ## We need to work with test VM image cache only for main branch + - name: Restore and save test VM images cache + if: github.ref_name == 'main' + uses: actions/cache@v4 with: path: integration/testdata/fixtures/vm-images - key: cache-test-vm-images-${{ steps.image-digest.outputs.digest }} \ No newline at end of file + key: cache-test-vm-images-${{ steps.image-digest.outputs.digest }} + restore-keys: + cache-test-vm-images- + + - name: Download test VM images + if: github.ref_name == 'main' + run: mage test:fixtureVMImages \ No newline at end of file