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:
1 parent
a34b33d50b
commit
b2aeb2f587
8 files changed
+129
-40
No files matched your search
@@ -54,7 +54,10 @@ jobs:
|
||||
- name: Version
|
||||
id: version
|
||||
run: |
|
||||
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
|
||||
# SemVer 2.0 as release-channels reads it (no leading zeros, no empty identifiers), without +BUILD, which an
|
||||
# image tag cannot hold: a tag it would refuse stops here, before anything is built or published.
|
||||
semver='^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-(0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(\.(0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*)?$'
|
||||
if [[ ! "$TAG" =~ $semver ]]; then
|
||||
echo "::error title=Release::Tag '$TAG' is not vMAJOR.MINOR.PATCH or vMAJOR.MINOR.PATCH-PRERELEASE"
|
||||
exit 1
|
||||
fi
|
||||
@@ -197,11 +200,29 @@ jobs:
|
||||
# most recently created one), so re-publishing an older tag never rolls a channel back. latest: the public
|
||||
# content follows the highest stable release. image_latest: :latest follows it too, or the highest pre-release
|
||||
# while no stable release exists, so compose and Unraid users find an image from the first pre-release on.
|
||||
releases="$RUNNER_TEMP/releases.json"
|
||||
curl -fsS -H "Authorization: token $token" -o "$releases" "${{ github.server_url }}/api/v1/repos/$TARGET/releases?draft=false&limit=50"
|
||||
channels="$(dotnet "$TOOLS" release-channels --tag "$TAG" --releases "$releases")"
|
||||
latest="$(printf '%s\n' "$channels" | sed -n 's/^latest=//p')"
|
||||
image_latest="$(printf '%s\n' "$channels" | sed -n 's/^image_latest=//p')"
|
||||
# Gitea lists 50 releases a page, newest first: every page up to the first empty one counts (at most 100).
|
||||
channels() {
|
||||
local page file pages=()
|
||||
for ((page = 1; page <= 100; page++)); do
|
||||
file="$RUNNER_TEMP/releases-$page.json"
|
||||
curl -fsS -H "Authorization: token $token" -o "$file" "${{ github.server_url }}/api/v1/repos/$TARGET/releases?draft=false&limit=50&page=$page" || return
|
||||
pages+=(--releases "$file")
|
||||
if ! grep -q '"tag_name"' "$file"; then
|
||||
dotnet "$TOOLS" release-channels --tag "$TAG" "${pages[@]}"
|
||||
return
|
||||
fi
|
||||
done
|
||||
echo "More than 100 pages of releases." >&2
|
||||
return 1
|
||||
}
|
||||
# The release is already published: when its channels cannot be decided (the list unreadable, or a tag older
|
||||
# than release-channels, such as v0.1.0-rc.2, whose Chronos.Tools lacks the command) it moves neither.
|
||||
if ! decided="$(channels)"; then
|
||||
echo "::warning title=Release::The channels of $TAG could not be decided (see the error above): it moves neither the releases repository nor :latest."
|
||||
decided="$(printf 'latest=false\nimage_latest=false')"
|
||||
fi
|
||||
latest="$(printf '%s\n' "$decided" | sed -n 's/^latest=//p')"
|
||||
image_latest="$(printf '%s\n' "$decided" | sed -n 's/^image_latest=//p')"
|
||||
echo "Releases of $TARGET: $TAG moves the public content: $latest; :latest: $image_latest"
|
||||
{ echo "latest=$latest"; echo "image_latest=$image_latest"; } >> "$GITHUB_OUTPUT"
|
||||
{ echo "LATEST=$latest"; echo "IMAGE_LATEST=$image_latest"; } >> "$GITHUB_ENV"
|
||||
|
||||
@@ -137,8 +137,9 @@ installed copy of either.
|
||||
2. Tag and push: `git tag v0.2.0 && git push origin v0.2.0` (pre-releases: `v0.2.0-rc.1`; they are published as
|
||||
Gitea pre-releases, move `:latest` only while no stable release exists and are ignored by the in-app update check).
|
||||
3. `release.yml` then, in its job *Build, test and publish* (SDK container):
|
||||
- validates the tag, builds with `ChronosVersion` from the tag and `ChronosReleasesUrl` (the repository the release
|
||||
goes to), runs the package guard, the i18n check and the Core, Data, Server and Tools tests;
|
||||
- validates the tag (SemVer 2.0 without build metadata: no leading zeros, no empty identifiers), builds with
|
||||
`ChronosVersion` from the tag and `ChronosReleasesUrl` (the repository the release goes to), runs the package
|
||||
guard, the i18n check and the Core, Data, Server and Tools tests;
|
||||
- cross-compiles the self-contained single-file win-x64 programs (Chronos, Uploader and Setup with ReadyToRun;
|
||||
Server), checks them with `Chronos.Tools pe-check` (GUI subsystem, icon, version, PerMonitorV2 manifest), signs
|
||||
them with osslsigncode when the signing secrets exist, packs `Chronos-Setup-<v>.exe` (components Chronos,
|
||||
@@ -160,7 +161,9 @@ installed copy of either.
|
||||
a pre-release once a stable release exists, only gets its release and its `:<v>` image. Without `REGISTRY_TOKEN`
|
||||
this job fails with instructions while the release is already published: add the secret and re-run the job.
|
||||
5. To publish an existing tag again (for example after adding a secret), run *Release* manually (Actions › Release ›
|
||||
*Run workflow*) with the tag.
|
||||
*Run workflow*) with the tag. The run builds `Chronos.Tools` from the tag: a tag older than `release-channels`
|
||||
(`v0.1.0-rc.1`, `v0.1.0-rc.2`) gets its release and its `:<v>` image, with a warning, but moves neither the
|
||||
releases repository nor `:latest`.
|
||||
|
||||
### Secrets and variables
|
||||
|
||||
|
||||
+16
-12
@@ -1246,7 +1246,8 @@ third-party actions at all (amended 2026-10-23, R3).
|
||||
### 19.3 `release.yml` (tag `v*`, or manual re-publish of an existing tag; amended 2026-10-23, R3; amended 2026-10-26, R1)
|
||||
|
||||
Job `release`, in the SDK container: the version from the tag
|
||||
(`vMAJOR.MINOR.PATCH[-PRERELEASE]`) passed as `-p:ChronosVersion`, with
|
||||
(`vMAJOR.MINOR.PATCH[-PRERELEASE]`, SemVer 2.0 as `release-channels` reads it, checked
|
||||
before anything is built) passed as `-p:ChronosVersion`, with
|
||||
`-p:ChronosReleasesUrl` (the releases repository's address, §18); build and the Linux
|
||||
tests; self-contained single-file win-x64 publish of App and Uploader (ReadyToRun), Server
|
||||
and Setup (ReadyToRun), cross-compiled on Linux; `Chronos.Tools pe-check` (GUI subsystem,
|
||||
@@ -1258,17 +1259,20 @@ installers `Chronos-Setup-<ver>.exe` (components Chronos, Uploader, Server) and
|
||||
(`Chronos.Tools changelog` from Conventional Commits) and `SHA256SUMS`; the Gitea release
|
||||
made by `Chronos.Tools gitea-release` (a draft first, every file uploaded and its size
|
||||
verified, then published). Then `Chronos.Tools release-channels` decides what the tag moves
|
||||
(amended 2026-10-26, R1): it reads the target repository's published releases
|
||||
(`releases?draft=false&limit=50`), stable and pre-releases alike, ignores drafts and tags
|
||||
that are not `v` + SemVer 2.0, always counts the tag itself, takes a release Gitea flags as
|
||||
a pre-release for one, and compares by SemVer 2.0 precedence (not Gitea's
|
||||
`releases/latest`, which is the most recently created release; equal precedence counts as
|
||||
highest). `latest` is true for the highest stable release and moves the releases
|
||||
repository's content (§19.4); `image_latest` is true for the highest stable release or,
|
||||
while no stable release exists, the highest pre-release, and moves `:latest`. Re-publishing
|
||||
an older tag, or a pre-release once a stable release exists, moves neither. Then job
|
||||
`image`, in the runner's default image with the docker CLI and the host's daemon: it builds
|
||||
`linux/amd64` only (arm64 would need QEMU on the host) and pushes
|
||||
(amended 2026-10-26, R1): it reads every page of the target repository's published releases
|
||||
(`releases?draft=false&limit=50&page=<n>` up to the first empty page, at most 100), stable
|
||||
and pre-releases alike, ignores drafts and tags that are not `v` + SemVer 2.0, always counts
|
||||
the tag itself, takes a release Gitea flags as a pre-release for one, and compares by
|
||||
SemVer 2.0 precedence (not Gitea's `releases/latest`, which is the most recently created
|
||||
release; equal precedence counts as highest). `latest` is true for the highest stable
|
||||
release and moves the releases repository's content (§19.4); `image_latest` is true for
|
||||
the highest stable release or, while no stable release exists, the highest pre-release,
|
||||
and moves `:latest`. Re-publishing an older tag, or a pre-release once a stable release
|
||||
exists, moves neither. When the channels cannot be decided (a page unreadable or not a
|
||||
list, or a tag older than `release-channels`, whose own `Chronos.Tools` lacks it) the tag
|
||||
moves neither, with a warning. Then job `image`, in the runner's default image with the
|
||||
docker CLI and the host's daemon: it builds `linux/amd64` only (arm64 would need QEMU on
|
||||
the host) and pushes
|
||||
`gitea.encke-hake.ts.net/balbosoft/chronos-server:<ver>`, plus `:latest` when `image_latest`
|
||||
is true. Pushing needs the repository secret `REGISTRY_TOKEN`, an access token of a user who
|
||||
can write the owner's packages (scope "package: read and write"): the workflow's own token
|
||||
|
||||
+6
-2
@@ -20,13 +20,17 @@ commits follow Conventional Commits (release notes are generated from them by `C
|
||||
- Server diagnostics: the environment report lists the archive, space and data volumes with their free space, file
|
||||
system and mount.
|
||||
- `Chronos.Tools release-channels`: which channels a release tag moves (`latest=`, `image_latest=`), by SemVer 2.0
|
||||
precedence among the published releases.
|
||||
precedence among the published releases (every page of Gitea's list, one `--releases` file per page).
|
||||
|
||||
### Changed
|
||||
- Server image: `:latest` now follows the highest stable release, or the highest pre-release while no stable release
|
||||
exists, so the Unraid template and the compose file find an image from the first pre-release on. The public
|
||||
releases repository still follows stable releases only, and re-publishing an older tag never moves either back.
|
||||
`:nightly` stays the nightly build of `main`, for testing only (owner review 2, R1).
|
||||
When the release workflow cannot decide (the releases list unreadable, or a tag older than `release-channels` such
|
||||
as `v0.1.0-rc.2` published again) it warns and moves neither, and still pushes the version's image. `:nightly`
|
||||
stays the nightly build of `main`, for testing only (owner review 2, R1).
|
||||
- Release workflow: the tag must be SemVer 2.0 without build metadata (no leading zeros such as `v01.2.0`, no empty
|
||||
identifiers); any other tag is refused before anything is built.
|
||||
- Desktop: About is the last page of Settings and the rail keeps Settings alone at the bottom. *Check for updates*
|
||||
and the Releases link are on Settings › Updates; the data folder and the diagnostics bundle are on Settings ›
|
||||
Advanced only (About's own copies of those buttons are gone) (owner review 2, R5).
|
||||
|
||||
+2
-1
@@ -429,7 +429,8 @@ One line per decision: date · decision · alternative · reason.
|
||||
| 2026-10-23 | Update check: the client reads the published stable releases and takes the highest version, because Gitea's `releases/latest` is the most recently created release (a re-published older tag or a backport would become it); a pre-release build (`0.1.0-rc.1`) is offered the final release of its own version, which it used to call "up to date" forever; a 404 is a failed check, because Gitea answers 404 for a repository the client may not see (the `BalboSoft` organisation is private today) and that used to read as "up to date". The release workflow picks `:latest` the same way. `gitea-release` checks every file's size before it publishes, and when it replaces the files of a release clients can already see it removes the old `SHA256SUMS` first and uploads the new one last. (R2, R3; independent review of this change.) | Trust `releases/latest`; leave the pre-release rule as it was | The first release is a pre-release: its testers must be told when 0.1.0 is out; a download checked against the checksums of another build would be refused. |
|
||||
| 2026-10-23 | Timed tests (bulk insert, JPEG and RAW decode, resampler, light analysis, metadata robustness, scroll smoke, and the lease renewal test's timer periods) take their budget from `TestTiming.Budget`, stretched by `CHRONOS_TEST_TIME_FACTOR` (at least 1, default 1); ci.yml and release.yml set 3, perf.yml nothing. On the owner's runner, which shares its CPU and disks with Gitea and the server's other containers, the 100k-frame SQLite bulk insert took 10–19 s against 15 s from one run to the next. (R3.) | Raise the budgets; move the timed tests to perf.yml | The budgets stay what a developer's PC must meet and the weekly performance gates measure them unstretched; a CI run fails on a real regression, not on a busy host. |
|
||||
| 2026-10-23 | The update check builds the release page (`<repository>/releases/tag/<tag>`) and the download links (`<repository>/releases/download/<tag>/<name>`) from `ChronosReleasesUrl` and takes only the tags, names and sizes from Gitea's answer: Gitea writes `html_url` and `browser_download_url` with its ROOT_URL, the owner's being `http://192.168.30.23:3000`, so the first release's links were plain http on a LAN address and the https-only check ignored the release. Without a repository address (tests) the answer's links are used as before. (R2, after the first release.) | Ask the owner to set ROOT_URL to the public https name | The build already names the address its users reach; the client then works whatever Gitea's ROOT_URL is, and a ROOT_URL change stays the owner's choice. |
|
||||
| 2026-10-26 | The server image's `:latest` follows the highest stable release, or the highest pre-release while no stable release exists; the releases repository's content and the in-app update check still follow stable releases only. `Chronos.Tools release-channels --tag <tag> --releases <file.json>` prints both answers (`latest=`, `image_latest=`) from Gitea's releases list (`releases?draft=false&limit=50`, saved by curl) by SemVer 2.0 precedence: drafts and tags that are not `v` + strict SemVer 2.0 are ignored, the tag itself always counts, a release Gitea flags `prerelease` counts as one whatever its tag, build metadata is ignored and equal precedence counts as highest; a body that is not a JSON array (a sign-in page, an API error) stops the release (exit 2). It replaces curl + grep + `sort -V` in release.yml and the 2026-10-23 rule "`:latest` only for the highest stable version". (Owner review 2, R1.) | Point the Unraid template and compose at `:nightly` or a pinned `:<ver>`; push `:latest` for every pre-release; keep `sort -V` over all releases | With only pre-releases published (v0.1.0-rc.1, rc.2) `:latest` never existed, so the template and compose found no image. Users should get the newest release, not the untested nightly build of `main`. A pre-release published after a stable one, or an older tag re-published, must not move `:latest`. `sort -V` ranks `1.0.0-rc.1` above `1.0.0`, so it cannot compare pre-releases with stable releases. |
|
||||
| 2026-10-26 | The server image's `:latest` follows the highest stable release, or the highest pre-release while no stable release exists; the releases repository's content and the in-app update check still follow stable releases only. `Chronos.Tools release-channels --tag <tag> --releases <page.json> […]` prints both answers (`latest=`, `image_latest=`) from every page of Gitea's releases list (`releases?draft=false&limit=50&page=<n>`, saved by curl, one `--releases` per page) by SemVer 2.0 precedence: drafts and tags that are not `v` + strict SemVer 2.0 are ignored, the tag itself always counts, a release Gitea flags `prerelease` counts as one whatever its tag, build metadata is ignored and equal precedence counts as highest; a body that is not a JSON array (a sign-in page, an API error) is refused (exit 2), and the tag then moves no channel (next row). It replaces curl + grep + `sort -V` in release.yml and the 2026-10-23 rule "`:latest` only for the highest stable version". (Owner review 2, R1.) | Point the Unraid template and compose at `:nightly` or a pinned `:<ver>`; push `:latest` for every pre-release; keep `sort -V` over all releases | With only pre-releases published (v0.1.0-rc.1, rc.2) `:latest` never existed, so the template and compose found no image. Users should get the newest release, not the untested nightly build of `main`. A pre-release published after a stable one, or an older tag re-published, must not move `:latest`. `sort -V` ranks `1.0.0-rc.1` above `1.0.0`, so it cannot compare pre-releases with stable releases. |
|
||||
| 2026-10-26 | release.yml decides the channels after publishing, from every page of the releases list (`page=1, 2, …` up to the first empty page, at most 100); when it cannot (a page unreadable or not a JSON array, more pages, or a tag older than `release-channels`, such as `v0.1.0-rc.1` and `rc.2`, whose `Chronos.Tools` is built from the tag and lacks the command) it warns and the tag moves neither the releases repository nor `:latest`, while the image job still pushes `:<ver>`. The Version step checks the tag with release-channels' SemVer 2.0 pattern without `+BUILD` (no leading zeros, no empty identifiers), so a tag the command would refuse stops before anything is built or published. (Owner review 2, R1; review of phase 1.) | Fail the step; build `Chronos.Tools` from the workflow's own commit for this command; read one page | The release is already public when the channels are decided: failing then loses the image as well, while moving no channel is always safe, and a second build for two old tags costs minutes. Pre-releases now share Gitea's 50-a-page list with stable releases, so one page could hide the only stable release and move `:latest` to a pre-release. |
|
||||
| 2026-10-26 | The admin panel's free space comes from an optional space path (`SpacePath` in `server.json`, `CHRONOS_SPACE_PATH`): the Unraid template maps the share's array view `/mnt/user0/Timelapse` read-only to `/space` (*Array view*) and sets *Space path* to `/space` (advanced); empty means the archive's volume, as before. The archive's own volume, where uploads land, is shown apart as *Write volume*. `ArchiveStatsDto` keeps `FreeBytes`/`CapacityBytes` as the shown volume's figures and gains optional `WriteFreeBytes`, `WriteCapacityBytes`, `FileSystem` and `UsesSpacePath`. (Owner review 2, R2.) | Sum the array disks (`/mnt/disk*`) mapped into the container; read Unraid's emhttp state files; call Unraid's API | The container sees only what is mapped: one read-only mount of the same share's array view gives the array's figures with no host access, no external process and no Unraid-specific code. Only the server builds the stats and only the admin panel reads them, so the new members break no client. |
|
||||
| 2026-10-26 | The file system type and mount of a folder come from `/proc/self/mountinfo` on Linux: the longest mount point that is the folder or one of its parents, of mounts stacked there the last listed, octal escapes (`\040`) decoded; elsewhere `DriveInfo.DriveFormat`. (Owner review 2, R2.) | `DriveInfo.DriveFormat` alone; `findmnt` or `stat -f` | `DriveFormat` calls a FUSE mount only "fuse", never `fuse.shfs`, which is what tells an Unraid share apart; external processes are not allowed at runtime. |
|
||||
| 2026-10-26 | A space path that is missing or cannot be measured falls back to the archive's volume with one warning: at start, and again only after it has been measured in between. (Owner review 2, R2.) | Refuse to start; warn on every request | The template's default (`/space`) without the mapping must not stop the server or flood the log. |
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Text.RegularExpressions;
|
||||
using Chronos.Testing;
|
||||
using Chronos.Tools.Commands;
|
||||
|
||||
@@ -75,6 +76,18 @@ public sealed class ReleaseChannelsCommandTests(TestContext context)
|
||||
Assert.Equal(Neither, Decide("v2.0.0", """[{"name":"no tag"},{"tag_name":42},{"tag_name":"v3.0.0"},7,null]"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EveryPageOfTheListCounts()
|
||||
{
|
||||
// Gitea lists 50 releases a page, newest first: 50 pre-releases after v1.0.0 push it to the second page.
|
||||
var first = Releases([.. Enumerable.Range(1, 50).Reverse().Select(n => $"v1.1.0-rc.{n}")]);
|
||||
var second = Releases("v1.0.0", "v0.9.0");
|
||||
Assert.Equal(ImageOnly, Decide("v1.1.0-rc.51", first), "the first page alone shows no stable release");
|
||||
Assert.Equal(Neither, Decide("v1.1.0-rc.51", first, second));
|
||||
Assert.Equal(Neither, Decide("v0.9.0", first, second));
|
||||
Assert.Equal(Both, Decide("v1.1.0", first, second, "[]"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheTagCountsAsPublishedWhenTheListIsEmpty()
|
||||
{
|
||||
@@ -128,12 +141,39 @@ public sealed class ReleaseChannelsCommandTests(TestContext context)
|
||||
await Assert.ThrowsAsync<ToolException>(() => command.RunAsync(["--tag", "v1.0.0-rc.01", "--releases", file]));
|
||||
await Assert.ThrowsAsync<ToolException>(() => command.RunAsync(["--releases", file]));
|
||||
await Assert.ThrowsAsync<ToolException>(() => command.RunAsync(["--tag", "v1.0.0", "--releases", file + ".missing"]));
|
||||
// A sign-in page or an API error instead of the list.
|
||||
// Every page is read: a missing one is refused, not skipped.
|
||||
Assert.Equal(0, await command.RunAsync(["--tag", "v1.0.0", "--releases", file, "--releases", file]));
|
||||
await Assert.ThrowsAsync<ToolException>(() => command.RunAsync(["--tag", "v1.0.0", "--releases", file, "--releases", file + ".missing"]));
|
||||
// A sign-in page or an API error instead of the list, on any page.
|
||||
Assert.Throws<ToolException>(() => Decide("v1.0.0", "<html>Sign in</html>"));
|
||||
Assert.Throws<ToolException>(() => Decide("v1.0.0", """{"message":"not found"}"""));
|
||||
Assert.Throws<ToolException>(() => Decide("v1.0.0", "[]", """{"message":"not found"}"""));
|
||||
}
|
||||
|
||||
private static ReleaseChannels Decide(string tag, string releases) => ReleaseChannelsCommand.Decide(tag, releases);
|
||||
[Test]
|
||||
public void TheReleaseWorkflowRefusesTheTagsReleaseChannelsRefuses()
|
||||
{
|
||||
// release.yml checks the tag before building, so a tag release-channels would refuse never gets published.
|
||||
var lines = File.ReadAllLines(Path.Combine(Args.RepoRoot(), ".gitea", "workflows", "release.yml"))
|
||||
.Select(l => l.Trim()).Where(l => l.StartsWith("semver='", StringComparison.Ordinal) && l.EndsWith('\'')).ToList();
|
||||
Assert.Count(1, lines);
|
||||
var check = new Regex(lines[0]["semver='".Length..^1], RegexOptions.CultureInvariant);
|
||||
|
||||
string[] tags =
|
||||
[
|
||||
"v0.1.0", "v1.2.3", "v10.20.30", "v0.1.0-rc.1", "v1.0.0-alpha.beta", "v1.0.0-0", "v1.0.0-x-y.7z.92", "v1.0.0-rc.1+sha.5",
|
||||
"v1.0.0+build", "1.0.0", "V1.0.0", "v1.0", "v1.0.0.0", "v01.2.0", "v1.02.0", "v1.2.03", "v1.0.0-", "v1.0.0-rc.",
|
||||
"v1.0.0-rc..1", "v1.0.0-rc.01", "v1.0.0-rc_1", "latest",
|
||||
];
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
// Build metadata is refused by the workflow as well: an image tag cannot hold a "+".
|
||||
var expected = TagVersion.Parse(tag) is not null && !tag.Contains('+', StringComparison.Ordinal);
|
||||
Assert.Equal(expected, check.IsMatch(tag), tag);
|
||||
}
|
||||
}
|
||||
|
||||
private static ReleaseChannels Decide(string tag, params string[] releases) => ReleaseChannelsCommand.Decide(tag, releases);
|
||||
|
||||
private static string Releases(params string[] tags) => new JsonArray([.. tags.Select(t => Release(t))]).ToJsonString();
|
||||
|
||||
|
||||
Reference in new issue
Block a user