From e3b5020c7b0cf138722662ff29a565a5af905360 Mon Sep 17 00:00:00 2001 From: Jennifer Power Date: Wed, 13 Dec 2023 09:18:31 -0500 Subject: [PATCH] ci: allows no-cache option for image building to ensure updated deps (#107) Signed-off-by: Jennifer Power --- .github/workflows/publish.yml | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 85980b5c..85826382 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -14,6 +14,11 @@ on: type: boolean required: false default: false + no_cache: + description: "Skip using cache when building the image." + type: boolean + required: false + default: false env: IMAGE_NAME: trestle-bot IMAGE_REGISTRY: quay.io @@ -25,14 +30,11 @@ jobs: permissions: contents: read outputs: - skip_tests: ${{ steps.check_event.outputs.event_type == 'release' - || (steps.check_event.outputs.event_type == 'workflow_dispatch' - && github.event.inputs.skip_tests == 'true') }} + skip_tests: ${{ steps.check_event.outputs.event_type == 'release' || + (steps.check_event.outputs.event_type == 'workflow_dispatch' && + github.event.inputs.skip_tests == 'true') }} image: ${{ env.IMAGE_REGISTRY }}/${{ vars.QUAY_ORG }}/${{ env.IMAGE_NAME }}@${{ steps.build-image.outputs.digest }} steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -53,20 +55,28 @@ jobs: # Using intermediary variable to process event based input - name: Set TAG environment variable for Release if: ${{ steps.check_event.outputs.event_type == 'release' }} - run: echo "TAG=$RELEASE_VERSION" >> "$GITHUB_ENV" + run: | + echo "TAG=$RELEASE_VERSION" >> "$GITHUB_ENV" + echo "NO_CACHE=true" >> "$GITHUB_ENV" env: RELEASE_VERSION: ${{ github.event.release.tag_name }} - name: Set TAG environment variable for Workflow Dispatch if: ${{ steps.check_event.outputs.event_type == 'workflow_dispatch' }} - run: echo "TAG=$INPUT_VERSION" >> "$GITHUB_ENV" + run: | + echo "TAG=$INPUT_VERSION" >> "$GITHUB_ENV" + echo "NO_CACHE=$INPUT_NO_CACHE" >> "$GITHUB_ENV" env: INPUT_VERSION: ${{ github.event.inputs.tag }} + INPUT_NO_CACHE: ${{ github.event.inputs.no_cache }} - name: Build and export to Docker uses: docker/build-push-action@v5 with: load: true + no-cache: ${{ env.NO_CACHE == 'true' }} + cache-from: type=gha + cache-to: type=gha,mode=max tags: ${{ env.IMAGE_REGISTRY }}/${{ vars.QUAY_ORG }}/${{ env.IMAGE_NAME }}:${{ env.TAG }} - name: Pre-push Image Scan @@ -77,13 +87,12 @@ jobs: scanners: secret severity: HIGH,CRITICAL,MEDIUM + # Does not rebuild. Uses internal cache from previous step. - name: Build and Push uses: docker/build-push-action@v5 id: build-image with: push: true - cache-from: type=gha - cache-to: type=gha,mode=max tags: ${{ env.IMAGE_REGISTRY }}/${{ vars.QUAY_ORG }}/${{ env.IMAGE_NAME }}:${{ env.TAG }} test: