Skip to content

Commit 5088591

Browse files
committed
ci: merge main branch
2 parents a21986a + db4ff0c commit 5088591

File tree

4 files changed

+128
-4
lines changed

4 files changed

+128
-4
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
runs-on: ubuntu-latest
21+
steps:
22+
- name: 'Download artifact'
23+
uses: actions/github-script@v7
24+
with:
25+
script: |
26+
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
27+
owner: context.repo.owner,
28+
repo: context.repo.repo,
29+
run_id: context.payload.workflow_run.id,
30+
});
31+
32+
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
33+
return artifact.name == "context.json"
34+
})[0];
35+
36+
let download = await github.rest.actions.downloadArtifact({
37+
owner: context.repo.owner,
38+
repo: context.repo.repo,
39+
artifact_id: matchArtifact.id,
40+
archive_format: 'zip',
41+
});
42+
43+
let fs = require('fs');
44+
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/context.zip`, Buffer.from(download.data));
45+
46+
- name: 'Unzip artifact'
47+
run: unzip context.zip
48+
- name: 'Return Parsed JSON'
49+
uses: actions/github-script@v7
50+
id: return-parsed-json
51+
with:
52+
script: |
53+
let fs = require('fs');
54+
let data = fs.readFileSync('./context.json');
55+
return JSON.parse(data);
56+
outputs:
57+
pr_num: ${{fromJSON(steps.return-parsed-json.outputs.result).pr_num}}
58+
event_action: ${{fromJSON(steps.return-parsed-json.outputs.result).event_action}}
59+
review_state: ${{fromJSON(steps.return-parsed-json.outputs.result).review_state}}
60+
event_name: ${{fromJSON(steps.return-parsed-json.outputs.result).event_name}}
61+
comment_body: ${{fromJSON(steps.return-parsed-json.outputs.result).comment_body}}
62+
review_comment_body: ${{fromJSON(steps.return-parsed-json.outputs.result).review_comment_body}}
63+
user_login: ${{fromJSON(steps.return-parsed-json.outputs.result).user_login}}
64+
action: ${{fromJSON(steps.return-parsed-json.outputs.result).action}}
65+
log_context_values:
66+
needs:
67+
- download_context_artifact
68+
runs-on: ubuntu-latest
69+
steps:
70+
- name: 'Set all Env Variable'
71+
run: |
72+
echo "GITHUB_PR_NUMBER=${{ needs.download_context_artifact.outputs.pr_num }}" >> "$GITHUB_ENV"
73+
echo "GITHUB_EVENT_ACTION=${{ needs.download_context_artifact.outputs.event_action }}" >> "$GITHUB_ENV"
74+
echo "GITHUB_EVENT_REVIEW_STATE=${{ needs.download_context_artifact.outputs.review_state }}" >> "$GITHUB_ENV"
75+
echo "GITHUB_EVENT_NAME=${{ needs.download_context_artifact.outputs.event_name }}" >> "$GITHUB_ENV"
76+
echo "COMMENT_BODY=${{ needs.download_context_artifact.outputs.comment_body }}" >> "$GITHUB_ENV"
77+
echo "REVIEW_COMMENT_BODY=${{ needs.download_context_artifact.outputs.review_comment_body }}" >> "$GITHUB_ENV"
78+
echo "GITHUB_USER_LOGIN=${{ needs.download_context_artifact.outputs.user_login }}" >> "$GITHUB_ENV"
79+
echo "ACTION=${{ needs.download_context_artifact.outputs.action }}" >> "$GITHUB_ENV"
80+
- uses: actions/checkout@v4
81+
82+
- name: Install uv
83+
uses: astral-sh/setup-uv@v5
84+
- name: 'Run add-remove-labels action'
85+
env:
86+
GITHUB_TOKEN: ${{ secrets.OPENDATAHUB_TESTS_BOT_PAT }}
87+
GITHUB_EVENT_NAME: ${{ needs.download_context_artifact.outputs.event_name }}
88+
run: uv run python .github/workflows/scripts/pr_workflow.py

.github/workflows/scripts/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
SUCCESS_STR: str = "success"
1212
FAILURE_STR: str = "failure"
1313
QUEUED_STR: str = "queued"
14-
APPROVED: str = "APPROVED"
14+
APPROVED: str = "approved"
1515

1616
SUPPORTED_LABELS: set[str] = {
1717
f"{LABEL_PREFIX}{WIP_LABEL_STR}",

.github/workflows/scripts/pr_workflow.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,13 @@ def add_remove_pr_labels(self) -> None:
246246

247247
elif self.event_name == "pull_request_review":
248248
self.pull_request_review_label_actions()
249-
self.issue_comment_label_actions()
250249

251250
return
252251

252+
# We will only reach here if the PR was created from a fork
253+
elif self.event_name == "workflow_run" and self.event_action == "submitted":
254+
self.pull_request_review_label_actions()
255+
253256
LOGGER.warning("`add_remove_pr_label` called without a supported event")
254257

255258
def pull_request_review_label_actions(
@@ -267,11 +270,11 @@ def pull_request_review_label_actions(
267270
label_to_remove = change_requested_label
268271
label_to_add = lgtm_label
269272

270-
elif self.review_state == "CHANGES_REQUESTED":
273+
elif self.review_state == "changes_requested":
271274
label_to_add = change_requested_label
272275
label_to_remove = lgtm_label
273276

274-
elif self.review_state == "COMMENTED":
277+
elif self.review_state == "commented":
275278
label_to_add = f"{COMMENTED_BY_LABEL_PREFIX}{self.user_login}"
276279

277280
if label_to_add and label_to_add not in self.pr_labels:
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Dummy Workflow on review
2+
3+
on:
4+
pull_request_review:
5+
types: [submitted, edited]
6+
7+
permissions:
8+
pull-requests: write
9+
contents: write
10+
issues: write
11+
12+
jobs:
13+
14+
dummy-workflow:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: save the pr information
19+
run: |
20+
printf '{
21+
"pr_num": "${{ github.event.pull_request.number || github.event.issue.number }}",
22+
"event_action": "${{ github.event.action }}",
23+
"review_state": "${{ github.event.review.state }}",
24+
"event_name": "${{ github.event_name }}",
25+
"comment_body": "${{ github.event.comment.body }}",
26+
"review_comment_body": "${{ github.event.review.body }}",
27+
"user_login": "${{ github.event.sender.login }}",
28+
"action": "add-remove-labels"
29+
}' >> context.json
30+
- uses: actions/upload-artifact@v4
31+
with:
32+
name: context.json
33+
path: ./

0 commit comments

Comments
 (0)