Skip to content

ci: Auto-accept API verifier changes in PRs#5228

Merged
jamescrosswell merged 14 commits into
mainfrom
ci/issue-5157-auto-verify-api
Jun 24, 2026
Merged

ci: Auto-accept API verifier changes in PRs#5228
jamescrosswell merged 14 commits into
mainfrom
ci/issue-5157-auto-verify-api

Conversation

@jamescrosswell

@jamescrosswell jamescrosswell commented May 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a new verify api workflow that auto-accepts API approval test snapshot changes on PRs, similar to the existing format-code workflow.

  • Runs ApiApprovalTests on a matrix of macos-15 (covers .NET / netstandard / iOS / MacCatalyst / Android TFMs) and windows-latest (covers the net48 / .NET Framework TFM, which is the common pain point when developing on non-Windows).
  • Uploads each runner's *.received.* files as artifacts.
  • A finalizer job downloads all received files, runs scripts/accept-verifier-changes.ps1, and pushes the accepted snapshots back to the PR branch.
  • When API changes are accepted, the PR is also labelled public API
  • For PRs from forks (where the workflow can't push back to the contributor's branch), the workflow fails with a clear message instructing the contributor to accept the snapshots locally — mirroring the fork-fallback in format-code.yml.

The Alternative suggested in the issue (switching to Microsoft.CodeAnalysis.PublicApiAnalyzers) is intentionally out of scope for this PR and can be considered in a follow-up.

Closes #5157

Adds a new `verify api` workflow that runs the ApiApprovalTests on
macOS (covers .NET / netstandard / iOS / MacCatalyst / Android TFMs)
and Windows (covers the net48 / .NET Framework TFM), then runs
scripts/accept-verifier-changes.ps1 over the resulting *.received.*
files and pushes the accepted snapshots back to the PR branch. When
API changes are accepted, the PR is also labelled `public API`.

For PRs from forks (where we can't push back), the workflow fails
with a hint telling the contributor how to accept the changes
locally.

Closes #5157

Co-Authored-By: Claude <noreply@anthropic.com>
@codecov

codecov Bot commented May 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.15%. Comparing base (0f91f7d) to head (13a480e).
⚠️ Report is 38 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5228      +/-   ##
==========================================
+ Coverage   74.13%   74.15%   +0.01%     
==========================================
  Files         508      508              
  Lines       18282    18353      +71     
  Branches     3574     3586      +12     
==========================================
+ Hits        13554    13610      +56     
- Misses       3859     3870      +11     
- Partials      869      873       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jamescrosswell jamescrosswell marked this pull request as ready for review May 20, 2026 00:37
@jamescrosswell jamescrosswell requested a review from Flash0ver as a code owner May 20, 2026 00:37
Comment thread .github/workflows/verify-api.yml
Comment thread .github/workflows/verify-api.yml
Comment thread .github/workflows/verify-api.yml
Comment thread .github/workflows/verify-api.yml
Comment thread .github/workflows/verify-api.yml Outdated
The workflow-level `contents: write` token was inherited by
`run-api-tests`, which builds and runs untrusted PR code.

Scope tokens per-job instead:
  - run-api-tests:           contents: read
  - accept-api-changes:      contents: write, pull-requests: write
  - report-fork-api-changes: contents: read

Co-Authored-By: Claude <noreply@anthropic.com>
Comment thread .github/workflows/verify-api.yml
The pattern branch of actions/download-artifact (no `name`/`artifact-ids`,
only `pattern`) tolerates zero matches without erroring — see
https://github.com/actions/download-artifact/blob/main/src/download-artifact.ts.
So `continue-on-error: true` isn't needed for the clean-PR case and would
otherwise mask genuine download failures.

Co-Authored-By: Claude <noreply@anthropic.com>
@jamescrosswell jamescrosswell added the skip-changelog Suppress automatic changelog generation via Craft label May 27, 2026
Comment thread .github/workflows/verify-api.yml
Comment thread .github/workflows/verify-api.yml
Comment thread .github/workflows/verify-api.yml Outdated
Comment thread .github/workflows/verify-api.yml Outdated
Comment thread .github/workflows/verify-api.yml Outdated
Comment thread .github/workflows/verify-api.yml Outdated
jamescrosswell and others added 3 commits June 24, 2026 11:20
The 'public API' label already exists in the repo, so the create call
just no-ops via '|| true'. Drop it and add the label directly.
Reviewer feedback:
- Add 'commands' to the intro so the plural matches the two-line block.
- Bare 'dotnet test' from repo root fails (two SLNX files, several SLNF
  files). Point users at SentryNoMobile.slnf + the ApiApprovalTests
  filter — works on every OS without mobile workloads.
Comment thread .github/workflows/verify-api.yml
Comment thread .github/workflows/verify-api.yml
Comment thread .github/workflows/verify-api.yml Outdated
matrix.slnf isn't in scope from the separate report-fork-api-changes job,
so the guidance had to name a different solution filter than CI actually
ran. Move the failure check into the matrix job so each OS prints the
exact filter it used. Drop the now-redundant fork-PR reporting job.
Both workflows auto-commit and push to the PR branch. If both fire on
the same PR and both find changes, the second git push is rejected as
non-fast-forward. Share a concurrency group so only one runs at a time
per PR.
Run scripts/generate-solution-filters.ps1 to add the perfview
FastSerialization/TraceEvent projects that the generator now includes
in the Windows/Windows-arm64/macOS CI filters.
Comment thread .github/workflows/verify-api.yml
upload-artifact@v4 strips the longest common parent from wildcard paths,
so '**/*.received.txt' would restore as Sentry.Tests/... instead of
test/Sentry.Tests/... in the accept job. accept-verifier-changes.ps1
renames each received file to a sibling .verified.txt — at the wrong
path — leaving the real snapshots untouched.

Tar the files first to preserve full paths through upload/download.
Comment thread .github/workflows/verify-api.yml Outdated
actions/checkout defaults to the pull_request merge ref (PR + target
branch), so the matrix job was running ApiApprovalTests against a tree
that differed from the PR head. The accept job then committed those
.verified.txt files onto the PR head — which doesn't contain target's
changes — guaranteeing the next run would fail again.

Pin the matrix checkout to pull_request.head.sha so both jobs operate
on the same tree.
Comment thread .github/workflows/verify-api.yml Outdated
Comment thread .github/workflows/verify-api.yml
Two related findings from review bots:

1. accept-api-changes was checking out head.ref (latest branch tip)
   while the matrix snapshotted head.sha (event-time tip). If the
   contributor pushed during the run, accept would commit old verified
   files on top of new code.

2. The blind 'git push' could fail non-fast-forward if the branch moved.

Pin both jobs to head.sha. Push from detached HEAD to refs/heads/head.ref
so the push fails fast (non-FF) if the branch advanced — re-running then
regenerates a fresh snapshot against the new head.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 13a480e. Configure here.

Comment thread .github/workflows/verify-api.yml
Comment thread .github/workflows/verify-api.yml
@jamescrosswell jamescrosswell requested a review from Flash0ver June 24, 2026 02:17
@jamescrosswell

Copy link
Copy Markdown
Collaborator Author

@Flash0ver after an epic game of ping pong between me and the bot reviewers, this is ready for review again...

@jamescrosswell jamescrosswell merged commit 9bd16eb into main Jun 24, 2026
37 checks passed
@jamescrosswell jamescrosswell deleted the ci/issue-5157-auto-verify-api branch June 24, 2026 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog Suppress automatic changelog generation via Craft

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci: Auto-Verify API changes in Pull Requests

2 participants