Skip to content

Commit 82b71a3

Browse files
committed
feat: add ok-to-test workflow approval for external PRs
This workflow solves the current bottleneck where external contributors must wait for maintainer approval to run any workflows, including functional tests. - Problem: Repository requires approval for all outside collaborators' fork PR workflows. Therefore, external contributors can't run functional tests until maintainer approval. Maintainers cannot approve without run functiona tests. This process forces manual local testing and functional validation, slowing down reviews. So we can't enjoy much from function tests and other tests in workflows. In a short, it creates unnecessary friction between PR approval and workflow approval. - Solution: Add pr-approve-workflows.yaml to automatically approve pending workflow runs. Uses pull_request_target with elevated permissions for security and triggers when 'ok-to-test' label is added, separating PR review from workflow approval. This enables external contributors to run functional tests immediately after maintainer adds the ok-to-test label, significantly reducing review time and eliminating the need for manual local testing. This pattern is widely used in other opensource projects. Signed-off-by: josedev-union <[email protected]>
1 parent 9b10349 commit 82b71a3

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

.github/workflows/pr-approve.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
permissions: {}
12+
13+
jobs:
14+
approve:
15+
name: Approve ok-to-test
16+
if: contains(github.event.pull_request.labels.*.name, 'ok-to-test')
17+
runs-on: ubuntu-latest
18+
permissions:
19+
actions: write
20+
steps:
21+
- name: Update PR
22+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
23+
continue-on-error: true
24+
with:
25+
github-token: ${{ secrets.GITHUB_TOKEN }}
26+
script: |
27+
const result = await github.rest.actions.listWorkflowRunsForRepo({
28+
owner: context.repo.owner,
29+
repo: context.repo.repo,
30+
event: "pull_request",
31+
status: "action_required",
32+
head_sha: context.payload.pull_request.head.sha,
33+
per_page: 100
34+
});
35+
36+
for (var run of result.data.workflow_runs) {
37+
await github.rest.actions.approveWorkflowRun({
38+
owner: context.repo.owner,
39+
repo: context.repo.repo,
40+
run_id: run.id
41+
});
42+
}

0 commit comments

Comments
 (0)