Skip to content

Commit 024329d

Browse files
add-workflow-approval (#146)
1 parent b06b2ca commit 024329d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

.github/workflows/python-package.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,36 @@ name: Python package
66
on: [push, pull_request]
77

88
jobs:
9+
collab-check:
10+
runs-on: ubuntu-latest
11+
outputs:
12+
approval-env: ${{ steps.collab-check.outputs.result }}
13+
steps:
14+
- name: Collaborator Check
15+
uses: actions/github-script@v7
16+
id: collab-check
17+
with:
18+
github-token: ${{ github.token }}
19+
result-encoding: string
20+
script: |
21+
try {
22+
const res = await github.rest.repos.checkCollaborator({
23+
owner: context.repo.owner,
24+
repo: context.repo.repo,
25+
username: "${{ github.event.pull_request.user.login }}",
26+
});
27+
console.log("Verifed ${{ github.event.pull_request.user.login }} is a repo collaborator. Auto Approving PR Checks.")
28+
return res.status == "204" ? "auto-approve" : "manual-approval"
29+
} catch (error) {
30+
console.log("${{ github.event.pull_request.user.login }} is not a collaborator. Requiring Manual Approval to run PR Checks.")
31+
return "manual-approval"
32+
}
33+
wait-for-approval:
34+
runs-on: ubuntu-latest
35+
needs: [collab-check]
36+
environment: ${{ needs.collab-check.outputs.approval-env }}
37+
steps:
38+
- run: echo "Workflow Approved! Starting PR Checks."
939
test:
1040
runs-on: ubuntu-latest
1141
strategy:

0 commit comments

Comments
 (0)