Skip to content

Commit d99927b

Browse files
committed
Allow runing github action with ok-to-test
Github actions are not running for non-member contributors, unless a repo admin presses the "Approve and Run" button. The problem with that is that PRs are getting merged with no verification, causing leak of bugs into the codebase. This PR copies a github action from the cluster-api repo, that approve running the github action by adding the `ok-to-test` label. Source: https://github.com/kubernetes-sigs/cluster-api/blob/613a37e0183e818403ff086165bd619393b34178/.github/workflows/pr-gh-workflow-approve.yaml Signed-off-by: Nahshon Unna-Tsameret <[email protected]>
1 parent b5ebf7b commit d99927b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: PR approve GH Workflows
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- edited
7+
- labeled
8+
- reopened
9+
- synchronize
10+
11+
jobs:
12+
approve:
13+
name: Approve ok-to-test
14+
if: (github.repository == 'kubernetes-sigs/cluster-api-provider-kubevirt') && contains(github.event.pull_request.labels.*.name, 'ok-to-test')
15+
runs-on: ubuntu-latest
16+
permissions:
17+
actions: write
18+
steps:
19+
- name: Update PR
20+
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
21+
continue-on-error: true
22+
with:
23+
github-token: ${{ secrets.GITHUB_TOKEN }}
24+
script: |
25+
const result = await github.rest.actions.listWorkflowRunsForRepo({
26+
owner: context.repo.owner,
27+
repo: context.repo.repo,
28+
event: "pull_request",
29+
status: "action_required",
30+
head_sha: context.payload.pull_request.head.sha,
31+
per_page: 100
32+
});
33+
34+
for (var run of result.data.workflow_runs) {
35+
await github.rest.actions.approveWorkflowRun({
36+
owner: context.repo.owner,
37+
repo: context.repo.repo,
38+
run_id: run.id
39+
});
40+
}

0 commit comments

Comments
 (0)