Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>` and `StringEnum<T>` constructors its JSON makes by reflection (#47). Reading a new Octokit model can need a
new `StringEnum<T>` 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.
30 changes: 30 additions & 0 deletions build/scripts/Program.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Program

open System
open System.IO
open System.Runtime.InteropServices
open Nullean.Make.Fs
open Proc.Fs

Expand All @@ -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
Expand Down Expand Up @@ -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()
35 changes: 35 additions & 0 deletions src/release-notes/OctokitClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Diagnostics.CodeAnalysis;
using Octokit;

namespace ReleaseNotes;

/// <summary>Creates the Octokit client the GitHub reads go through.</summary>
/// <remarks>
/// 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:
/// <list type="bullet">
/// <item>a JSON array becomes a <see cref="List{T}"/> made with <c>MakeGenericType</c> 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;</item>
/// <item>a <see cref="StringEnum{TEnum}"/> property is made with <c>Activator.CreateInstance(type, string)</c>.
/// <c>StringEnum</c> 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 (<see cref="Release"/>, <see cref="Issue"/>, <see cref="Label"/> and
/// <see cref="Branch"/>) reach through their properties. A missing one makes Octokit throw
/// MissingMethodException, which the issue scan swallows into empty release notes: <c>./build.sh smokeaot</c>
/// catches that.</item>
/// </list>
/// The managed builds ignore these attributes.
/// </remarks>
internal static class OctokitClient
{
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(List<>))]
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(StringEnum<ItemState>))]
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(StringEnum<ItemStateReason>))]
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(StringEnum<LockReason>))]
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(StringEnum<MergeableState>))]
[DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, typeof(StringEnum<TeamPrivacy>))]
public static GitHubClient Create(string? token) =>
new(new ProductHeaderValue("ReleaseNotesGenerator")) { Credentials = token is { } t ? new Credentials(t) : Credentials.Anonymous };
}
5 changes: 1 addition & 4 deletions src/release-notes/ReleaseNotesRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,7 @@ private static async Task WriteReleaseNotes(ReleaseNotesConfig config, GitHubCli

public static async Task<int> 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
{
Expand Down
6 changes: 6 additions & 0 deletions src/release-notes/release-notes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
<SignAssembly>false</SignAssembly>
</PropertyGroup>

<!-- Octokit reads every GitHub response by reflection, with no trimming annotations: keep its models (#47).
OctokitClient keeps the rest of what that reflection needs. -->
<ItemGroup Condition="'$(RuntimeIdentifier)' != ''">
<TrimmerRootAssembly Include="Octokit" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Nullean.Argh" />
<PackageReference Include="Octokit" />
Expand Down
Loading