Skip to content

Conversation

runningcode
Copy link
Contributor

Test Workflow for PR Head-SHA Detection

This PR contains a GitHub Actions workflow that will test our PR head-sha detection fix in a real CI environment.

What the workflow does:

  1. Builds sentry-cli - Creates the actual binary with our fix
  2. Shows the environment - Displays GitHub Actions variables and event payload
  3. Tests real CLI execution - Runs to see head-sha detection in action
  4. Compares SHAs - Shows the difference between git HEAD (merge commit) vs PR head SHA
  5. Tests fallback - Verifies behavior when not in GitHub Actions context

Expected Results:

  • Git HEAD: Will be the temporary merge commit created by GitHub Actions
  • PR Head SHA: Will be the actual commit from our feature branch
  • Our Fix: Should detect and use the PR head SHA instead

This will demonstrate that the fix works end-to-end in the exact scenario described in EME-325.

🤖 Generated with Claude Code

@runningcode runningcode force-pushed the no/test-pr-head-sha-workflow branch 2 times, most recently from 4591371 to 8df1dd0 Compare September 23, 2025 09:20
runningcode and others added 11 commits September 23, 2025 12:09
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 <noreply@anthropic.com>
- 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 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fixes clippy str_to_string warnings in test code.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This workflow will:
- Build the actual sentry-cli binary
- Run it in a real GitHub Actions PR environment
- Demonstrate that it correctly detects GITHUB_EVENT_PATH
- Show it extracts the real PR head SHA instead of merge commit
- Verify the fix works end-to-end

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

Co-Authored-By: Claude <noreply@anthropic.com>
Use --log-level debug parameter instead of RUST_LOG env var to see
the GitHub Actions PR head SHA detection debug logs in CI output.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This allows the CLI to proceed past authentication and reach
the head-sha detection logic where we can see our debug logs.

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

Co-Authored-By: Claude <noreply@anthropic.com>
- Copy real APK from hackernews project to test_artifacts/
- Update workflow to use app-debug.apk instead of creating fake file
- This provides more realistic testing for sentry-cli build upload

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

Co-Authored-By: Claude <noreply@anthropic.com>
- Add --org test-org --project test-project to sentry-cli commands
- This allows the CLI to proceed further into execution flow
- Should help reach the head SHA detection logic for testing

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

Co-Authored-By: Claude <noreply@anthropic.com>
- Change --org to -o and --project to -p (correct build subcommand flags)
- Move org/project flags to after build subcommand where they belong

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

Co-Authored-By: Claude <noreply@anthropic.com>
- Add debug logs to trace HEAD finding process
- Log event path when GITHUB_EVENT_PATH is set
- Log event file content for debugging
- This helps troubleshoot why SHA detection message isn't appearing

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

Co-Authored-By: Claude <noreply@anthropic.com>
@runningcode runningcode force-pushed the no/test-pr-head-sha-workflow branch from 75d4792 to 19ef6ad Compare September 23, 2025 10:09
runningcode and others added 2 commits September 23, 2025 12:13
- Remove test_get_github_base_ref() test that references non-existent function
- The function get_github_base_ref() was never implemented
- This test was incorrectly added during merge conflict resolution

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

Co-Authored-By: Claude <noreply@anthropic.com>
- 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
- Fix clippy warning by using to_owned() instead of to_string()

This should fix the issue where SHA detection message wasn't appearing
in the test workflow by properly parsing the real event payload structure.

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

Co-Authored-By: Claude <noreply@anthropic.com>
runningcode added a commit that referenced this pull request Sep 24, 2025
…#2785)

## 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](https://claude.ai/code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Daniel Szoke <7881302+szokeasaurusrex@users.noreply.github.com>
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.

1 participant