@@ -2,41 +2,59 @@ name: Secure Integration test
22
33on :
44 pull_request_target :
5- types : [opened, synchronize, labeled, unlabled, reopened]
5+ branches : main
66
77jobs :
8+ authorization-check :
9+ permissions : read-all
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+ result-encoding : string
19+ script : |
20+ try {
21+ const permissionResponse = await github.rest.repos.getCollaboratorPermissionLevel({
22+ owner: context.repo.owner,
23+ repo: context.repo.repo,
24+ username: context.payload.pull_request.user.login,
25+ });
26+ const permission = permissionResponse.data.permission;
27+ const hasWriteAccess = ['write', 'admin'].includes(permission);
28+ if (!hasWriteAccess) {
29+ console.log(`User ${context.payload.pull_request.user.login} does not have write access to the repository (permission: ${permission})`);
30+ return "manual-approval"
31+ } else {
32+ console.log(`Verifed ${context.payload.pull_request.user.login} has write access. Auto Approving PR Checks.`)
33+ return "auto-approve"
34+ }
35+ } catch (error) {
36+ console.log(`${context.payload.pull_request.user.login} does not have write access. Requiring Manual Approval to run PR Checks.`)
37+ return "manual-approval"
38+ }
839 check-access-and-checkout :
940 runs-on : ubuntu-latest
41+ needs : authorization-check
42+ environment : ${{ needs.authorization-check.outputs.approval-env }}
1043 permissions :
1144 id-token : write
1245 pull-requests : read
1346 contents : read
1447 steps :
15- - name : Check PR labels and author
16- id : check
17- uses : actions/github-script@v7
18- with :
19- script : |
20- const pr = context.payload.pull_request;
21-
22- const labels = pr.labels.map(label => label.name);
23- const hasLabel = labels.includes('approved-for-integ-test')
24- if (hasLabel) {
25- core.info('PR contains label approved-for-integ-test')
26- return
27- }
28-
29- core.setFailed('Pull Request must either have label approved-for-integ-test')
3048 - name : Configure Credentials
3149 uses : aws-actions/configure-aws-credentials@v4
3250 with :
3351 role-to-assume : ${{ secrets.STRANDS_INTEG_TEST_ROLE }}
3452 aws-region : us-east-1
3553 mask-aws-account-id : true
36- - name : Checkout base branch
54+ - name : Checkout head commit
3755 uses : actions/checkout@v4
3856 with :
39- ref : ${{ github.event.pull_request.head.ref }} # Pull the commit from the forked repo
57+ ref : ${{ github.event.pull_request.head.sha }} # Pull the commit from the forked repo
4058 persist-credentials : false # Don't persist credentials for subsequent actions
4159 - name : Set up Python
4260 uses : actions/setup-python@v5
0 commit comments