"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 ... // // 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, «versioncreated» 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 ..."); 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`); }