Skip to content

Commit dc48b82

Browse files
feat: run workflows on /ok-to-test label (#2639)
* run workflows on `/ok-to-test` Signed-off-by: milinddethe15 <milinddethe15@gmail.com> * Add membership check to auto-approve workflows for org members Signed-off-by: milinddethe15 <milinddethe15@gmail.com> --------- Signed-off-by: milinddethe15 <milinddethe15@gmail.com>
1 parent 58ff1b7 commit dc48b82

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Approve Workflow Runs
2+
3+
permissions:
4+
actions: write
5+
contents: read
6+
7+
on:
8+
pull_request_target:
9+
types:
10+
- labeled
11+
- synchronize
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event.number }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
ok-to-test:
19+
if: contains(github.event.pull_request.labels.*.name, 'ok-to-test') || github.event_name == 'pull_request_target'
20+
runs-on: ubuntu-latest
21+
continue-on-error: true
22+
23+
steps:
24+
- name: Check if author is a Kubeflow GitHub member
25+
id: membership-check
26+
uses: actions/github-script@v7
27+
with:
28+
script: |
29+
const username = context.payload.pull_request.user.login;
30+
const org = context.repo.owner;
31+
try {
32+
const res = await github.rest.orgs.checkMembershipForUser({
33+
org,
34+
username
35+
});
36+
core.setOutput("is_member", true);
37+
} catch (error) {
38+
if (error.status === 404) {
39+
// User is not a member
40+
core.setOutput("is_member", false);
41+
} else {
42+
throw error;
43+
}
44+
}
45+
46+
- name: Approve Pending Workflow Runs
47+
if: steps.membership-check.outputs.is_member == 'true' || contains(github.event.pull_request.labels.*.name, 'ok-to-test')
48+
uses: actions/github-script@v7
49+
with:
50+
retries: 3
51+
script: |
52+
const request = {
53+
owner: context.repo.owner,
54+
repo: context.repo.repo,
55+
event: "pull_request",
56+
status: "action_required",
57+
head_sha: context.payload.pull_request.head.sha,
58+
}
59+
60+
core.info(`Getting workflow runs that need approval for commit ${request.head_sha}`)
61+
const runs = await github.paginate(github.rest.actions.listWorkflowRunsForRepo, request)
62+
63+
core.info(`Found ${runs.length} workflow runs that need approval`)
64+
for (const run of runs) {
65+
core.info(`Approving workflow run ${run.id}`)
66+
const request = {
67+
owner: context.repo.owner,
68+
repo: context.repo.repo,
69+
run_id: run.id,
70+
}
71+
await github.rest.actions.approveWorkflowRun(request)
72+
}

0 commit comments

Comments
 (0)