Files
Febe/.gitea/scripts/versioni-registro.js
T
Alby96andClaude Opus 5.5 5988c503f7 Pulizia: versioni-registro.js con codice e commenti in inglese
Lo script è nuovo e la regola del repository vuole codice e commenti in
inglese (CLAUDE.md, «Convenzioni»); i messaggi restano in italiano, come
tutti quelli della CI. Nessun cambio di comportamento: sulle pagine di
tests/Febe.Tests/Packaging/versioni-registro.json la scelta è identica
byte per byte, tenendone 0, 10 e 20, e gli errori escono ancora con 2.
Gli script di shell di .gitea, già in italiano prima di questo ramo,
restano come sono.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 11:29:38 +02:00

60 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use strict";
// Chooses the tags to remove from Gitea's container registry (pulizia-docker.sh, mode «completa»). It only reads the
// files it is given: no network, no writes, so it is tested with a JSON file.
//
// node versioni-registro.js <how many to keep> <page.json>...
//
// Each file is a page of the answer of GET /api/v1/packages/{owner}/container/febe of Gitea 28: a list of versions with
// «type», «name», «version» and «created_at» (an empty page may be «[]» or «null»). It prints, oldest first and one per
// line, «version<TAB>created» of the sha-<7 to 40 hex digits> tags of the container package «febe» beyond the N newest
// by creation date. Everything else always stays: main, latest, the X.Y.Z releases (X.Y.Z-rc.N too), the digests
// (sha256:…), any other tag and a sha- tag without a date that can be read. A version found in two pages counts once.
// If a file is not a JSON list it exits with 2 and prints nothing: when in doubt nothing is removed.
// Messages are in Italian, like every message of the CI.
const fs = require("fs");
const [keep, ...pages] = process.argv.slice(2);
if (!/^[0-9]+$/.test(keep || "") || pages.length === 0) {
console.error("Uso: node versioni-registro.js <quante tenere> <pagina.json>...");
process.exit(2);
}
const shaTag = /^sha-[0-9a-f]{7,40}$/;
const versions = new Map();
for (const file of pages) {
let page;
try {
page = JSON.parse(fs.readFileSync(file, "utf8").replace(/^/, ""));
} catch (error) {
console.error(`${file}: ${error.message}`);
process.exit(2);
}
if (page === null) {
continue;
}
if (!Array.isArray(page)) {
console.error(`${file}: non è un elenco di versioni`);
process.exit(2);
}
for (const version of page) {
if (version && version.type === "container" && version.name === "febe" && typeof version.version === "string") {
versions.set(version.version, version);
}
}
}
const candidates = [...versions.values()]
.filter((version) => shaTag.test(version.version))
.map((version) => ({
name: version.version,
created: String(version.created_at),
time: Date.parse(version.created_at),
id: Number(version.id) || 0,
}))
.filter((version) => Number.isFinite(version.time))
.sort((a, b) => b.time - a.time || b.id - a.id);
for (const version of candidates.slice(Number(keep)).reverse()) {
process.stdout.write(`${version.name}\t${version.created}\n`);
}