88permissions :
99 contents : read
1010 actions : read
11- pull-requests : write
11+
12+ concurrency :
13+ group : ${{ github.workflow }}-${{ github.event.workflow_run.id }}
14+ cancel-in-progress : true
1215
1316jobs :
1417 aggregate :
1518 name : Aggregate Comparison Results
1619 runs-on : ubuntu-latest
20+ permissions :
21+ pull-requests : write
22+
1723 steps :
1824 - name : Harden Runner
1925 uses : step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
@@ -40,24 +46,41 @@ jobs:
4046 echo "EOF"
4147 } >> "$GITHUB_OUTPUT"
4248
43- # `github.event.workflow_run.pull_requests` is only populated for PRs from
44- # branches in this repository; for fork PRs it is empty, so we resolve the
45- # PR number from the head repository and branch instead.
46- - name : Resolve PR number
49+ - name : Resolve Pull Request Number
4750 id : pr
4851 if : steps.combine.outputs.combined
49- env :
50- GH_TOKEN : ${{ github.token }}
51- HEAD_REPO : ${{ github.event.workflow_run.head_repository.login }}
52- HEAD_BRANCH : ${{ github.event.workflow_run.head_branch }}
53- run : |
54- PR_NUMBER=$(gh api \
55- "repos/${GITHUB_REPOSITORY}/pulls?head=${HEAD_REPO}:${HEAD_BRANCH}" \
56- --jq '[.[] | select(.state == "open")][0].number // .[0].number // empty')
57- echo "number=${PR_NUMBER:-}" >> "$GITHUB_OUTPUT"
52+ uses : actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
53+ with :
54+ script : |
55+ const run = context.payload.workflow_run;
56+
57+ // 1. For same-repo Pull Requests the run is already linked to its PR(s).
58+ if (run.pull_requests && run.pull_requests.length) {
59+ core.setOutput('number', run.pull_requests[0].number);
60+ return;
61+ }
62+
63+ // 2. For forks that list is empty, so find the open Pull Request who has the
64+ // correct branch information
65+ const match = await github.rest.pulls.list({
66+ owner: context.repo.owner,
67+ repo: context.repo.repo,
68+ state: 'open',
69+ head: `${run.head_repository.owner.login}:${run.head_branch}`,
70+ sort: 'updated',
71+ direction: 'desc',
72+ per_page: 1,
73+ }).then(r => r.data[0]);
74+
75+ if (!match) {
76+ core.info(`No open pull request found for HEAD ${run.head_sha}`);
77+ return;
78+ }
79+
80+ core.setOutput('number', match.number);
5881
5982 - name : Add Comment to PR
60- if : steps.combine.outputs.combined && steps.pr.outputs.number
83+ if : steps.combine.outputs.combined && steps.pr.outputs.number != ''
6184 uses : thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1
6285 with :
6386 comment-tag : compared
0 commit comments