fix(release): decide channels from every page and never fail after publishing

The release step decided :latest and the releases repository's content
after the Gitea release was already public, and could then fail or decide
wrongly (owner review 2, phase 1 review):

- Re-publishing v0.1.0-rc.1 or rc.2 builds Chronos.Tools from the tag,
  which has no release-channels: the step failed after publishing and the
  image job never ran. Any failure to decide (a tag older than the
  command, an unreadable page, a body that is not a list) now warns and
  moves no channel, so the version's image is still pushed.
- Only the first page (50, newest first) of releases was read, and
  pre-releases now share it with stable ones: 50 pre-releases after a
  stable release hid it and moved :latest to a pre-release. The workflow
  reads every page up to the first empty one (at most 100) and
  release-channels takes one --releases file per page (Args.GetAll).
- The Version step accepted tags release-channels refuses (v01.2.0), which
  then failed only after publishing. It now uses release-channels' SemVer
  2.0 pattern without +BUILD, and a test keeps the two in step.

BRIEF §19.3, DECISIONS, CHANGELOG and README step 5 say so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-10-26 23:22:10 +01:00
1 parent a34b33d50b
commit b2aeb2f587
8 files changed
+129 -40

No files matched your search

@@ -12,35 +12,43 @@ internal sealed record ReleaseChannels(bool Latest, bool ImageLatest);
/// <summary>
/// Decides which channels a release moves (BRIEF §19.3, amended 2026-10-26, R1). Gitea's "latest"
/// release is the most recently created one, so the choice is made by SemVer 2.0 precedence among the published
/// releases instead: re-publishing an older tag never rolls a channel back. Prints <c>latest=…</c> and
/// <c>image_latest=…</c>, ready for <c>$GITHUB_OUTPUT</c>.
/// releases instead: re-publishing an older tag never rolls a channel back. Gitea lists releases a page at a time,
/// so <c>--releases</c> is given once per page. Prints <c>latest=…</c> and <c>image_latest=…</c>, ready for
/// <c>$GITHUB_OUTPUT</c>.
/// </summary>
internal sealed class ReleaseChannelsCommand : ICommand
{
public string Name => "release-channels";
public string Summary => "Channels a tag moves: --tag vX.Y.Z[-pre] --releases <file.json>; prints latest= and image_latest=";
public string Summary => "Channels a tag moves: --tag vX.Y.Z[-pre] --releases <page.json> (once per page); prints latest= and image_latest=";
public async Task<int> RunAsync(string[] args)
{
var a = new Args(args);
if (a.Get("tag") is not { Length: > 0 } tag || a.Get("releases") is not { Length: > 0 } file)
throw new ToolException("Usage: release-channels --tag vMAJOR.MINOR.PATCH[-PRERELEASE] --releases <file.json>");
// The tag is checked before the file is read: a mistyped tag is the likelier error.
var files = a.GetAll("releases");
if (a.Get("tag") is not { Length: > 0 } tag || files.Count == 0 || files.Any(f => f.Length == 0))
throw new ToolException("Usage: release-channels --tag vMAJOR.MINOR.PATCH[-PRERELEASE] --releases <page.json> [--releases <page.json> …]");
// The tag is checked before the files are read: a mistyped tag is the likelier error.
if (TagVersion.Parse(tag) is null) throw new ToolException(InvalidTag(tag));
if (!File.Exists(file)) throw new ToolException($"Releases file not found: {file}");
Console.Out.Write(Render(Decide(tag, await File.ReadAllTextAsync(file))));
var pages = new List<string>(files.Count);
foreach (var file in files)
{
if (!File.Exists(file)) throw new ToolException($"Releases file not found: {file}");
pages.Add(await File.ReadAllTextAsync(file));
}
Console.Out.Write(Render(Decide(tag, [.. pages])));
return 0;
}
/// <summary>
/// The channels <paramref name="tag"/> moves, given Gitea's releases list (<c>GET /repos/{owner}/{repo}/releases</c>).
/// Drafts and tags that are not SemVer are ignored; the tag itself always counts as published. A release is a
/// pre-release when its tag has a pre-release part or Gitea flags it so.
/// The channels <paramref name="tag"/> moves, given every page of Gitea's releases list
/// (<c>GET /repos/{owner}/{repo}/releases</c>), merged. Drafts and tags that are not SemVer are ignored; the tag
/// itself always counts as published. A release is a pre-release when its tag has a pre-release part or Gitea
/// flags it so.
/// </summary>
internal static ReleaseChannels Decide(string tag, string releasesJson)
internal static ReleaseChannels Decide(string tag, params string[] releasesPages)
{
var current = TagVersion.Parse(tag) ?? throw new ToolException(InvalidTag(tag));
var listed = Published(releasesJson);
var listed = releasesPages.SelectMany(Published).ToList();
var currentIsPrerelease = current.IsPrerelease || listed.Any(r => r.Version.Tag == tag && r.Prerelease);
var all = listed.Where(r => r.Version.Tag != tag).Append((Version: current, Prerelease: currentIsPrerelease)).ToList();
+9 -1
View File
@@ -9,10 +9,11 @@ internal interface ICommand
internal sealed class ToolException(string message) : Exception(message);
/// <summary>Minimal option parser: <c>--key value</c>, <c>--flag</c>, positional arguments.</summary>
/// <summary>Minimal option parser: <c>--key value</c> (the last one wins, <see cref="GetAll"/> has every one), <c>--flag</c>, positional arguments.</summary>
internal sealed class Args
{
private readonly Dictionary<string, string?> _options = new(StringComparer.OrdinalIgnoreCase);
private readonly Dictionary<string, List<string>> _values = new(StringComparer.OrdinalIgnoreCase);
public Args(string[] args, params string[] flags)
{
@@ -25,7 +26,11 @@ internal sealed class Args
if (flags.Contains(key, StringComparer.OrdinalIgnoreCase) || i + 1 >= args.Length || args[i + 1].StartsWith("--", StringComparison.Ordinal))
_options[key] = null;
else
{
_options[key] = args[++i];
if (!_values.TryGetValue(key, out var values)) _values[key] = values = [];
values.Add(args[i]);
}
}
else
{
@@ -42,6 +47,9 @@ internal sealed class Args
public string Get(string key, string fallback) => Get(key) ?? fallback;
/// <summary>Every value of an option given more than once (<c>--key a --key b</c>), in order.</summary>
public IReadOnlyList<string> GetAll(string key) => _values.TryGetValue(key, out var values) ? values : [];
public static string RepoRoot()
{
var dir = new DirectoryInfo(Directory.GetCurrentDirectory());