diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ca6d29..a9bc834 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,6 +43,11 @@ jobs: env: RID: ${{ matrix.rid }} + # Trimming breaks only the native-AOT binary (#47), so read real releases and issues with it + - run: ./build.sh smokeaot -s + name: Run the native-AOT binary against GitHub + shell: bash + # Container image, linux-x64 only for now — the platform every GitHub-hosted Linux runner # already matches. No --push here and no registry login on this leg, so this only proves the # container build itself still works: AOT compiles, the chiseled base image resolves, and the diff --git a/AGENTS.md b/AGENTS.md index 1fc7070..1ba51c3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -58,6 +58,10 @@ one release label. This repository's own releases do not run the tool: release-d builds rely on. Removing or renaming any of it is a breaking change. - Octokit's reflection-based JSON is unreliable under native AOT (see the remarks on `GitHubReleaseClient`). Request bodies go through `GitHubJsonContext`, and writes are idempotent upserts rather than check-then-create. +- Reads still go through Octokit. The csproj roots the Octokit assembly for the AOT build, and `OctokitClient` keeps the + `List` and `StringEnum` constructors its JSON makes by reflection (#47). Reading a new Octokit model can need a + new `StringEnum` there. `./build.sh smokeaot` publishes the AOT binary and reads real releases and issues with it; + CI's `aot-pack` job runs it on each RID it builds. - Build targets are Make.Fs `target { }` blocks in `build/scripts/Program.fs` whose commands are Proc.Fs `sh $"…"` lines; values come from `text` inside `shell { }` (`Versions.fs`). Do not call the C# `ProcNet` API from the build. CI calls targets by name (`./build.sh generatepackages -s true`): keep multi-word case names as one word. diff --git a/build/scripts/Program.fs b/build/scripts/Program.fs index 20e6242..6bccfec 100644 --- a/build/scripts/Program.fs +++ b/build/scripts/Program.fs @@ -1,6 +1,8 @@ module Program +open System open System.IO +open System.Runtime.InteropServices open Nullean.Make.Fs open Proc.Fs @@ -23,6 +25,8 @@ type Target = | Generateapichanges /// Publish the native-AOT build as the ghcr.io/nullean/release-notes container image | Publishcontainers + /// Publish the native-AOT build for this machine and read a public repository's releases and issues with it + | Smokeaot /// build/output, relative to the repository root let private output = Paths.RootRelative Paths.Output.FullName @@ -111,4 +115,30 @@ let main argv = else sh $"dotnet publish {toolProject} -c Release -f net10.0 -r linux-x64 /t:PublishContainer -p DebugType=none -p ContainerBaseImage={baseImage} -p ContainerRepository={Paths.Repository} -p {tags} -p ContainerUser=1001:1001" } + // The framework-dependent build cannot catch what trimming breaks: #47 broke only the native-AOT binary, where + // Octokit's reflection-based JSON returned nothing or threw. So this publishes that binary and reads releases + // and issues that no longer change: elastic/apm-agent-dotnet's 1.11.0 and the line around it. It runs + // anonymously, as the issue's reproduction did, which costs about 15 of the 60 requests an hour GitHub allows. + | Smokeaot -> target [] { + let rid = RuntimeInformation.RuntimeIdentifier + let publishDirectory = Path.Combine(Paths.Output.FullName, "aot-smoke") + let publish = Paths.RootRelative publishDirectory + sh $"dotnet publish {toolProject} -c Release -f net10.0 -r {rid} -o {publish}" + let executable = if OperatingSystem.IsWindows() then $"{Paths.ToolName}.exe" else Paths.ToolName + let binary = Paths.RootRelative <| Path.Combine(publishDirectory, executable) + // checked one command at a time and stopping at the first failure, so a broken binary spends few requests + let check (command: string) (result: string) (expected: string list) = + printfn "%s %s:\n%s" Paths.ToolName command result + for line in expected do + if not (result.Contains line) then failwithf "the native-AOT binary's %s did not print '%s'" command line + // the latest release, then every page of releases: one object, then lists + let! previous = text $"{binary} find-previous elastic apm-agent-dotnet --version 1.11.0" + check "find-previous" previous [ "1.10.0" ] + // every page of releases again, then one release by its tag + let! current = text $"{binary} current-version elastic apm-agent-dotnet --query 1.11 --version 1.11.0" + check "current-version" current [ "1.11.1"; "1.11.2" ] + // issues and pull requests, with their labels and pull request links + let! notes = text $"{binary} generate elastic apm-agent-dotnet --version 1.11.0" + check "generate" notes [ "- #1239 Add Cosmos DB support (issue: #1154)"; "- #1302 Prefer W3C traceparent" ] } + app.RunAsync(argv).GetAwaiter().GetResult() diff --git a/src/release-notes/OctokitClient.cs b/src/release-notes/OctokitClient.cs new file mode 100644 index 0000000..519e386 --- /dev/null +++ b/src/release-notes/OctokitClient.cs @@ -0,0 +1,35 @@ +using System.Diagnostics.CodeAnalysis; +using Octokit; + +namespace ReleaseNotes; + +/// Creates the Octokit client the GitHub reads go through. +/// +/// Octokit reads every response with SimpleJson, by reflection and with no trimming annotations, so the native-AOT +/// build has to keep by hand what that reflection reaches (#47). release-notes.csproj roots the Octokit assembly, which +/// keeps the models' constructors and setters. That is not enough, because SimpleJson also builds types at run time +/// that live outside Octokit or only exist as generic instantiations: +/// +/// a JSON array becomes a made with MakeGenericType and its capacity constructor, +/// found by reflection. Nothing calls that constructor for Octokit's models, so without it every list read throws a +/// NullReferenceException. Keeping the open type's constructors keeps them for each reference type T; +/// a property is made with Activator.CreateInstance(type, string). +/// StringEnum is a struct, so each instantiation is compiled on its own and needs its own entry. These are the +/// ones the models this tool reads (, , and +/// ) reach through their properties. A missing one makes Octokit throw +/// MissingMethodException, which the issue scan swallows into empty release notes: ./build.sh smokeaot +/// catches that. +/// +/// The managed builds ignore these attributes. +/// +internal static class OctokitClient +{ + [DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(List<>))] + [DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(StringEnum))] + [DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(StringEnum))] + [DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(StringEnum))] + [DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(StringEnum))] + [DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(StringEnum))] + public static GitHubClient Create(string? token) => + new(new ProductHeaderValue("ReleaseNotesGenerator")) { Credentials = token is { } t ? new Credentials(t) : Credentials.Anonymous }; +} diff --git a/src/release-notes/ReleaseNotesRunner.cs b/src/release-notes/ReleaseNotesRunner.cs index e110ba1..92db620 100644 --- a/src/release-notes/ReleaseNotesRunner.cs +++ b/src/release-notes/ReleaseNotesRunner.cs @@ -309,10 +309,7 @@ private static async Task WriteReleaseNotes(ReleaseNotesConfig config, GitHubCli public static async Task Run(ReleaseNotesConfig config) { - var client = new GitHubClient(new ProductHeaderValue("ReleaseNotesGenerator")) - { - Credentials = config.Token is { } token ? new Credentials(token) : Credentials.Anonymous - }; + var client = OctokitClient.Create(config.Token); try { diff --git a/src/release-notes/release-notes.csproj b/src/release-notes/release-notes.csproj index c63c006..c0f27b3 100644 --- a/src/release-notes/release-notes.csproj +++ b/src/release-notes/release-notes.csproj @@ -38,6 +38,12 @@ false + + + + +