Skip to content

Add the api command and the verify-api action - #97

Merged
Mpdreamz merged 1 commit into
mainfrom
api-command
Nov 14, 2026
Merged

Mpdreamz merged 1 commit into
mainfrom
api-command

Conversation

@Mpdreamz

Copy link
Copy Markdown
Contributor

Step 4 of the public API files: the CLI and the action, on top of the reader, parser and comparison from #94 to #96.

assembly-differ api

dotnet build -c Release && assembly-differ api -o api   # api/MyLib.api for every library in the solution
assembly-differ api --verify api                        # exit 5 when the build no longer matches them
assembly-differ api MyLib.1.2.0.nupkg                   # print a package's API
assembly-differ api bin/Release/net8.0 -t MyLib -f json # every part of each declaration as a field
  • Sources: a .dll, a directory, a .nupkg, or nothing. With nothing, it reads the solution's libraries for every target framework, skipping test and unpackable projects the way projects does. It doesn't build.
  • Frameworks: an assembly gets one file when all its frameworks have the same API, and one per framework otherwise, such as MyLib.net8.0.api.
  • Splitting: --split namespace or --split top-level-namespace writes MyLib/<namespace>.api. Each file's header names the types it uses from the other files, so every file parses on its own.
  • Writing: -o removes .api files the API no longer has. It only touches files that start with assembly .
  • Verifying: --verify lists each change by path, file:line, who it breaks and how, and the bump, then prints the command that updates the files:
[api] Lib: 2 changes since the committed files, suggested version change: Major
  {fixture}/api/Lib.api:7  Lib › Widget › Name(int, bool)  added public string Name(int index, bool upper)  [minor]
  {fixture}/api/Lib.api:11  Lib › Widget › Name(int)  removed public string Name(int index)  [major: breaks callers, compiled code and source]
[api] {fixture}/api does not match the build. Suggested version change: Major
[api] Update the files with: assembly-differ api {fixture}/new -o {fixture}/api

nullean/assembly-differ/verify-api@v1

A composite action that installs the tool and runs api --verify. Checkout and the build are the caller's own steps, as the README documents.

  • Permissions: it needs only contents: read.
  • Comment: with comment: true and pull-requests: write, it keeps one comment on the pull request through gh api, holding the report and the update command. When the files match again it updates that comment, and it never posts one for a pull request that always matched.
  • Outputs: matches and suggested-change.

Library

  • ApiWriter.Write(assembly, split) returns the chunks.
  • ApiParser.Parse(files) reads them back into one API.
  • ApiDocument.LocationOf(node) gives each declaration's file and line.
  • ApiChange.OldScope locates an addition in the old file.

Tests

  • CLI (ApiFileTests, ProjectsTests): print, JSON, write then verify, five kinds of change under --verify, a split write/verify/rewrite cycle, a missing directory, solution mode and the help text.
  • Library: CoreLib and System.Text.Json split both ways parse back to the same model, field by field.
  • Mutation: a --verify that never reports a match makes two tests fail.
  • The action: I ran its shell steps locally, with the built tool and a stub gh. The outputs, exit code 5 and the comment body came out right. It has not run on GitHub. It installs the released tool, which doesn't have api yet, so it can only work after the next release.

Not in this PR

.api files as a baseline for files, release and pull-request. Those commands report through the JustAssembly-compatible engine, which compares assemblies. Taking .api files means moving them to the new comparison, which is the deliberate switch we agreed on: behind a flag first, the default in 2.0.

🤖 Generated with Claude Code

assembly-differ api writes a build's public API as .api files (-o), prints it, or prints it as JSON with every part of
each declaration as a field (-f json). It takes a .dll, a directory or a .nupkg, or without a path the solution's
libraries for every framework they target, the way the projects command picks them; --split namespace and
--split top-level-namespace write a file per chunk for large assemblies. An assembly whose frameworks share an API gets
one file, otherwise one per framework.

api --verify checks committed files against the build and exits with 5 when they differ, listing each change by path,
file and line, who it breaks and how, the suggested version change, and the command that updates the files.

The verify-api composite action installs the tool and runs api --verify after the caller's checkout and build; with
comment: true it keeps a pull request comment with the report.

In the library, ApiWriter.Write(assembly, split) writes the chunks, each with a header naming the types it uses from
the others so it parses alone, and ApiParser.Parse reads a set of files back into one API with the file and line of
every declaration.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Mpdreamz Mpdreamz added the feature A new capability (minor bump) label Nov 14, 2026
@Mpdreamz
Mpdreamz merged commit 3faeaa3 into main Nov 14, 2026
6 of 7 checks passed
@Mpdreamz
Mpdreamz deleted the api-command branch November 14, 2026 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature A new capability (minor bump)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant