88 types :
99 - completed
1010
11+ concurrency :
12+ group : pr-${{ github.event.workflow_run.pull_requests[0].number }}
13+ cancel-in-progress : true
14+
15+
1116jobs :
1217 # Pull requests are valid if:
1318 # - they match the sha of the workflow run head commit
1621 test-pr :
1722 name : " Test if pull request is valid"
1823 runs-on : ubuntu-latest
19- if : >
20- github.event.workflow_run.event == 'pull_request' &&
24+ if : >
25+ github.event.workflow_run.event == 'pull_request' &&
2126 github.event.workflow_run.conclusion == 'success'
2227 outputs :
2328 is_valid : ${{ steps.check-pr.outputs.VALID }}
5863 with :
5964 pr : ${{ steps.get-pr.outputs.NUM }}
6065 sha : ${{ github.event.workflow_run.head_sha }}
66+ headroom : 3 # if it's within the last three commits, we can keep going, because it's likely rapid-fire
6167 invalid : ${{ fromJSON(steps.hash.outputs.json)[github.repository] }}
6268 fail_on_error : true
6369
7278 if : ${{ needs.test-pr.outputs.is_valid == 'true' }}
7379 env :
7480 NR : ${{ needs.test-pr.outputs.number }}
81+ permissions :
82+ contents : write
7583 steps :
7684 - name : ' Checkout md outputs'
7785 uses : actions/checkout@v3
98106 git config --local user.name "GitHub Actions"
99107 CURR_HEAD=$(git rev-parse HEAD)
100108 git checkout --orphan md-outputs-PR-${NR}
101- git add -A
109+ git add -A
102110 git commit -m "source commit: ${CURR_HEAD}"
103- ls -A | grep -v '^.git$' | xargs rm -r
111+ ls -A | grep -v '^.git$' | xargs -I _ rm -r '_'
104112 cd ..
105113 unzip -o -d built built.zip
106114 cd built
@@ -116,14 +124,16 @@ jobs:
116124 if : ${{ needs.test-pr.outputs.is_valid == 'true' }}
117125 env :
118126 NR : ${{ needs.test-pr.outputs.number }}
127+ permissions :
128+ pull-requests : write
119129 steps :
120130 - name : ' Download comment artifact'
121131 id : dl
122132 uses : carpentries/actions/download-workflow-artifact@main
123133 with :
124134 run : ${{ github.event.workflow_run.id }}
125135 name : ' diff'
126-
136+
127137 - if : ${{ steps.dl.outputs.success == 'true' }}
128138 run : unzip ${{ github.workspace }}/diff.zip
129139
@@ -132,7 +142,7 @@ jobs:
132142 if : ${{ steps.dl.outputs.success == 'true' }}
133143 uses : carpentries/actions/comment-diff@main
134144 with :
135- pr : ${{ env.NR }}
145+ pr : ${{ env.NR }}
136146 path : ${{ github.workspace }}/diff.md
137147
138148 # Comment if the PR is open and matches the SHA, but the workflow files have
@@ -145,6 +155,8 @@ jobs:
145155 env :
146156 NR : ${{ github.event.workflow_run.pull_requests[0].number }}
147157 body : ${{ needs.test-pr.outputs.msg }}
158+ permissions :
159+ pull-requests : write
148160 steps :
149161 - name : ' Check for spoofing'
150162 id : dl
0 commit comments