Skip to content

Conversation

runningcode
Copy link
Contributor

@runningcode runningcode commented Sep 22, 2025

Summary

Fixes the issue where sentry-cli build upload uses incorrect commit SHAs when running in GitHub Actions for pull requests.

Previously, when running in GitHub Actions PR builds, sentry-cli would use the temporary merge commit SHA (created by GitHub Actions when it merges the PR branch with the target branch) instead of the actual PR head commit SHA. This caused build uploads to be associated with commit SHAs that don't exist in the actual repository history.

  • Modified find_head() function: Now checks for GITHUB_EVENT_PATH environment variable
  • This once again affects the release functionality. I don’t think there is a case where the release functionality would work from a PR branch but if it did this would in either case improve the logic to use an actual commit instead of the temporary merge commit.

How it works

  1. If --head-sha is explicitly provided → use that (existing behavior)
  2. If GITHUB_EVENT_PATH is set → extract PR head SHA from event payload
  3. Otherwise → use git rev-parse HEAD (existing behavior)

Alternative

Alternatively, we could use a complex regex to parse the json, i think the logic here is easier to follow/debug than a regex.

Testing

I tested this functionality in this test PR: #2787

Fixes

Closes EME-325

🤖 Generated with Claude Code

Copy link

linear bot commented Sep 22, 2025

@runningcode runningcode force-pushed the no/eme-325-github-actions-head-sha-fix branch 2 times, most recently from 2bebf86 to a0e9d7b Compare September 23, 2025 10:34
@runningcode runningcode marked this pull request as ready for review September 23, 2025 10:41
@runningcode runningcode requested review from a team and szokeasaurusrex as code owners September 23, 2025 10:41
Copy link
Member

@szokeasaurusrex szokeasaurusrex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I left some nitpicks, all optional.

@runningcode runningcode force-pushed the no/eme-325-github-actions-head-sha-fix branch from 4934a1c to 2403ea6 Compare September 24, 2025 14:14
runningcode and others added 12 commits September 24, 2025 16:18
When sentry-cli build upload runs in GitHub Actions for pull requests,
it was using the temporary merge commit SHA (from git rev-parse HEAD)
instead of the actual PR head commit SHA. This caused build uploads
to be associated with non-existent commit SHAs.

Changes:
- Modify find_head() to check for GITHUB_EVENT_PATH environment variable
- Extract PR head SHA from GitHub Actions event payload when available
- Fall back to existing git rev-parse HEAD behavior when not in GitHub Actions
- Add comprehensive tests for JSON parsing and event handling

This ensures build uploads in GitHub Actions PR workflows use the correct
commit SHA for size analysis and other features that rely on commit tracking.

Fixes EME-325

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Use iterator instead of needless range loop
- Use to_owned() instead of to_string() on &str

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Fixes clippy str_to_string warnings in test code.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Simplify JSON parsing logic to be more reliable
- Use sequential string searching instead of line-by-line parsing
- Add test case with real GitHub Actions JSON format
- This should fix issues with parsing complex nested JSON payloads
Address security vulnerability where user-controlled content in PR titles
or descriptions could interfere with SHA extraction by replacing naive
string parsing with robust serde_json deserialization.

- Replace string-based SHA extraction with proper JSON parsing using serde
- Add SHA validation to ensure extracted values are valid 40-character hex strings
- Add comprehensive test coverage including malicious input scenarios
- Update existing tests to work with new implementation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Remove client-side SHA validation as the backend will handle validation.
This simplifies the code while maintaining the security fix from proper
JSON parsing.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Clean up code by removing verbose comments while preserving functionality.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Co-authored-by: Daniel Szoke <[email protected]>
Co-authored-by: Daniel Szoke <[email protected]>
Remove unused structs and imports that were causing dead code warnings.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@runningcode runningcode force-pushed the no/eme-325-github-actions-head-sha-fix branch from 2403ea6 to 7f29355 Compare September 24, 2025 14:18
@runningcode runningcode enabled auto-merge (squash) September 24, 2025 14:19
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@runningcode runningcode merged commit d17bfc1 into master Sep 24, 2025
24 checks passed
@runningcode runningcode deleted the no/eme-325-github-actions-head-sha-fix branch September 24, 2025 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants