Skip to content

Commit b0aa23b

Browse files
committed
Support /build-push-pr-image comment to push image to quay for testing via jenkins
1 parent eda4aeb commit b0aa23b

File tree

4 files changed

+91
-4
lines changed

4 files changed

+91
-4
lines changed

.github/workflows/add-remove-labels.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ jobs:
1919
contains(github.event.comment.body, '/verified') ||
2020
contains(github.event.comment.body, '/lgtm') ||
2121
contains(github.event.comment.body, '/hold') ||
22-
contains(github.event.comment.body, '/cherry-pick')
22+
contains(github.event.comment.body, '/cherry-pick') ||
23+
contains(github.event.comment.body, '/build-push-pr-image')
2324
runs-on: ubuntu-latest
2425

2526
steps:
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Delete PR Image On PR Close Action
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+
delete-quay-tag:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Install regctl
17+
run: |
18+
curl -LO https://github.com/regclient/regclient/releases/latest/download/regctl-linux-amd64
19+
chmod +x regctl-linux-amd64
20+
sudo mv regctl-linux-amd64 /usr/local/bin/regctl
21+
regctl version
22+
23+
- name: Configure regctl authentication
24+
run: |
25+
regctl registry login quay.io -u ${{ secrets.QUAY_USERNAME }} -p ${{ secrets.QUAY_PASSWORD }}
26+
echo "PR number: ${{ github.event.pull_request.number }}"
27+
echo "TAG_TO_DELETE=$(regctl tag ls quay.io/opendatahub/opendatahub-tests --include pr-${{ github.event.pull_request.number }})" >> $GITHUB_ENV
28+
- name: Delete Quay Tag
29+
if: env.TAG_TO_DELETE != ''
30+
run: |
31+
echo "Deleting tag '$TAG_TO_DELETE' from repository..."
32+
regctl tag rm quay.io/opendatahub/opendatahub-tests:pr-${{ github.event.pull_request.number }}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Push Container Image On PR Comment
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
7+
permissions:
8+
pull-requests: write
9+
contents: write
10+
issues: write
11+
12+
jobs:
13+
push-container-on-comment:
14+
name: push-registry-image
15+
if: contains(github.event.comment.body, '/build-push-pr-image')
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout Repository
19+
uses: actions/checkout@v4
20+
- name: Set env TAG for image
21+
run: |
22+
echo "TAG=pr-${{ github.event.issue.number }}" >> "$GITHUB_ENV"
23+
- name: Build Image to push
24+
id: build-image
25+
uses: redhat-actions/buildah-build@v2
26+
with:
27+
image: opendatahub-tests
28+
tags: ${{ env.TAG }}
29+
containerfiles: |
30+
./Dockerfile
31+
- name: Push To Image Registry
32+
id: push-to-registry
33+
uses: redhat-actions/push-to-registry@v2
34+
with:
35+
image: ${{ steps.build-image.outputs.image }}
36+
tags: ${{ steps.build-image.outputs.tags }}
37+
registry: quay.io/opendatahub
38+
username: ${{ secrets.QUAY_USERNAME }}
39+
password: ${{ secrets.QUAY_PASSWORD }}
40+
41+
- name: Add comment to PR
42+
if: always()
43+
env:
44+
URL: ${{ github.event.pull_request.comments_url }}
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
run: |
47+
curl \
48+
-X POST \
49+
$URL \
50+
-H "Content-Type: application/json" \
51+
-H "Authorization: token $GITHUB_TOKEN" \
52+
--data '{ "body": "Status of building tag ${{ env.TAG }}: ${{ steps.build-image.outcome }}. \nStatus of pushing tag ${{ env.TAG }} to image registry: ${{ steps.push-to-registry.outcome }}." }'

docs/GITHUB_WORKFLOWS.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010

1111
### On user action
1212
- Add to or remove a label from PR; supported labels: `wip`, `lgtm`, `verified`, and `hold`.
13-
To add a new label, add `/<label name>` in a comment.
14-
To remove a label, add `/<label name> cancel` in a comment.
13+
- To add a new label, add `/<label name>` in a comment.
14+
- To remove a label, add `/<label name> cancel` in a comment.
1515
`verified` and `lgtm` are removed on new commits.
16+
- To build and push image to quay, add `/build-push-pr-image` in a comment.
17+
This would create an image with tag pr-<pr_number> to quay repository. This image tag,
18+
however would be deleted on PR merge or close action.
1619

1720
## How to add a new workflow
1821
1. Create a new file in `.github/workflows` directory.
@@ -25,7 +28,6 @@
2528
## To be added
2629
- Block merging if not all defined checks pass. For example: a `verified` label was added and at least 2 approvals.
2730
- When a PR is opened, add reviewers (requires updates to OWNERS file(s))
28-
- When a PR is reviewed/commented by a user who's not the PR owner, add `reviewed|commented|approved-by-<username>` label
2931
- When a PR is ready to be merged (all checks passed), add `ready-to-merge` label
3032
- If a label is missing from the repository (i.e was manually deleted), add it back (label colors should be defined as well)
3133
- Tests

0 commit comments

Comments
 (0)