Skip to content

Commit

Permalink
Rework setting image tags to support PRs better
Browse files Browse the repository at this point in the history
  • Loading branch information
webbnh committed Nov 6, 2024
1 parent 3ab9905 commit c7c36bb
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions .github/workflows/reusable_workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,38 @@ on:
env:
QUAY_TAG_ROOT: quay.io/${{ secrets.QUAY_NAMESPACE }}/${{ inputs.image_name }}
QUAY_IMG_EXP: 0


jobs:
act-build:
name: Build ${{ github.ref_name }} from ${{ github.event_name }}
runs-on: ubuntu-latest
steps:
- name: Set image tags for release
if: github.event_name == 'release'
- name: Set image tags
run: |
echo "IMAGE_TAGS=${{ env.QUAY_TAG_ROOT }}:${GITHUB_REF#refs/*/} ${{ env.QUAY_TAG_ROOT }}:latest" >> $GITHUB_ENV
- name: Set image tags for main
if: github.ref == 'refs/heads/main' && github.event_name != 'release'
run: |
echo "IMAGE_TAGS=${{ env.QUAY_TAG_ROOT }}:main_latest" >> $GITHUB_ENV
if [[ ${{ github.event_name }} == 'release' ]]; then
# Set image tags for release builds
IMAGE_TAGS="${{ env.QUAY_TAG_ROOT }}:${GITHUB_REF#refs/*/} ${{ env.QUAY_TAG_ROOT }}:latest"
elif [[ ${{ github.ref }} == 'refs/heads/main' ]]; then
# Set image tags for main branch builds
IMAGE_TAGS="${{ env.QUAY_TAG_ROOT }}:main_latest"
else
if [[ ${{ github.event_name }} == 'pull_request' ]]; then
# Set image tags for pull request builds
bname=${{ github.head_ref }}
else
# Set image tags for any other builds (such as tags)
bname=${GITHUB_REF##*/}
fi
commit_hash=${{ github.sha }}
IMAGE_TAGS="${{ env.QUAY_TAG_ROOT }}:${bname}_${commit_hash:0:7}"
# Builds other than main and releases get automatic expiration
echo "QUAY_IMG_EXP=90d" >> $GITHUB_ENV
fi
echo "IMAGE_TAGS=${IMAGE_TAGS}" | tee -a $GITHUB_ENV
- name: Set image tags and expiration for dev
if: github.ref != 'refs/heads/main' && github.event_name != 'release'
run: |
export commit_hash=${{ github.sha }}
echo "QUAY_IMG_EXP=90d" >> $GITHUB_ENV
echo "IMAGE_TAGS=${{ env.QUAY_TAG_ROOT }}:${GITHUB_REF##*/}_${commit_hash:0:7}" >> $GITHUB_ENV
- name: Checkout this project
uses: actions/checkout@v4

- name: arcaflow-container-toolkit-action
uses: arcalot/[email protected]
with:
Expand Down Expand Up @@ -96,18 +101,17 @@ jobs:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}

- name: Build multi-arch image
id: build-multi-arch
uses: redhat-actions/buildah-build@v2
with:
context: .
platforms: ${{ inputs.build_platforms }}
tags: ${{ env.IMAGE_TAGS }}
containerfiles: |
./Dockerfile
containerfiles: ./Dockerfile
labels: quay.expires-after=${{ env.QUAY_IMG_EXP }}

- name: Push image to quay.io
uses: redhat-actions/push-to-registry@v2
with:
Expand Down

0 comments on commit c7c36bb

Please sign in to comment.