@@ -2,41 +2,59 @@ name: Secure Integration test
2
2
3
3
on :
4
4
pull_request_target :
5
- types : [opened, synchronize, labeled, unlabled, reopened]
5
+ branches : main
6
6
7
7
jobs :
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
+ }
8
39
check-access-and-checkout :
9
40
runs-on : ubuntu-latest
41
+ needs : authorization-check
42
+ environment : ${{ needs.authorization-check.outputs.approval-env }}
10
43
permissions :
11
44
id-token : write
12
45
pull-requests : read
13
46
contents : read
14
47
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')
30
48
- name : Configure Credentials
31
49
uses : aws-actions/configure-aws-credentials@v4
32
50
with :
33
51
role-to-assume : ${{ secrets.STRANDS_INTEG_TEST_ROLE }}
34
52
aws-region : us-east-1
35
53
mask-aws-account-id : true
36
- - name : Checkout base branch
54
+ - name : Checkout head commit
37
55
uses : actions/checkout@v4
38
56
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
40
58
persist-credentials : false # Don't persist credentials for subsequent actions
41
59
- name : Set up Python
42
60
uses : actions/setup-python@v5
0 commit comments