Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework setting image tags to support PRs better #161

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading