Skip to content

Commit f4e69a8

Browse files
authored
Correctly compare to main for stacked prs. (#259)
1 parent 961661a commit f4e69a8

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎.github/workflows/visual.yml‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
- uses: actions/checkout@v4
4444
with:
4545
submodules: true
46-
# PR checkouts are merge commits; HEAD^1 is the main commit they're compared against.
46+
# PR checkouts are merge commits; HEAD^1 leads back to the main commit they're compared against.
4747
fetch-depth: 2
4848
persist-credentials: false
4949

@@ -85,7 +85,9 @@ jobs:
8585
env:
8686
GH_TOKEN: ${{ github.token }}
8787
run: |
88-
sha=$(git rev-parse HEAD^1)
88+
# Stacked PRs merge onto their parents' merge commits, so compare against the main commit
89+
# at the bottom of the stack rather than HEAD^1 itself.
90+
sha=$(gh api "repos/$GITHUB_REPOSITORY/compare/main...$(git rev-parse HEAD^1)" --jq .merge_base_commit.sha)
8991
latest() {
9092
gh run list -R "$GITHUB_REPOSITORY" --workflow visual.yml --branch main --event push \
9193
--commit "$sha" --limit 1 --json databaseId,status,conclusion --jq '.[0] // empty'
@@ -99,7 +101,7 @@ jobs:
99101
fi
100102
if [ "$(jq -r '.conclusion // empty' <<< "$run")" = success ] &&
101103
gh run download "$(jq -r .databaseId <<< "$run")" -R "$GITHUB_REPOSITORY" -n visual-screenshots -D out/baseline; then
102-
echo "Using screenshots from run $(jq -r .databaseId <<< "$run")"
104+
echo "Using screenshots from main at $sha (run $(jq -r .databaseId <<< "$run"))"
103105
else
104106
echo "::notice::No screenshots published for main at $sha; cases are reported as new"
105107
fi

0 commit comments

Comments
 (0)