CI senza azioni e senza Node, solo comandi scritti in casa (C6, 3/4)
Per la decisione di Alberto del 18 novembre 2026 (niente componenti esterni) i flussi di verifica, rilascio e pulizia non usano più azioni JavaScript, che vogliono Node: - sorgenti con git init/fetch e il gettone del lavoro, passato a git solo nell'ambiente del passo, mai scritto nella configurazione; - SDK .NET con .gitea/scripts/dotnet.sh, dai metadati di Microsoft e verificato con lo SHA-512 prima di installarlo nella cache degli strumenti del runner; - builder buildx creato da costruisci-immagine.sh builder; - artefatti nel pacchetto generico febe-ci del registro di Gitea (artefatti.sh, con REGISTRY_TOKEN), tolti dalla pulizia del lunedì dopo 14 giorni; la release ricostruisce installatore e zip invece di riceverli da un altro lavoro; - JSON letto con un lettore in awk POSIX (json.awk) per i controlli e per la scelta delle versioni del registro, al posto di versioni-registro.js; - contenitore delle prove debian:trixie al posto di node:24-trixie; - la prova della pagina di accesso gira in Chromium invece che in Node. controlli.sh rifiuta ora un flusso con uses:, tabulazioni o rientri dispari, e le prove nuove controllano l'assenza di Node, il passo dei sorgenti uguale in ogni lavoro, l'SDK prima di ogni dotnet, la scelta dell'SDK, il caricamento degli artefatti con un curl finto e la scadenza dei vecchi. Nessuna esecuzione vera di Gitea Actions: ciò che resta da vedere è in docs/processo.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7a54f1a460
commit
a4ad8a8bc4
27 files changed
+1763
-396
No files matched your search
@@ -7,8 +7,9 @@ using Febe.Tests.Support;
|
||||
namespace Febe.Tests.Packaging;
|
||||
|
||||
/// <summary>
|
||||
/// The cleanup of the CI: .gitea/scripts/pulizia-docker.sh, its choice of registry tags (versioni-registro.js) and the
|
||||
/// steps that run it. The Docker daemon is shared with Alberto's other projects, very likely with his Unraid apps, and
|
||||
/// The cleanup of the CI: .gitea/scripts/pulizia-docker.sh, its choice of registry versions (versioni-registro.sh, awk
|
||||
/// with json.awk: no Node, no jq) and the steps that run it. The Docker daemon is shared with Alberto's other projects,
|
||||
/// very likely with his Unraid apps, and
|
||||
/// may run a real Febe. Since 21 October 2026 the cleanup removes what the CI of Febe made and what nothing uses any
|
||||
/// more, of any project; never a container, a volume or a network that is not the CI's, never main, latest or a
|
||||
/// release on the registry, never the token in the log; with --prova it removes nothing at all. The script runs against
|
||||
@@ -34,6 +35,12 @@ public sealed partial class PipelineTests
|
||||
"sha256:d0e666bf0a465af6218c1825f3fd72143e2f9ddfc038a8cda19b0504656e0647",
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
/// The versions of the generic package febe-ci in artefatti-registro.json created more than 14 days ago, oldest
|
||||
/// first: those of 2020 with the shape of an artifact of the CI and a date with its zone.
|
||||
/// </summary>
|
||||
private static readonly string[] ExpiredArtifacts = ["0.1.2-rilascio.3", "0.1.2-ci.40", "0.2.0-rc.1-ci.7"];
|
||||
|
||||
[TestMethod]
|
||||
public void TheCleanupNeverPrunesBlindlyAndChoosesOnlyByTheMarksOfTheCiOrByUse()
|
||||
{
|
||||
@@ -80,9 +87,13 @@ public sealed partial class PipelineTests
|
||||
Assert.IsFalse(ForcedImageRemoval().IsMatch(cleanup), "an image is never removed by force");
|
||||
StringAssert.Contains(cleanup, "[[ \"$riferimento\" =~ ^febe-ci:[0-9]+$ ]]");
|
||||
|
||||
// On the registry only the shape of a sha- tag of the verification, checked again before every DELETE.
|
||||
// On the registry only the shape of a sha- tag of the verification, or of an artifact of the CI, checked again
|
||||
// before every DELETE.
|
||||
StringAssert.Contains(cleanup, "[[ ! \"$versione\" =~ ^sha-[0-9a-f]{7,40}$ ]]");
|
||||
StringAssert.Contains(Script("versioni-registro.js"), "/^sha-[0-9a-f]{7,40}$/");
|
||||
StringAssert.Contains(cleanup, "[[ ! \"$versione\" =~ ^[0-9]+\\.[0-9]+\\.[0-9]+(-[0-9A-Za-z.-]+)?-(ci|rilascio)\\.[0-9]+$ ]]");
|
||||
var chooser = Script("versioni-registro.sh");
|
||||
StringAssert.Contains(chooser, "$4 ~ /^sha-[0-9a-f]+$/ && length($4) >= 11 && length($4) <= 44");
|
||||
Assert.DoesNotContain("node", Code(Script("pulizia-docker.sh")) + Code(chooser), "the registry is read with awk, not with Node");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -321,7 +332,6 @@ public sealed partial class PipelineTests
|
||||
public async Task TheDryRunListsWhatTheCleanupWouldTakeAndTouchesNothing()
|
||||
{
|
||||
var bash = RequireBash();
|
||||
RequireNode();
|
||||
var world = SharedDaemon.World with { Registry = new FakeRegistry(RegistryToken) };
|
||||
var tried = await RunCleanupAsync(bash, world, "completa", "--prova");
|
||||
Assert.AreEqual(0, tried.Code, tried.Report);
|
||||
@@ -336,7 +346,14 @@ public sealed partial class PipelineTests
|
||||
|
||||
Assert.IsTrue(tried.RegistryCalls.Count > 0 && tried.RegistryCalls.All(c => c.StartsWith("GET ", StringComparison.Ordinal)), tried.Report);
|
||||
Assert.IsEmpty(tried.Deleted, tried.Report);
|
||||
Assert.IsEmpty(tried.DeletedArtifacts, tried.Report);
|
||||
Assert.DoesNotContain(RegistryToken, tried.Output + tried.Errors, "the token never reaches the log");
|
||||
foreach (var version in ExpiredArtifacts)
|
||||
{
|
||||
StringAssert.Contains(tried.Output, $" toglierei febe-ci {version} (caricata il ", tried.Report);
|
||||
}
|
||||
|
||||
Assert.AreEqual(ExpiredArtifacts.Length.ToString(System.Globalization.CultureInfo.InvariantCulture), SummaryCount(tried.Output, "artefatti della CI sul registro"), tried.Report);
|
||||
|
||||
// What it lists, with size and age: also what becomes unused once the leftovers it lists are gone.
|
||||
Assert.DoesNotContain("solo indicativo", tried.Output, "with the classic store the ages are those «until» uses");
|
||||
@@ -428,21 +445,22 @@ public sealed partial class PipelineTests
|
||||
[Timeout(60_000, CooperativeCancellation = true)]
|
||||
public async Task TheRegistryKeepsMainLatestTheReleasesAndTheTenNewestShaTags()
|
||||
{
|
||||
var node = RequireNode();
|
||||
var script = CiPath("scripts", "versioni-registro.js");
|
||||
var bash = RequireBash();
|
||||
CiPath("scripts", "versioni-registro.sh");
|
||||
const string script = ".gitea/scripts/versioni-registro.sh";
|
||||
using var folder = new TempFolder("febe-registro");
|
||||
var pages = await WriteRegistryPagesAsync(folder.Path);
|
||||
|
||||
// Of fourteen sha- tags the four oldest go. sha-3d4e5f6 (23:30 UTC) is newer than sha-4e5f6a7 (01:00 in Italy,
|
||||
// 23:00 UTC): dates, not text. main, latest, the releases, digests, malformed sha- tags, one without a date and
|
||||
// other packages stay, though they are older; a tag in two pages counts once.
|
||||
var chosen = await RunProcessAsync(node, [script, "10", .. pages]);
|
||||
var chosen = await RunProcessAsync(bash, [script, "10", .. pages]);
|
||||
Assert.AreEqual(0, chosen.Code, chosen.Errors);
|
||||
CollectionAssert.AreEqual(OldShaTags, Lines(chosen.Output).Select(l => l.Split('\t')[0]).ToList(), chosen.Output);
|
||||
StringAssert.Contains(chosen.Output, "sha-2c3d4e5\t2026-10-03T07:00:00Z\n");
|
||||
|
||||
// Keeping none: every well formed sha- tag of the container febe, and nothing else.
|
||||
var all = await RunProcessAsync(node, [script, "0", .. pages]);
|
||||
var all = await RunProcessAsync(bash, [script, "0", .. pages]);
|
||||
Assert.HasCount(14, Lines(all.Output), all.Output);
|
||||
foreach (var line in Lines(all.Output))
|
||||
{
|
||||
@@ -451,20 +469,63 @@ public sealed partial class PipelineTests
|
||||
|
||||
// The untagged versions, the manifests of an index with their layers: listed only to be counted, oldest first,
|
||||
// those of the container febe and no other package.
|
||||
var untagged = await RunProcessAsync(node, [script, "senza-etichetta", .. pages]);
|
||||
var untagged = await RunProcessAsync(bash, [script, "senza-etichetta", .. pages]);
|
||||
Assert.AreEqual(0, untagged.Code, untagged.Errors);
|
||||
CollectionAssert.AreEqual(UntaggedDigests, Lines(untagged.Output).Select(l => l.Split('\t')[0]).ToList(), untagged.Output);
|
||||
|
||||
// Keeping more than there are: nothing. An empty page of Gitea is fine; a page that is not a list stops
|
||||
// everything, so in doubt nothing goes.
|
||||
// Keeping more than there are: nothing. An empty page of Gitea is fine; a page that is not a list, or not JSON,
|
||||
// stops everything, so in doubt nothing goes. So does a mode written another way.
|
||||
var empty = Path.Combine(folder.Path, "vuota.json");
|
||||
await File.WriteAllTextAsync(empty, "null", TestContext.CancellationToken);
|
||||
Assert.IsEmpty((await RunProcessAsync(node, [script, "20", .. pages, empty])).Output);
|
||||
Assert.IsEmpty((await RunProcessAsync(bash, [script, "20", .. pages, empty])).Output);
|
||||
var broken = Path.Combine(folder.Path, "rotta.json");
|
||||
await File.WriteAllTextAsync(broken, "{\"message\":\"internal error\"}", TestContext.CancellationToken);
|
||||
var refused = await RunProcessAsync(node, [script, "10", .. pages, broken]);
|
||||
Assert.AreEqual(2, refused.Code, refused.Errors);
|
||||
Assert.IsEmpty(refused.Output);
|
||||
var cut = Path.Combine(folder.Path, "tagliata.json");
|
||||
await File.WriteAllTextAsync(cut, "[{\"type\":\"container\",\"name\":\"febe\",\"version\":\"sha-0a1b2c3\"", TestContext.CancellationToken);
|
||||
foreach (var bad in new[] { broken, cut })
|
||||
{
|
||||
var refused = await RunProcessAsync(bash, [script, "10", .. pages, bad]);
|
||||
Assert.AreEqual(2, refused.Code, refused.Errors);
|
||||
Assert.IsEmpty(refused.Output);
|
||||
StringAssert.Contains(refused.Errors, Path.GetFileName(bad));
|
||||
}
|
||||
|
||||
foreach (var mode in new[] { "dieci", "-1", "senza_etichetta" })
|
||||
{
|
||||
var wrong = await RunProcessAsync(bash, [script, mode, .. pages]);
|
||||
Assert.AreEqual(2, wrong.Code, mode);
|
||||
Assert.IsEmpty(wrong.Output, mode);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(60_000, CooperativeCancellation = true)]
|
||||
public async Task OnlyTheArtifactsOfTheCiOlderThanTheirDaysExpire()
|
||||
{
|
||||
var bash = RequireBash();
|
||||
CiPath("scripts", "versioni-registro.sh");
|
||||
const string script = ".gitea/scripts/versioni-registro.sh";
|
||||
using var folder = new TempFolder("febe-artefatti");
|
||||
var pages = await WriteArtifactPagesAsync(folder.Path, "pagina-");
|
||||
var now = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
|
||||
// Those of 2020 with the shape <x.y.z>-ci.<n> or <x.y.z>-rilascio.<n>, oldest first. The one of 2099, a release
|
||||
// version, a date that does not read or has no zone, another package, a container and a strange name stay.
|
||||
var expired = await RunProcessAsync(bash, [script, "scadute", "14", now, .. pages]);
|
||||
Assert.AreEqual(0, expired.Code, expired.Errors);
|
||||
CollectionAssert.AreEqual(ExpiredArtifacts, Lines(expired.Output).Select(l => l.Split('\t')[0]).ToList(), expired.Output);
|
||||
StringAssert.Contains(expired.Output, "0.2.0-rc.1-ci.7\t2020-04-01T00:00:00.250Z\n");
|
||||
|
||||
// On the first of April 2020 at noon only those created more than a day before have expired.
|
||||
var early = await RunProcessAsync(bash, [script, "scadute", "1", "1585742400", .. pages]);
|
||||
CollectionAssert.AreEqual(new[] { "0.1.2-rilascio.3", "0.1.2-ci.40" }, Lines(early.Output).Select(l => l.Split('\t')[0]).ToList(), early.Output);
|
||||
|
||||
foreach (var arguments in new[] { new[] { "scadute", "14" }, ["scadute", "quattordici", now], ["scadute", "14", "ieri"] })
|
||||
{
|
||||
var wrong = await RunProcessAsync(bash, [script, .. arguments, .. pages]);
|
||||
Assert.AreEqual(2, wrong.Code, string.Join(' ', arguments));
|
||||
Assert.IsEmpty(wrong.Output);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -472,41 +533,54 @@ public sealed partial class PipelineTests
|
||||
public async Task TheRegistryCleanupDeletesOnlyTheChosenTagsNeverPrintsTheTokenAndARefusalIsOnlyAWarning()
|
||||
{
|
||||
var bash = RequireBash();
|
||||
RequireNode();
|
||||
|
||||
// A daemon with almost nothing on it: here only the registry counts.
|
||||
var quiet = new World(["c-encelado|encelado|exited|5000|encelado:latest|img-encelado|"], ["img-encelado|encelado:latest|5000||250MB"], [], []);
|
||||
var run = await RunCleanupAsync(bash, quiet with { Registry = new FakeRegistry(RegistryToken) }, "completa");
|
||||
Assert.AreEqual(0, run.Code, run.Report);
|
||||
CollectionAssert.AreEqual(OldShaTags, run.Deleted, run.Report);
|
||||
CollectionAssert.AreEqual(ExpiredArtifacts, run.DeletedArtifacts, run.Report);
|
||||
var package = $"{RegistryApi}/packages/Alby96/container/febe";
|
||||
var artifacts = $"{RegistryApi}/packages/Alby96/generic/febe-ci";
|
||||
CollectionAssert.AreEqual(
|
||||
new[] { $"GET {package}?page=1&limit=50", $"GET {package}?page=2&limit=50", $"GET {package}?page=3&limit=50" }
|
||||
.Concat(OldShaTags.Select(tag => $"DELETE {package}/{tag}")).ToList(),
|
||||
.Concat(OldShaTags.Select(tag => $"DELETE {package}/{tag}"))
|
||||
.Concat([$"GET {artifacts}?page=1&limit=50", $"GET {artifacts}?page=2&limit=50", $"GET {artifacts}?page=3&limit=50"])
|
||||
.Concat(ExpiredArtifacts.Select(version => $"DELETE {artifacts}/{version}")).ToList(),
|
||||
run.RegistryCalls,
|
||||
run.Report);
|
||||
Assert.DoesNotContain(RegistryToken, run.Output + run.Errors, "the token never reaches the log");
|
||||
Assert.AreEqual("4", SummaryCount(run.Output, "etichette sha- sul registro"), run.Report);
|
||||
Assert.AreEqual("3", SummaryCount(run.Output, "artefatti della CI sul registro"), run.Report);
|
||||
|
||||
// The untagged versions stay, and the log says how many there are: their layers are freed only by a cleanup
|
||||
// rule of Gitea, which knows whether a tag still uses them.
|
||||
Assert.IsFalse(run.RegistryCalls.Any(c => c.Contains("sha256:", StringComparison.Ordinal)), run.Report);
|
||||
StringAssert.Contains(run.Output, $" {UntaggedDigests.Length} versioni senza etichetta (sha256:…, i manifest di un indice con i loro strati): restano", run.Report);
|
||||
|
||||
// No package febe-ci yet (404): nothing to remove there, and no warning.
|
||||
var without = await RunCleanupAsync(bash, quiet with { Registry = new FakeRegistry(RegistryToken, Artifacts: false) }, "completa");
|
||||
Assert.AreEqual(0, without.Code, without.Report);
|
||||
StringAssert.Contains(without.Output, "Il pacchetto febe-ci non è ancora sul registro: niente da togliere.", without.Report);
|
||||
Assert.IsEmpty(without.DeletedArtifacts, without.Report);
|
||||
Assert.IsFalse(WarningLine().IsMatch(without.Output), without.Report);
|
||||
|
||||
// The API refuses (a token without the permission) or does not know the token: a warning, nothing deleted,
|
||||
// and the weekly job stays green.
|
||||
// the registry is not asked again with the same token, and the weekly job stays green.
|
||||
foreach (var registry in new[] { new FakeRegistry(RegistryToken, Refuse: true), new FakeRegistry(RegistryToken, Sent: "un-altro-gettone-finto") })
|
||||
{
|
||||
var refused = await RunCleanupAsync(bash, quiet with { Registry = registry }, "completa");
|
||||
Assert.AreEqual(0, refused.Code, refused.Report);
|
||||
StringAssert.Contains(refused.Output, "::warning::L'API dei pacchetti di Gitea risponde 40", refused.Report);
|
||||
Assert.IsEmpty(refused.Deleted, refused.Report);
|
||||
Assert.IsEmpty(refused.DeletedArtifacts, refused.Report);
|
||||
Assert.HasCount(1, refused.RegistryCalls, refused.Report);
|
||||
Assert.DoesNotContain(RegistryToken, refused.Output + refused.Errors);
|
||||
Assert.DoesNotContain("un-altro-gettone-finto", refused.Output + refused.Errors);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The daemon of <see cref="OnADaemonSharedWithARealFebeTheCleanupOfTheCiTakesOnlyWhatTheCiMade"/> (format in
|
||||
/// fake-docker.sh). A real Febe started from :latest and one from :main carry the febe.ci.* labels of their images,
|
||||
@@ -714,10 +788,11 @@ public sealed partial class PipelineTests
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The packages API of Gitea with the pages of versioni-registro.json, for the token given. Sent is the token the
|
||||
/// cleanup gets (the same, if null); Refuse answers 403 to everything.
|
||||
/// The packages API of Gitea with the pages of versioni-registro.json and, with Artifacts, the generic package
|
||||
/// febe-ci of artefatti-registro.json, for the token given. Sent is the token the cleanup gets (the same, if null);
|
||||
/// Refuse answers 403 to everything.
|
||||
/// </summary>
|
||||
private sealed record FakeRegistry(string Token, bool Refuse = false, string? Sent = null);
|
||||
private sealed record FakeRegistry(string Token, bool Refuse = false, string? Sent = null, bool Artifacts = true);
|
||||
|
||||
private sealed record CleanupRun(int Code, string Output, string Errors)
|
||||
{
|
||||
@@ -740,6 +815,9 @@ public sealed partial class PipelineTests
|
||||
/// <summary>The versions deleted from the registry.</summary>
|
||||
public List<string> Deleted { get; init; } = [];
|
||||
|
||||
/// <summary>The versions of the generic package febe-ci deleted from the registry.</summary>
|
||||
public List<string> DeletedArtifacts { get; init; } = [];
|
||||
|
||||
public List<string> ImageIds => [.. Images.Select(i => i.Split('|')[0])];
|
||||
|
||||
public string Report => $"codice {Code}\n{Output}\n{Errors}";
|
||||
@@ -794,6 +872,11 @@ public sealed partial class PipelineTests
|
||||
}
|
||||
|
||||
await WriteRegistryPagesAsync(registry);
|
||||
if (fake.Artifacts)
|
||||
{
|
||||
await File.WriteAllTextAsync(Path.Combine(registry, "base-ci"), $"{RegistryApi}/packages/Alby96/generic/febe-ci", TestContext.CancellationToken);
|
||||
await WriteArtifactPagesAsync(registry, "ci-page-");
|
||||
}
|
||||
}
|
||||
|
||||
// The fakes go first on the PATH from inside bash: Git Bash puts its own folders (with a real curl) before the
|
||||
@@ -826,6 +909,7 @@ public sealed partial class PipelineTests
|
||||
Calls = await ReadLinesAsync(folder.Combine("calls")),
|
||||
RegistryCalls = await ReadLinesAsync(Path.Combine(registry, "calls")),
|
||||
Deleted = await ReadLinesAsync(Path.Combine(registry, "deleted")),
|
||||
DeletedArtifacts = await ReadLinesAsync(Path.Combine(registry, "deleted-ci")),
|
||||
};
|
||||
if (touchesDocker)
|
||||
{
|
||||
@@ -879,6 +963,23 @@ public sealed partial class PipelineTests
|
||||
return files;
|
||||
}
|
||||
|
||||
/// <summary>The pages of artefatti-registro.json (the generic package febe-ci) as Gitea would answer them, one
|
||||
/// file each, named prefix plus the page number.</summary>
|
||||
private async Task<List<string>> WriteArtifactPagesAsync(string folder, string prefix)
|
||||
{
|
||||
var fixture = await File.ReadAllTextAsync(Repository.PathOf("tests", "Febe.Tests", "Packaging", "artefatti-registro.json"), TestContext.CancellationToken);
|
||||
using var pages = JsonDocument.Parse(fixture);
|
||||
var files = new List<string>();
|
||||
foreach (var page in pages.RootElement.EnumerateArray())
|
||||
{
|
||||
var file = Path.Combine(folder, $"{prefix}{files.Count + 1}.json");
|
||||
await File.WriteAllTextAsync(file, page.GetRawText(), TestContext.CancellationToken);
|
||||
files.Add(file);
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
private static void InstallFake(string name, string path)
|
||||
{
|
||||
File.Copy(Repository.PathOf("tests", "Febe.Tests", "Packaging", name), path);
|
||||
@@ -935,22 +1036,6 @@ public sealed partial class PipelineTests
|
||||
return bash;
|
||||
}
|
||||
|
||||
/// <summary>node from the PATH: the registry part of the cleanup reads JSON with it, in the CI as here.</summary>
|
||||
private static string RequireNode()
|
||||
{
|
||||
var names = OperatingSystem.IsWindows() ? new[] { "node.exe" } : ["node"];
|
||||
var node = (Environment.GetEnvironmentVariable("PATH") ?? string.Empty)
|
||||
.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries)
|
||||
.SelectMany(folder => names.Select(name => Path.Combine(folder.Trim('"'), name)))
|
||||
.FirstOrDefault(File.Exists);
|
||||
if (node is null)
|
||||
{
|
||||
Assert.Inconclusive("Manca node: la prova della scelta delle versioni del registro si salta.");
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"docker (?<what>[a-z]+) prune(?<args>[^\n]*)")]
|
||||
private static partial Regex Prune();
|
||||
|
||||
|
||||
Reference in new issue
Block a user