Skip to content

Commit

Permalink
ci: allows no-cache option for image building to ensure updated deps (#…
Browse files Browse the repository at this point in the history
…107)

Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
  • Loading branch information
jpower432 authored Dec 13, 2023
1 parent 071d4f0 commit e3b5020
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit e3b5020

Please sign in to comment.