Skip to content

Commit 3dde96e

Browse files
committed
[2.19] update workflow
1 parent 137cac5 commit 3dde96e

File tree

9 files changed

+335
-23
lines changed

9 files changed

+335
-23
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,8 @@ on:
33
pull_request_target:
44
types: [synchronize]
55

6-
pull_request_review:
7-
86
issue_comment:
97
types: [created, edited, deleted]
10-
if: |
11-
contains(github.event.comment.body, '/wip') ||
12-
contains(github.event.comment.body, '/verified') ||
13-
contains(github.event.comment.body, '/lgtm') ||
14-
contains(github.event.comment.body, '/hold')
158

169

1710
permissions:
@@ -20,7 +13,14 @@ permissions:
2013
issues: write
2114

2215
jobs:
23-
add-remove-labels:
16+
add-remove-labels-reactions:
17+
if: |
18+
contains(github.event.comment.body, '/wip') ||
19+
contains(github.event.comment.body, '/verified') ||
20+
contains(github.event.comment.body, '/lgtm') ||
21+
contains(github.event.comment.body, '/hold') ||
22+
contains(github.event.comment.body, '/cherry-pick') ||
23+
contains(github.event.comment.body, '/build-push-pr-image')
2424
runs-on: ubuntu-latest
2525

2626
steps:
@@ -31,10 +31,14 @@ jobs:
3131
comment-id: ${{ github.event.comment.id }}
3232
reactions: '+1'
3333

34+
add-remove-labels:
35+
runs-on: ubuntu-latest
36+
37+
steps:
3438
- uses: actions/checkout@v4
3539

3640
- name: Install uv
37-
uses: astral-sh/setup-uv@v5
41+
uses: astral-sh/setup-uv@v6
3842

3943
- name: Run add remove labels
4044
env:
@@ -44,6 +48,7 @@ jobs:
4448
GITHUB_EVENT_REVIEW_STATE: ${{ github.event.review.state }}
4549
GITHUB_EVENT_NAME: ${{ github.event_name }}
4650
COMMENT_BODY: ${{ github.event.comment.body }}
51+
REVIEW_COMMENT_BODY: ${{ github.event.review.body }}
4752
GITHUB_USER_LOGIN: ${{ github.event.sender.login }}
4853
ACTION: "add-remove-labels"
4954
run: uv run python .github/workflows/scripts/pr_workflow.py
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Cherry Pick On Comment
2+
on:
3+
issue_comment:
4+
types: [created]
5+
jobs:
6+
cherry-pick:
7+
name: Cherry Pick
8+
if: |
9+
github.event.issue.pull_request != '' &&
10+
contains(github.event.comment.body, '/cherry-pick') &&
11+
((github.event.pull_request.author_association != 'NONE') &&
12+
(github.event.pull_request.author_association != 'MANNEQUIN') &&
13+
(github.event.pull_request.author_association != 'FIRST_TIMER') &&
14+
(github.event.pull_request.author_association != 'FIRST_TIME_CONTRIBUTOR'))
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout the latest code
18+
uses: actions/checkout@v4
19+
with:
20+
token: ${{ secrets.RHODS_CI_BOT_PAT }}
21+
fetch-depth: 0 # otherwise, you will fail to push refs to dest repo
22+
- name: Automatic Cherry Pick
23+
uses: dbasunag/cherry-pick-pr@master
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.RHODS_CI_BOT_PAT }}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: delete-image-tag.yml
2+
on:
3+
4+
jobs:
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Run Label Action on PR Review Event
2+
on:
3+
workflow_run:
4+
workflows: ["Dummy Workflow on review"]
5+
types:
6+
- completed
7+
permissions:
8+
pull-requests: write
9+
contents: write
10+
issues: write
11+
12+
jobs:
13+
run_on_workflow_a_success:
14+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Run this on Dummy workflow success
18+
run: echo "Dummy Workflow on review completes successfully"
19+
download_context_artifact:
20+
needs:
21+
- run_on_workflow_a_success
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: 'Download artifact'
25+
uses: actions/github-script@v7
26+
with:
27+
script: |
28+
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
29+
owner: context.repo.owner,
30+
repo: context.repo.repo,
31+
run_id: context.payload.workflow_run.id,
32+
});
33+
34+
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
35+
return artifact.name == "context.json"
36+
})[0];
37+
38+
let download = await github.rest.actions.downloadArtifact({
39+
owner: context.repo.owner,
40+
repo: context.repo.repo,
41+
artifact_id: matchArtifact.id,
42+
archive_format: 'zip',
43+
});
44+
45+
let fs = require('fs');
46+
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/context.zip`, Buffer.from(download.data));
47+
48+
- name: 'Unzip artifact'
49+
run: unzip context.zip
50+
- name: 'Return Parsed JSON'
51+
uses: actions/github-script@v7
52+
id: return-parsed-json
53+
with:
54+
script: |
55+
let fs = require('fs');
56+
let data = fs.readFileSync('./context.json');
57+
return JSON.parse(data);
58+
outputs:
59+
pr_num: ${{fromJSON(steps.return-parsed-json.outputs.result).pr_num}}
60+
event_action: ${{fromJSON(steps.return-parsed-json.outputs.result).event_action}}
61+
review_state: ${{fromJSON(steps.return-parsed-json.outputs.result).review_state}}
62+
event_name: ${{fromJSON(steps.return-parsed-json.outputs.result).event_name}}
63+
comment_body: ${{fromJSON(steps.return-parsed-json.outputs.result).comment_body}}
64+
review_comment_body: ${{fromJSON(steps.return-parsed-json.outputs.result).review_comment_body}}
65+
user_login: ${{fromJSON(steps.return-parsed-json.outputs.result).user_login}}
66+
action: ${{fromJSON(steps.return-parsed-json.outputs.result).action}}
67+
log_context_values:
68+
needs:
69+
- download_context_artifact
70+
runs-on: ubuntu-latest
71+
steps:
72+
- name: 'Set all Env Variable'
73+
run: |
74+
echo "GITHUB_PR_NUMBER=${{ needs.download_context_artifact.outputs.pr_num }}" >> "$GITHUB_ENV"
75+
echo "GITHUB_EVENT_ACTION=${{ needs.download_context_artifact.outputs.event_action }}" >> "$GITHUB_ENV"
76+
echo "GITHUB_EVENT_REVIEW_STATE=${{ needs.download_context_artifact.outputs.review_state }}" >> "$GITHUB_ENV"
77+
echo "GITHUB_EVENT_NAME=${{ needs.download_context_artifact.outputs.event_name }}" >> "$GITHUB_ENV"
78+
echo "COMMENT_BODY=${{ needs.download_context_artifact.outputs.comment_body }}" >> "$GITHUB_ENV"
79+
echo "REVIEW_COMMENT_BODY=${{ needs.download_context_artifact.outputs.review_comment_body }}" >> "$GITHUB_ENV"
80+
echo "GITHUB_USER_LOGIN=${{ needs.download_context_artifact.outputs.user_login }}" >> "$GITHUB_ENV"
81+
echo "ACTION=${{ needs.download_context_artifact.outputs.action }}" >> "$GITHUB_ENV"
82+
- uses: actions/checkout@v4
83+
84+
- name: Install uv
85+
uses: astral-sh/setup-uv@v6
86+
- name: 'Run add-remove-labels action'
87+
env:
88+
GITHUB_TOKEN: ${{ secrets.RHODS_CI_BOT_PAT }}
89+
GITHUB_EVENT_NAME: ${{ needs.download_context_artifact.outputs.event_name }}
90+
run: uv run python .github/workflows/scripts/pr_workflow.py
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
if: contains(github.event.comment.body, '/build-push-pr-image')
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout pull request
18+
uses: actions/checkout@v4
19+
with:
20+
ref: refs/pull/${{ github.event.issue.number }}/head
21+
- name: Install uv
22+
uses: astral-sh/setup-uv@v6
23+
24+
- name: Check if the user is authorized
25+
env:
26+
GITHUB_TOKEN: ${{ secrets.RHODS_CI_BOT_PAT }}
27+
GITHUB_PR_NUMBER: ${{ github.event.issue.number }}
28+
GITHUB_EVENT_ACTION: ${{ github.event.action }}
29+
GITHUB_EVENT_REVIEW_STATE: ${{ github.event.review.state }}
30+
GITHUB_EVENT_NAME: ${{ github.event_name }}
31+
COMMENT_BODY: ${{ github.event.comment.body }}
32+
REVIEW_COMMENT_BODY: ${{ github.event.review.body }}
33+
GITHUB_USER_LOGIN: ${{ github.event.sender.login }}
34+
ACTION: "push-container-on-comment"
35+
run: uv run python .github/workflows/scripts/pr_workflow.py
36+
- name: Set env TAG for image
37+
run: |
38+
echo "TAG=pr-${{ github.event.issue.number }}" >> "$GITHUB_ENV"
39+
- name: Build Image to push
40+
id: build-image
41+
uses: redhat-actions/buildah-build@v2
42+
with:
43+
image: opendatahub-tests
44+
tags: ${{ env.TAG }}
45+
containerfiles: |
46+
./Dockerfile
47+
- name: Push To Image Registry
48+
id: push-to-registry
49+
uses: redhat-actions/push-to-registry@v2
50+
with:
51+
image: ${{ steps.build-image.outputs.image }}
52+
tags: ${{ steps.build-image.outputs.tags }}
53+
registry: quay.io/opendatahub
54+
username: ${{ secrets.QUAY_USERNAME }}
55+
password: ${{ secrets.QUAY_PASSWORD }}
56+
57+
- name: Add comment to PR
58+
if: always()
59+
env:
60+
URL: ${{ github.event.issue.comments_url }}
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
run: |
63+
curl \
64+
-X POST \
65+
$URL \
66+
-H "Content-Type: application/json" \
67+
-H "Authorization: token $GITHUB_TOKEN" \
68+
--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 }}." }'

.github/workflows/scripts/constants.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
SUCCESS_STR: str = "success"
1212
FAILURE_STR: str = "failure"
1313
QUEUED_STR: str = "queued"
14+
APPROVED: str = "approved"
1415

1516
SUPPORTED_LABELS: set[str] = {
1617
f"{LABEL_PREFIX}{WIP_LABEL_STR}",
1718
f"{LABEL_PREFIX}{LGTM_LABEL_STR}",
1819
f"{LABEL_PREFIX}{VERIFIED_LABEL_STR}",
1920
f"{LABEL_PREFIX}{HOLD_LABEL_STR}",
21+
f"{LABEL_PREFIX}build-push-pr-image",
22+
f"{LABEL_PREFIX}cherry-pick",
2023
}
2124

2225
CANCEL_ACTION: str = "cancel"
@@ -26,6 +29,7 @@
2629
* Run [pre-commit](https://pre-commit.ci/)
2730
* Run [tox](https://tox.wiki/)
2831
* Add PR author as the PR assignee
32+
* Build image based on the PR
2933
3034
Available user actions:
3135
* To mark a PR as `WIP`, add `/wip` in a comment. To remove it from the PR comment `/wip cancel` to the PR.
@@ -34,6 +38,10 @@
3438
`lgtm` label removed on each new commit push.
3539
* To mark PR as verified comment `/verified` to the PR, to un-verify comment `/verified cancel` to the PR.
3640
`verified` label removed on each new commit push.
41+
* To Cherry-pick a merged PR `/cherry-pick <target_branch_name>` to the PR. If <target_branch_name> is valid,
42+
and the current PR is merged, a cherry-picked PR would be created and linked to the current PR.
43+
* To build and push image to quay, add `/build-push-pr-image` in a comment. This would create an image with tag
44+
pr-<pr_number> to quay repository. This image tag, however would be deleted on PR merge or close action.
3745
3846
<details>
3947
<summary>Supported labels</summary>

0 commit comments

Comments
 (0)