Merge branch 'review2-p1-fix-release' into claude/owner-review-2-p1
This commit is contained in:
commit
5dfd5f93cf
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,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());
|
||||
|
||||
Reference in new issue
Block a user