Skip to content

Commit 39c5869

Browse files
committed
On PR merge update the quay image
1 parent 346edbc commit 39c5869

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Build and Push Container Image On PR Merge
2+
3+
on:
4+
pull_request_target:
5+
types: [closed]
6+
7+
permissions:
8+
pull-requests: write
9+
contents: write
10+
issues: write
11+
12+
jobs:
13+
if_merged:
14+
if: github.event.pull_request.merged == true
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout Repository
18+
uses: actions/checkout@v4
19+
- name: Set env TAG
20+
run: |
21+
if [ ${{ github.event.pull_request.base.ref }} == "main" ]; then
22+
echo "TAG=latest" >> $GITHUB_ENV
23+
else
24+
echo "TAG=${{ github.event.pull_request.base.ref }}" >> "$GITHUB_ENV"
25+
fi
26+
- name: Build Image
27+
id: build-image
28+
uses: redhat-actions/buildah-build@v2
29+
with:
30+
image: ${{ secrets.IMAGE_NAME }}
31+
tags: ${{ env.TAG }}
32+
containerfiles: |
33+
./Dockerfile
34+
35+
- name: Push To Image Registry
36+
id: push-to-registry
37+
uses: redhat-actions/push-to-registry@v2
38+
with:
39+
image: ${{ steps.build-image.outputs.image }}
40+
tags: ${{ steps.build-image.outputs.tags }}
41+
registry: ${{ secrets.IMAGE_REGISTRY }}/${{ secrets.IMAGE_NAMESPACE }}
42+
username: ${{ secrets.QUAY_USERNAME }}
43+
password: ${{ secrets.QUAY_PASSWORD }}
44+
45+
- name: Set env PR_COMMENT
46+
run: |
47+
echo "PR_COMMENT=Successfully updated image tag: ${{ env.TAG }}" >> $GITHUB_ENV
48+
49+
- name: Add comment to PR
50+
env:
51+
URL: ${{ github.event.pull_request.comments_url }}
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
run: |
54+
curl \
55+
-X POST \
56+
$URL \
57+
-H "Content-Type: application/json" \
58+
-H "Authorization: token $GITHUB_TOKEN" \
59+
--data '{ "body": "${{ env.PR_COMMENT }}" }'

0 commit comments

Comments
 (0)