|
5 | 5 | branches: [master] |
6 | 6 | pull_request: |
7 | 7 | branches: [master] |
| 8 | + # Added in response to recent changes by GitHub on 1 March 2021 involving dependabot pull requests running with read only permissions which resulted in by default GitHub secrets are unable to be read. |
| 9 | + # References: |
| 10 | + # https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target (Announcement of changes to be made to dependabot pull requests) |
| 11 | + # https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ (Recommended security mitigations by GitHub) |
| 12 | + # https://github.com/dependabot/dependabot-core/issues/3253#issuecomment-797125425 (Ongoing GitHub issues by users in response to the changes) |
| 13 | + pull_request_target: |
| 14 | + branches: [master] |
8 | 15 |
|
9 | 16 | jobs: |
10 | 17 | build: |
11 | 18 | runs-on: ubuntu-latest |
12 | 19 |
|
13 | 20 | timeout-minutes: 18 |
14 | 21 |
|
| 22 | + # If the Pull Request is coming from a fork (pull_request_target), ensure it's opened by "dependabot[bot]". Otherwise, clone it normally. |
| 23 | + # References: |
| 24 | + # https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target |
| 25 | + # https://github.com/dependabot/dependabot-core/issues/3253#issuecomment-797125425 (dependabot PM recommended solution) |
| 26 | + |
| 27 | + if: |
| 28 | + ${{ (github.event_name == 'pull_request_target' && github.actor == 'dependabot[bot]') || |
| 29 | + (github.event_name != 'pull_request_target' && github.actor != 'dependabot[bot]') }} |
| 30 | + |
15 | 31 | steps: |
16 | 32 | - name: checkout |
| 33 | + if: ${{ github.event_name != 'pull_request_target' }} |
| 34 | + uses: actions/checkout@v2.3.4 |
| 35 | + |
| 36 | + - name: checkout Pull Request (dependabot[bot] only) |
| 37 | + if: ${{ github.event_name == 'pull_request_target' }} |
17 | 38 | uses: actions/checkout@v2.3.4 |
| 39 | + with: |
| 40 | + # Without ref with pull_request_target, it does not actually build the PR, instead it builds the latest changeset from the target repository which is not the intended behaviour. (Reference: https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ [Last example]) |
| 41 | + ref: ${{ github.event.pull_request.head.sha }} |
| 42 | + |
18 | 43 | # Pull the latest image to build, and avoid caching pull-only images. |
19 | 44 | # (docker pull is faster than caching in most cases.) |
20 | 45 | - name: docker-compose pull |
21 | 46 | run: docker-compose pull |
| 47 | + |
22 | 48 | - name: docker layer caching |
23 | 49 | uses: satackey/action-docker-layer-caching@v0.0.11 |
24 | 50 | continue-on-error: true |
| 51 | + |
25 | 52 | - name: Run test in container |
26 | 53 | shell: bash |
27 | 54 | env: |
|
0 commit comments