Skip to content

Commit 027142c

Browse files
authored
ci: Fix PR reporter for non-main branch targets (#4900)
1 parent 5dd6c09 commit 027142c

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

.github/workflows/pr-reporter.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,37 @@ jobs:
1919
jsChanged: ${{ steps.filter.outputs.jsChanged }}
2020
steps:
2121
- uses: actions/checkout@v4
22+
23+
# Warning: This is kinda gnarly and weird! GitHub doesn't expose the `pull_request`
24+
# data if the PR is from a fork, nor does it let you access that data via their API
25+
# (by querying for PRs associated with the commit or querying the commit itself, both
26+
# come up empty for forked commits). As such, to get the base SHA of the PR we need to
27+
# query for all PRs on the repo and match the owner+branch to find the right one and
28+
# then extract the base SHA from that.
29+
#
30+
# I see no reason why GitHub shouldn't expose this, it's just an SHA, branch name, and
31+
# URL, but they don't so we're doing it this way. Hopefully we can remove this one day.
32+
- name: Get PR Base SHA
33+
id: get_pr_base_sha
34+
env:
35+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
FORK_OWNER: ${{ github.event.workflow_run.head_repository.owner.login }}
37+
FORK_BRANCH: ${{ github.event.workflow_run.head_branch }}
38+
run: |
39+
set -euo pipefail
40+
41+
PR_JSON=$(gh api "repos/preactjs/preact/pulls?state=all&head=$FORK_OWNER:$FORK_BRANCH")
42+
BASE_SHA=$(jq -r '.[0].base.sha' <<< "$PR_JSON")
43+
44+
echo "base_sha=$BASE_SHA" >> "$GITHUB_OUTPUT"
45+
2246
- uses: dorny/paths-filter@v3
2347
id: filter
2448
with:
2549
# As this Workflow is triggered by a `workflow_run` event, the filter action
2650
# can't automatically assume we're working with PR data. As such, we need to
2751
# wire it up manually with a base (merge target) and ref (source branch).
28-
base: ${{ github.sha }}
52+
base: ${{ steps.get_pr_base_sha.outputs.base_sha }}
2953
ref: ${{ github.event.workflow_run.head_sha }}
3054
# Should be kept in sync with the filter in the CI workflow
3155
predicate-quantifier: 'every'

0 commit comments

Comments
 (0)