Skip to content

Commit 9469a3b

Browse files
committed
Fork PR workflow
1 parent eeb61ca commit 9469a3b

1 file changed

Lines changed: 37 additions & 4 deletions

File tree

.github/workflows/pull-request-build.yml

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
name: Build SDK
22
on:
33
merge_group:
4-
pull_request:
4+
pull_request_target:
5+
types: [opened, synchronize, reopened, labeled]
56
push:
67
branches:
78
- master
@@ -11,16 +12,48 @@ on:
1112
- 'docs/**'
1213

1314
concurrency:
14-
group: start-pull-request-build-${{ github.ref }}
15+
group: start-pull-request-build-${{ github.event.pull_request.number || github.ref }}
1516
cancel-in-progress: true
1617

1718
env:
1819
DOWNLOAD_FOLDER: '.build-scripts/'
1920
SCRIPT_LOCATION: 'workflows/start-pull-request-build/pull-request-build-v1.sh'
2021

2122
jobs:
23+
# Strip the safe-to-build label on every new push from a fork so that
24+
# a maintainer must re-review and re-label after each update.
25+
revoke-approval:
26+
if: >
27+
github.event_name == 'pull_request_target' &&
28+
github.event.action == 'synchronize' &&
29+
github.event.pull_request.head.repo.full_name != github.repository
30+
runs-on: ubuntu-latest
31+
permissions:
32+
pull-requests: write
33+
steps:
34+
- name: Remove safe-to-build label
35+
env:
36+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
run: |
38+
gh api -X DELETE \
39+
"repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/safe-to-build" \
40+
|| true # 404 if label wasn't present
41+
2242
aws-sdk-pr-build:
23-
if: github.event.pull_request.draft == false
43+
needs: revoke-approval
44+
if: >
45+
always() &&
46+
needs.revoke-approval.result != 'failure' &&
47+
(
48+
github.event_name != 'pull_request_target' ||
49+
(
50+
github.event.pull_request.draft == false &&
51+
(
52+
github.event.pull_request.head.repo.full_name == github.repository ||
53+
contains(github.event.pull_request.labels.*.name, 'safe-to-build')
54+
)
55+
)
56+
)
2457
runs-on: ubuntu-latest
2558
permissions:
2659
id-token: write
@@ -49,4 +82,4 @@ jobs:
4982
--branch "$HEAD_REF" \
5083
--pr-number "${{ github.event.pull_request.number }}" \
5184
--run-id "${{ github.run_id }}"
52-
timeout-minutes: 120
85+
timeout-minutes: 120

0 commit comments

Comments
 (0)