File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed
Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change 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 }}" }'
You can’t perform that action at this time.
0 commit comments