Commit 8dd5b65
authored
🐛 Fix GitHub Actions PR commit SHA detection (#182)
## Summary
- Fix incorrect commit SHA detection for GitHub Actions `pull_request`
events
- The CLI now reads `GITHUB_EVENT_PATH` to extract the actual PR head
commit SHA instead of using `GITHUB_SHA` (which is a merge commit)
- This fixes check runs appearing on wrong commits and baseline
detection issues
## Problem
For `pull_request` events in GitHub Actions, `GITHUB_SHA` points to a
**temporary merge commit**, not the actual head commit of the PR. This
caused:
- Check runs appearing on non-existent or wrong commits
- "Check run not found" errors in GitHub
- Incorrect baseline detection (comparing against wrong ancestor)
From [GitHub's official
docs](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request):
> "GITHUB_SHA for this event is the last merge commit of the pull
request merge branch. If you want to get the commit ID for the last
commit to the head branch of the pull request, use
`github.event.pull_request.head.sha` instead."
## Solution
The CLI now reads the GitHub Actions event payload from
`GITHUB_EVENT_PATH` (a JSON file containing the full webhook payload)
and extracts `pull_request.head.sha` for PR events.
| Scenario | Before | After |
|----------|--------|-------|
| `push` to `main` | ✅ Correct SHA | ✅ Correct SHA |
| `pull_request` event | ❌ Merge commit SHA | ✅ Head commit SHA |
| `VIZZLY_COMMIT_SHA` set | ✅ Uses override | ✅ Uses override |
## Changes
- `src/utils/ci-env.js`:
- Add `getGitHubEvent()` to read and cache event payload
- Update `getCommit()` to extract PR head SHA
- Update `getPullRequestHeadSha()` with same fix
- Update `getPullRequestBaseSha()` to extract base SHA
- Tests updated with comprehensive coverage
## Test plan
- [x] All existing tests pass
- [x] New tests cover PR event file reading
- [x] New tests cover fallback to `GITHUB_SHA` for push events
- [x] New tests cover error handling (missing file, invalid JSON)1 parent 587bf38 commit 8dd5b65
File tree
4 files changed
+303
-11
lines changed- src/utils
- tests
- unit
- utils
4 files changed
+303
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
7 | 51 | | |
8 | 52 | | |
9 | 53 | | |
| |||
31 | 75 | | |
32 | 76 | | |
33 | 77 | | |
34 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
35 | 89 | | |
36 | 90 | | |
37 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
38 | 112 | | |
39 | | - | |
40 | | - | |
41 | 113 | | |
42 | 114 | | |
43 | 115 | | |
| |||
145 | 217 | | |
146 | 218 | | |
147 | 219 | | |
148 | | - | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
149 | 225 | | |
150 | 226 | | |
151 | 227 | | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
152 | 243 | | |
153 | | - | |
154 | | - | |
155 | 244 | | |
156 | 245 | | |
157 | 246 | | |
| |||
166 | 255 | | |
167 | 256 | | |
168 | 257 | | |
169 | | - | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
170 | 263 | | |
171 | 264 | | |
172 | 265 | | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
173 | 280 | | |
174 | | - | |
175 | 281 | | |
176 | 282 | | |
177 | 283 | | |
| |||
0 commit comments