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

👷 Build images on PR and comment the tag for each run #75

Merged
merged 4 commits into from
Nov 11, 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
29 changes: 27 additions & 2 deletions .github/workflows/image-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ on:
push:
tags:
- 'v*'
pull_request:
types:
- opened
- synchronize
- reopened


run-name: "Image Build for tag ${{ github.ref_name }}"

Expand All @@ -23,7 +29,21 @@ jobs:
- name: Create safe tag for image
id: safe_tag
run: |
echo "SAFE_TAG=$(echo ${{ github.ref_name }} | sed 's/[^a-zA-Z0-9.]/-/g')" >> $GITHUB_OUTPUT
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "SAFE_TAG=$(echo ${{ github.event.pull_request.head.ref }} | sed 's/[^a-zA-Z0-9.]/-/g')-${{ github.run_id }}-${{ github.run_number }}" >> $GITHUB_OUTPUT
else
echo "SAFE_TAG=$(echo ${{ github.ref_name }} | sed 's/[^a-zA-Z0-9.]/-/g')" >> $GITHUB_OUTPUT
fi

- name: Output VERSION_REF
id: output_version_ref
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
# if on a PR we need to get the current branch name
echo "VERSION_REF=${{ github.event.pull_request.head.ref }}" >> $GITHUB_OUTPUT
else
echo "VERSION_REF=${{ github.ref_name }}" >> $GITHUB_OUTPUT
fi

- name: Set up Docker Buildx
id: setup_buildx
Expand All @@ -45,7 +65,12 @@ jobs:
push: true
tags: ghcr.io/ministryofjustice/hmpps-ldap-automation:${{ steps.safe_tag.outputs.SAFE_TAG }}
build-args: |
VERSION_REF=${{ steps.BumpVersionAndPushTag.outputs.new_tag }}
VERSION_REF=${{ steps.output_version_ref.outputs.VERSION_REF }}

- name: Comment image tag on PR
if: github.event_name == 'pull_request'
run: |
gh pr comment ${{ github.event.pull_request.number }} --body "Image built and pushed to ghcr.io/ministryofjustice/hmpps-ldap-automation:${{ steps.safe_tag.outputs.SAFE_TAG }}"

- name: Slack failure notification
if: ${{ failure() }}
Expand Down
Loading