File tree Expand file tree Collapse file tree 2 files changed +54
-1
lines changed
actions/check-authorization Expand file tree Collapse file tree 2 files changed +54
-1
lines changed Original file line number Diff line number Diff line change 1+ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+ # SPDX-License-Identifier: Apache-2.0 OR ISC
3+
4+ name : ' check-authorization'
5+ description : ' A helper action to determine the authorization level of a pull request for running CI'
6+ outputs :
7+ approval-env :
8+ description : ' The target environment to use for the workflow'
9+ value : ${{ steps.collab-check.outputs.result }}
10+ runs :
11+ using : ' composite'
12+ steps :
13+ - name : Collaborator Check
14+ uses : actions/github-script@v8
15+ id : collab-check
16+ with :
17+ result-encoding : string
18+ script : |
19+ try {
20+ const permissionResponse = await github.rest.repos.getCollaboratorPermissionLevel({
21+ owner: context.repo.owner,
22+ repo: context.repo.repo,
23+ username: context.payload.pull_request.user.login,
24+ });
25+ const permission = permissionResponse.data.permission;
26+ const hasWriteAccess = ['write', 'admin'].includes(permission);
27+ if (!hasWriteAccess) {
28+ console.log(`User ${context.payload.pull_request.user.login} does not have write access to the repository (permission: ${permission})`);
29+ return "manual-approval"
30+ } else {
31+ console.log(`Verifed ${context.payload.pull_request.user.login} has write access. Auto Approving PR Checks.`)
32+ return "auto-approve"
33+ }
34+ } catch (error) {
35+ console.log(`${context.payload.pull_request.user.login} does not have write access. Requiring Manual Approval to run PR Checks.`)
36+ return "manual-approval"
37+ }
Original file line number Diff line number Diff line change @@ -29,7 +29,21 @@ permissions:
2929 contents : read
3030
3131jobs :
32+ authorization-check :
33+ outputs :
34+ approval-env : ${{ steps.authz.outputs.approval-env }}
35+ runs-on :
36+ - codebuild-aws-lc-ci-github-actions-${{ github.run_id }}-${{ github.run_attempt }}
37+ image:linux-5.0
38+ instance-size:small
39+ steps :
40+ - uses : actions/checkout@v5
41+ - uses : ./.github/actions/check-authorization
42+ id : authz
43+
3244 build :
45+ needs : [authorization-check]
46+ environment : ${{ needs.authorization-check.outputs.approval-env }}
3347 runs-on :
3448 codebuild-aws-lc-ci-github-actions-${{ github.run_id }}-${{ github.run_attempt }}
3549 image:linux-5.0
3953 steps :
4054 - uses : actions/checkout@v5
4155 with :
42- ref : ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.ref || github.ref }}
56+ ref : ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.ref }}
4357 - name : Query Environment
4458 id : env
4559 run : |
@@ -74,11 +88,13 @@ jobs:
7488
7589 push :
7690 if : ${{ github.event_name != 'pull_request_target' }}
91+ environment : ${{ needs.authorization-check.outputs.approval-env }}
7792 runs-on :
7893 codebuild-aws-lc-ci-github-actions-${{ github.run_id }}-${{ github.run_attempt }}
7994 image:linux-5.0
8095 instance-size:small
8196 needs :
97+ - authorization-check
8298 - build
8399 outputs :
84100 android : ${{ steps.images.outputs.android }}
You can’t perform that action at this time.
0 commit comments