Skip to content

Commit 4ad6a6d

Browse files
edmundhungdario-piotrowiczpetebacondarwin
authored
chore: run ci for external forks by commit sha (#9306)
* chore: run ci for external forks by commit sha * restrict access * Update .github/workflows/run-ci-for-external-forks.yml Co-authored-by: Pete Bacon Darwin <[email protected]> --------- Co-authored-by: Dario Piotrowicz <[email protected]> Co-authored-by: Pete Bacon Darwin <[email protected]>
1 parent 7344344 commit 4ad6a6d

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

.github/workflows/run-ci-for-external-forks.yml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ on:
55
pr-number:
66
description: "The PR number to run CI on behalf of"
77
required: true
8+
commit-sha:
9+
description: "The specific commit SHA from the PR branch to run CI on"
10+
required: true
811
reviewed:
912
description: "Confirm that the PR has been reviewed for use/leakage of secrets"
1013
type: boolean
@@ -15,6 +18,7 @@ jobs:
1518
if: ${{ inputs.reviewed == true }}
1619
runs-on: ubuntu-latest
1720
permissions:
21+
# We use the default token to create the draft PR only
1822
pull-requests: write
1923
contents: write
2024
steps:
@@ -24,29 +28,42 @@ jobs:
2428
fetch-depth: 0
2529

2630
- name: Check user for team affiliation
27-
uses: tspascoal/get-user-teams-membership@v2
31+
uses: tspascoal/get-user-teams-membership@ba78054988f58bea69b7c6136d563236f8ed2fc0
2832
id: teamAffiliation
2933
with:
3034
GITHUB_TOKEN: ${{ secrets.READ_ONLY_ORG_GITHUB_TOKEN }}
3135
username: ${{ github.actor }}
3236
team: wrangler
3337

3438
- name: Stop workflow if user is not a team member
35-
if: ${{ steps.teamAffiliation.outputs.isTeamMember == false }}
39+
if: ${{ steps.teamAffiliation.outputs.isTeamMember != 'true' }}
3640
run: |
37-
echo "You must be on the "wrangler" team to trigger this job."
41+
echo "You must be on the \"wrangler\" team to trigger this job."
3842
exit 1
3943
4044
- name: "Checkout PR"
41-
run: gh pr checkout ${{ inputs.pr-number }} -b run-ci-on-behalf-of-${{ inputs.pr-number }} -f
45+
run: |
46+
gh pr checkout "$PR_NUM" --branch "run-ci-on-behalf-of-$PR_NUM"
47+
git reset --hard "$COMMIT_SHA"
4248
env:
49+
# We need a PAT to checkout the fork
4350
GH_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
51+
PR_NUM: ${{ inputs.pr-number }}
52+
COMMIT_SHA: ${{ inputs.commit-sha }}
4453

4554
- name: Push Branch
4655
run: git push origin HEAD --force
4756

4857
- name: "Create Draft PR"
4958
run: |
50-
gh pr create --head run-ci-on-behalf-of-${{ inputs.pr-number }} --draft --label "e2e" --title "Run CI on behalf of #${{ inputs.pr-number }}" --body "This PR is created to run CI on behalf of \#${{ inputs.pr-number }}. It can be closed after the CI run is complete."
59+
gh pr create \
60+
--head "run-ci-on-behalf-of-$PR_NUM" \
61+
--draft \
62+
--label "e2e" \
63+
--title "$TITLE" \
64+
--body "$BODY"
5165
env:
52-
GH_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }}
66+
GH_TOKEN: ${{ github.token }}
67+
PR_NUM: ${{ inputs.pr-number }}
68+
TITLE: "Run CI on behalf of #${{ inputs.pr-number }} @${{ inputs.commit-sha }}"
69+
BODY: "This PR runs CI on behalf of #${{ inputs.pr-number }} at commit ${{ inputs.commit-sha }}. It can be closed after the CI run is complete."

0 commit comments

Comments
 (0)