Use the merge-base of a PR when comparing SASS changes, not the instantaneous main - #11191
Use the merge-base of a PR when comparing SASS changes, not the instantaneous main#11191Jacobfaib wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review. 📝 SummarySummary by CodeRabbit
WalkthroughThe pull-request workflow now computes and exports ChangesSASS merge-base handling
Assessment against linked issues
Merge Risk: ⚪ Minimal · up to The workflow now uses a shared merge-base SHA for pull-request SASS comparisons, avoiding attribution of later main-branch changes to the pull request. No current merge-blocking risk remains. Comment |
This comment has been minimized.
This comment has been minimized.
| echo "base_sha=${BASE_SHA}" | tee -a "${GITHUB_OUTPUT}" | ||
| echo "pr_number=${{ fromJSON(steps.get-pr-info.outputs.pr-info).number }}" | tee -a "${GITHUB_OUTPUT}" | ||
| git fetch origin "${BASE_SHA}" -q | ||
| echo "merge_base_sha=$(git merge-base "${BASE_SHA}" "${GITHUB_SHA}")" | tee -a "${GITHUB_OUTPUT}" |
There was a problem hiding this comment.
Do we need a fail early for PRs that do not merge cleanly?
There was a problem hiding this comment.
The merge-base path does not merge the PRs. merge-base is the first common commit between 2 branches, so in the diagrams above it asks for commit B. Since every branch is some descendant of main it is infallible.
bernhardmgruber
left a comment
There was a problem hiding this comment.
The logic LGTM, but claude thinks we should add an additional check (my knowledge on github workflows is close to zero):
| echo "base_sha=${{ fromJSON(steps.get-pr-info.outputs.pr-info).base.sha }}" | tee -a "${GITHUB_OUTPUT}" | ||
| echo "base_sha=${BASE_SHA}" | tee -a "${GITHUB_OUTPUT}" | ||
| echo "pr_number=${{ fromJSON(steps.get-pr-info.outputs.pr-info).number }}" | tee -a "${GITHUB_OUTPUT}" | ||
| git fetch origin "${BASE_SHA}" -q |
There was a problem hiding this comment.
So, claude is telling me that this line should be guarded:
- runs git fetch/git merge-base on BASE_SHA with no guard.
- The step it replaces (branch-notes-dirt, introduced in Add .branch_notes. #7238) explicitly guarded this exact computation with:
if [[ -z "${BASE_SHA}" ]]; then
echo "branch_notes_dirt=" >> "${GITHUB_OUTPUT}"
exit 0
fi - This guard exists because BASE_SHA (fromJSON(get-pr-info.outputs.pr-info).base.sha) can genuinely be empty — this workflow also triggers on push to pull-request/[0-9]+ branches, where get-pr-info may not resolve a linked PR.
- Since the whole workflow runs under defaults.run.shell: bash --noprofile --norc -euo pipefail, an empty BASE_SHA will now make git fetch origin "" (or git merge-base "" "$GITHUB_SHA") fail with -e, aborting the entire build-workflow job — not just gracefully degrading the .branch_notes check as before. This is a behavior change/regression for the exact edge case the original guard was written to handle.
- Suggestion: wrap the fetch/merge-base computation in the same if [[ -z "${BASE_SHA}" ]]; then ... fi guard (emitting an empty merge_base_sha in that branch), and keep the downstream consumers (dispatch-sass-diff, branch-notes-dirt) tolerant of an empty value, matching prior behavior.
There was a problem hiding this comment.
BASE_SHA (fromJSON(get-pr-info.outputs.pr-info).base.sha) can genuinely be empty — this workflow also triggers on push to pull-request/[0-9]+ branches, where get-pr-info may not resolve a linked PR.
I don't think it's possible for get-pr-info to ever return an empty base sha. Any pull-request created against CCCL should always create a pull-request/1234 pointing to the original PR courtesy of the nv-copy-pr bot.
But could be wrong, @trxcllnt to confirm the above ^^.
🥳 CI Workflow Results🟩 Finished in 13h 55m: Pass: 100%/501 | Total: 6d 16h | Max: 2h 09m | Hits: 89%/880320See results here. |
Description
closes #11190
As mentioned in the issue, the root problem here is that the current sass diff checker will compare the branch against current
main. If your branch is behindmain(and it almost always is), andmainitself made changes to SASS, then to the checker it will appear as if it undid those changes, effectively producing a diff.The checker would compare D vs E and erroneously think that E undid C.
There are 2 ways to solve this:
mainfrom which the PR was split from) as the baseline. Instead of comparingEvsD, we now compareEvsBwhich only includes the changes on the branch.mainand the PR as the PRs "current" state. So create a new commit or rebase:This also has the same effect as 1. but from the other angle. Instead of ignoring
Cwe now merge it into our branch for the purposes of SASS diffing, and effectively only compare our own commits againstmain.There are pros and cons of either approach:
Merge-base:
Pro: Always works
Con: If the combination of main + PR would actually produce diffs, then the checker wouldn't catch it. Similar to how merging a PR prior to
clang-tidyupdates may causemainto be broken for a bit until a follow-up fixes the issues.Synthetic merge:
Pro: The most correct answer at all times
Con: Brittle, and doesn't work if there are merge failures
Con: Not clear how this should be handled when the script is run standalone since a new commit is actually made.
So this PR implements option 1
Checklist