Files
Mimante/.gitea/scripts/versioni-registro.js
T
Alby96andClaude Opus 5.5 bddb624f5e
verifica / controlli (push) Failing after 1m0s
verifica / prove (push) Skipped
verifica / immagine (push) Skipped
CI su Gitea come Febe: verifica, rilascio, pulizia (#24)
I flussi di prima non erano mai partiti (stavano in una sottocartella) e
avrebbero pubblicato la porta 5432 sul Docker di Unraid, dove gira il
PostgreSQL vero. Ora, come in Febe: a ogni push controlli (sintassi, versione,
CHANGELOG, elenco chiuso dei pacchetti, niente risorse esterne
nell'interfaccia, JSON con commenti come li legge il programma) e gitleaks su
tutta la storia; tutte le prove con un postgres:18 di servizio senza porte,
nessuna saltata; immagine costruita, provata su una rete Docker interna con un
PostgreSQL usa e getta (salute, file di /config a 99:100, arresto entro 15 s) e
scansionata con Trivy, pubblicata come :main/:sha- solo da main. Il rilascio
sul tag pubblica :X.Y.Z e :latest (un -rc.N solo la sua etichetta) e allega il
modello Unraid; la pulizia notturna tocca solo i resti della CI di Mimante e le
:sha- vecchie. PipelineTests tiene ferme queste regole; le sue prove leggono
.gitea e per questo non girano dentro la costruzione dell'immagine.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 12:07:02 +01:00

83 lines
3.2 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>...
// node versioni-registro.js senza-etichetta <page.json>...
//
// Each file is a page of the answer of GET /api/v1/packages/{owner}/container/mimante of Gitea 28: a list of versions with
// «type», «name», «version» and «created_at» (an empty page may be «[]» or «null»). Only the versions of the container
// package «mimante» count, and a version found in two pages counts once. Both forms print, oldest first and one per line,
// «version<TAB>created».
//
// With a number N: the sha-<7 to 40 hex digits> tags 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.
//
// With «senza-etichetta»: the untagged versions, sha256:<64 hex digits>. They are the manifests of an image index,
// which Gitea keeps as versions of their own with the configuration and the layers; nothing here removes them (Gitea
// cannot be asked through this API whether a tag still uses one), the cleanup only says how many there are.
//
// 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 [mode, ...pages] = process.argv.slice(2);
const untagged = mode === "senza-etichetta";
if (!(untagged || /^[0-9]+$/.test(mode || "")) || pages.length === 0) {
console.error("Uso: node versioni-registro.js <quante tenere> | senza-etichetta <pagina.json>...");
process.exit(2);
}
const shaTag = /^sha-[0-9a-f]{7,40}$/;
const digest = /^sha256:[0-9a-f]{64}$/;
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 === "mimante" && typeof version.version === "string") {
versions.set(version.version, version);
}
}
}
const dated = (version) => ({
name: version.version,
created: String(version.created_at),
time: Date.parse(version.created_at),
id: Number(version.id) || 0,
});
let chosen;
if (untagged) {
chosen = [...versions.values()]
.filter((version) => digest.test(version.version))
.map(dated)
.sort((a, b) => (Number.isFinite(a.time) ? a.time : 0) - (Number.isFinite(b.time) ? b.time : 0) || a.id - b.id);
} else {
chosen = [...versions.values()]
.filter((version) => shaTag.test(version.version))
.map(dated)
.filter((version) => Number.isFinite(version.time))
.sort((a, b) => b.time - a.time || b.id - a.id)
.slice(Number(mode))
.reverse();
}
for (const version of chosen) {
process.stdout.write(`${version.name}\t${version.created}\n`);
}