|
| 1 | +name: Secure Integration test |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + branches: main |
| 6 | + |
| 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 | + } |
| 39 | + check-access-and-checkout: |
| 40 | + runs-on: ubuntu-latest |
| 41 | + needs: authorization-check |
| 42 | + environment: ${{ needs.authorization-check.outputs.approval-env }} |
| 43 | + permissions: |
| 44 | + id-token: write |
| 45 | + pull-requests: read |
| 46 | + contents: read |
| 47 | + steps: |
| 48 | + - name: Configure Credentials |
| 49 | + uses: aws-actions/configure-aws-credentials@v4 |
| 50 | + with: |
| 51 | + role-to-assume: ${{ secrets.STRANDS_INTEG_TEST_ROLE }} |
| 52 | + aws-region: us-east-1 |
| 53 | + mask-aws-account-id: true |
| 54 | + - name: Checkout head commit |
| 55 | + uses: actions/checkout@v4 |
| 56 | + with: |
| 57 | + ref: ${{ github.event.pull_request.head.sha }} # Pull the commit from the forked repo |
| 58 | + persist-credentials: false # Don't persist credentials for subsequent actions |
| 59 | + - name: Set up Python |
| 60 | + uses: actions/setup-python@v5 |
| 61 | + with: |
| 62 | + python-version: '3.10' |
| 63 | + - name: Install dependencies |
| 64 | + run: | |
| 65 | + pip install --no-cache-dir hatch |
| 66 | + - name: Run integration tests |
| 67 | + env: |
| 68 | + AWS_REGION: us-east-1 |
| 69 | + id: tests |
| 70 | + run: | |
| 71 | + hatch test tests_integ |
0 commit comments