Skip to content

Check the public API on every pull request with assembly-differ - #232

Merged
Mpdreamz merged 12 commits into
mainfrom
feature/assembly-differ
Nov 25, 2026
Merged

Mpdreamz merged 12 commits into
mainfrom
feature/assembly-differ

Conversation

@Mpdreamz

@Mpdreamz Mpdreamz commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Every pull request now reports what it changes in the public API of Elastic.Transport and Elastic.Transport.VirtualizedCluster, labels it for release-drafter, and fails on a breaking change until someone adds breaking-allowed. The approved API is committed in api/ and checked in CI and in a test.

Prompt summary: Onboard this repository to nullean/assembly-differ and its new GitHub Action for pull requests, including the verification tests that use Nullean.Snapshots for public API validation, in the existing ci.yml instead of a second workflow, with the permissions of the pull request checks reviewed.

Why

The generateapichanges target ran the old diff command in CI and only wrote a markdown file, so it never failed and nobody saw the result. A breaking change to the public API reached review with nothing to flag it, and the release label depended on a person noticing.

What

Checks in ci.yml

The build job already builds Release and fetches the tags, so one step after Build runs the API checks on a pull request: nullean/assembly-differ with api-files: api. It compares each packable library with its latest release on nuget.org, checks that the committed api/*.api files match the build, and keeps one comment up to date: every library it compared, with a tick when it has no changes, the files check, and the release label (breaking for a major change, feature for a minor one). A major change or out-of-date files fail the check; a major change passes once someone adds breaking-allowed. A push and a tag have no pull request to comment on, so they run ./build.sh verifyapi instead and cannot release out-of-date files. The workflow also runs on labeled and unlabeled; on those events only the build and the API step run, so adding breaking-allowed does not run the tests again. The action is pinned to the commit of its 1.4.0 release, and the tool to 1.4.0, which ignores unlisted versions (Elastic.Transport 8.0.1 is unlisted) and the SDK-specific GeneratedCode version in .api files.

Permissions

The workflow default is now permissions: {}. The AOT jobs, which publish and run pull request code, get contents: read; they had a write token before. The build job keeps contents, issues and packages write and gains pull-requests: write for the comment and labels. On a pull request from a fork GitHub gives a read-only token, the action warns and still applies the failure. The action reads the built assemblies as metadata and only its last step has the token. Neither checkout keeps the token in git config (persist-credentials: false); nothing after it needs git credentials, and the tag fetch runs without them. zizmor reports 18 findings on this file against 24 on main: the excessive-permissions and artipacked findings are gone, and what remains is the actions/* tags that policy allows and three trusted-publishing notes.

Committed API

api/*.api holds the public API, one file per target framework where they differ (six files). ./build.sh api regenerates them and ./build.sh verifyapi checks them; both restore the tool manifest themselves. These replace generateapichanges, Paths.GenerateApiChanges and the old ci.yml step. assembly-differ is last in dotnet-tools.json: with it earlier, dotnet tool restore on the Linux runner reported that the two tools listed after it were not contained in their packages.

Public API test

Elastic.Transport.PublicApi.Tests (net10.0, xunit) calls MatchApiSnapshot() on both assemblies, with Nullean.Snapshots.PublicApi 0.18.1. A change fails the test with each difference by path, who it breaks and the version bump it calls for. It is a separate project because Nullean.Snapshots builds on AwesomeAssertions and the other tests use FluentAssertions. Its snapshots repeat the net10.0 api/ files on purpose: the test gives fast feedback in ./build.sh test, api/ covers every framework.

Docs

contributing.md explains how to change the public API and what the comment and labels mean.

Out of scope: the open 2.0 stack (#219 to #229): once this merges, each of those PRs shows as major and needs breaking-allowed and regenerated api/ files. Moving the publish steps into a job of their own, so the pull request jobs drop the contents, issues and packages write permissions, is the next pull request. The stale "Public API files match the build" comment on this pull request is from the first version of the workflow and nothing updates it any more.

Verify

dotnet tool restore
./build.sh verifyapi
dotnet test tests/Elastic.Transport.PublicApi.Tests -c Release

Make a public member internal (for example Node.IsResurrected): the test, verifyapi and dotnet assembly-differ projects --fail-on major (exit 4) all report a major change. Add a public type instead and all three report minor. On unchanged main the tool compares with 1.1.0 and reports None. The comment, the labels and the breaking-allowed flow can only be seen on a pull request run; the first two are on this one.

Mpdreamz and others added 5 commits November 24, 2026 15:49
Bump assembly-differ to 1.2.1. The old target ran the diff command and
only wrote a markdown file, so it never failed. api writes the public
API to api/, verifyapi fails when api/ differs from the Release build.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
assembly-differ reports what a pull request changes against the latest
release, labels it for release-drafter and fails on a breaking change
until the breaking-allowed label is added. verify-api fails when the
committed api/ files differ from the build. The ci.yml step that only
wrote a file nobody read is gone.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Mpdreamz Mpdreamz added the Infra Build and repository infrastructure label Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

API changes: suggested version change None

✅ All good: the public API is unchanged.

  • ✅ Elastic.Transport.dll: no changes
  • ✅ Elastic.Transport.VirtualizedCluster.dll: no changes

Public API files

✅ The committed API files match the build (6 files).

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Public API files match the build

Mpdreamz and others added 2 commits November 24, 2026 18:59
Both leave GeneratedCode out of the public API files. The attribute held
the SDK's System.Text.Json source generator version, so the committed
files failed on CI's runner, whose SDK has another patch release.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
dotnet tool restore on the Linux runner reported that release-notes and
nupkg-validator, the two tools listed after assembly-differ 1.3.0, are not
contained in their packages and that the packages only hold assembly-differ.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Mpdreamz and others added 4 commits November 25, 2026 15:09
MinVer builds version 0.x without tags, so the libraries differed from the
1.1.0 release in the version of the assemblies they reference and the
comment reported a Patch change on unchanged code.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The build job already builds Release and has the tags, so the checks run
there instead of in a second workflow that built again: assembly-differ
reports the change and sets the labels on a pull request, and verifyapi
fails when api/ differs from the build. The workflow also runs on labeled
and unlabeled, where only the API checks run, so adding breaking-allowed
does not run the tests again. The api targets restore the tool manifest
themselves.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The workflow-level token had contents, issues, packages and now
pull-requests write on every pull request, including for the AOT jobs
that publish and run pull request code. The workflow default is now none,
the AOT jobs read contents, and the build job keeps what it had plus
pull-requests write for the API comment. The assembly-differ action is
pinned to the commit of its 1.3.0 release.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
assembly-differ 1.4.0 verifies the committed api/ files in the same action
and the same comment, so the two steps become one on a pull request. A
push and a tag still run verifyapi. Neither checkout keeps the token in
git config, since nothing after it needs git credentials.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…en (#233)

Pull request jobs no longer hold a write token or the publishing
secrets: the publish steps of `ci.yml` move into a job of their own that
runs for a push to main and for a tag only.

**Prompt summary:** After reviewing the permissions of the pull request
checks in #232, the owner asked for the remaining finding to be fixed:
the `build` job ran pull request code, and a third-party action, with
`contents`, `issues` and `packages` write, only because the publish
steps shared it. The change is its own pull request, apart from the API
onboarding.

## Why
The `build` job builds and tests the pull request, runs MSBuild tasks
and source generators from its dependencies, and runs the
assembly-differ action. It also pushed the canary and release packages,
so it held `contents`, `issues` and `packages` write for every run,
including pull requests from branches of this repository. A compromised
dependency or action in that job could write to the repository's
releases and packages.

## What

#### A publish job
`publish` has `needs: build` and `if: github.event_name == 'push'`. It
holds `contents`, `issues` and `packages` write, and is the only job
that names `FEEDZ_IO_API_KEY`, `NUGET_ORG_API_KEY` or the token for the
release. It checks out the same commit, fetches the tags, restores the
tools, and runs the same push steps with the same conditions as before:
canary packages to GitHub Packages and feedz.io for a push to a branch;
release notes, the GitHub release and nuget.org for a tag.

#### What it publishes
The `build` job already built, tested and validated the packages. On a
push it uploads `build/output/*.nupkg` as an artifact that expires after
a day, and `publish` downloads it into `build/output`. The packages that
are pushed are the ones that were tested, not a rebuild.

#### Build job permissions
`build` now has `contents: read` and `pull-requests: write`, the comment
and labels of the API step. `zizmor` finds nothing about permissions or
secrets in `ci.yml`; the remaining findings are the `actions/*` tags
that policy allows and three trusted-publishing notes.

**Risk:** the publish steps only run for a push to main and for a tag,
so a pull request cannot run them. I ran the hand-off on this pull
request with a temporary commit, since reverted: both `.nupkg` files
reached `build/output` in the `publish` job, which restored the tools
and generated release notes. The pushes themselves first run when this
merges, as canary packages from main, and the release steps with the
next tag. A failed canary run only needs a rerun.

**Stack:** 2 of 2, on top of
[#232](#232);
retarget it to `main` once that merges.

## Verify
```bash
git diff feature/assembly-differ -- .github/workflows/ci.yml
```
In the run of this pull request, the `build` job's "GITHUB_TOKEN
Permissions" show `Contents: read` and `PullRequests: write`, and the
`publish` job does not run.

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

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
@Mpdreamz
Mpdreamz merged commit 3913365 into main Nov 25, 2026
7 checks passed
Mpdreamz added a commit that referenced this pull request Nov 25, 2026
… makes (#234)

The API check now fails a pull request only for a breaking change the
pull request itself makes, not for one that `main`, or a pull request
below it in a stack, already has.

**Prompt summary:** The API comments on the stacked 2.0 pull requests
listed breaking changes that the pull requests did not touch, and would
turn every pull request red whenever `main` has an unreleased breaking
change. The owner asked for the check to follow only what a pull request
itself changes, and for the pull requests that introduced the changes to
be listed.

## Why
Since #232 the action compared each build with the latest release on
nuget.org. A pull request in the middle of a stack therefore showed
everything below it: #227 changes nothing in the public API and still
listed 32 breaking changes and failed the check.

## What

#### assembly-differ 1.5.0
The pinned action, the `version:` input and the tool in
`dotnet-tools.json` go from 1.4.0 to 1.5.1
([nullean/assembly-differ#119](nullean/assembly-differ#119),
and the fix of 1.5.0 in
[#120](nullean/assembly-differ#120)). 1.5.0
fetched the base branch into the workflow's own checkout with
`--depth=1`, which cut the history that MinVer reads in
`validatepackages`; 1.5.1 fetches into a repository of its own. With
`api-files: api`, the action now compares a pull request's committed
`api/` with its base branch's, target framework by target framework, and
the check, the release label and `--fail-on` follow that. The comparison
with the latest release stays in the comment, collapsed and marked as
information, with a table of the pull requests below this one that
introduced the changes. A change that is the same in every framework is
listed once. No workflow change is needed: the new step reads the base
branch and the open pull requests of a stack with the token the job
already has.

**Out of scope:** the 2.0 stack picks this up once it is rebased onto
`main`: a pull request runs the workflow of its base branch, so until
then the stack pull requests run the old one.

## Verify
```bash
dotnet tool restore
./build.sh verifyapi
```
On this pull request the comment compares with `main` and lists both
libraries as having no changes. I ran the steps of the new action on the
real stack beforehand: #227 gets `None` and passes, and #220, which does
break the API, gets the `breaking` label and fails.

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

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Infra Build and repository infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants