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
@@ -1,9 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
# Prepara il contenitore Debian del lavoro «prove» (node:24-trixie: Debian 13 con Node, che serve alle azioni) perché
|
||||
# nessuna prova si salti: Chromium vero della distribuzione (su Ubuntu è uno snap, che nei contenitori non va) con le
|
||||
# sue lingue, Xvfb, ffmpeg e ffprobe, la lingua it_IT.UTF-8, fusi orari, ICU e gli stessi
|
||||
# caratteri dell'immagine di Febe. Node c'è già (prova della pagina di accesso); setpriv, getent e l'utente nobody
|
||||
# (65534) vengono con Debian (prove dell'avvio del contenitore).
|
||||
# Prepara il contenitore Debian del lavoro «prove» (debian:trixie, Debian 13 senza nient'altro: nessuna azione
|
||||
# JavaScript, quindi niente Node) perché nessuna prova si salti: Chromium vero della distribuzione (su Ubuntu è uno
|
||||
# snap, che nei contenitori non va) con le sue lingue, Xvfb, ffmpeg e ffprobe, la lingua it_IT.UTF-8, fusi orari e gli
|
||||
# stessi caratteri dell'immagine di Febe; ICU, OpenSSL, zlib e libstdc++ per l'SDK .NET (dotnet.sh). git, curl e i
|
||||
# certificati li installa il passo prima dei sorgenti. setpriv, getent e l'utente nobody (65534) vengono con Debian
|
||||
# (prove dell'avvio del contenitore).
|
||||
#
|
||||
# .gitea/scripts/ambiente-prove.sh
|
||||
set -euo pipefail
|
||||
@@ -17,7 +18,7 @@ $sudo apt-get install -y -qq --no-install-recommends \
|
||||
chromium chromium-l10n \
|
||||
xvfb \
|
||||
ffmpeg \
|
||||
locales tzdata libicu76 ca-certificates \
|
||||
locales tzdata libicu76 libssl3t64 zlib1g libstdc++6 ca-certificates curl git \
|
||||
fonts-noto-color-emoji fonts-liberation fonts-dejavu-core \
|
||||
util-linux procps > /dev/null
|
||||
$sudo sed -i 's/^# *\(it_IT.UTF-8 UTF-8\)/\1/' /etc/locale.gen
|
||||
@@ -28,7 +29,10 @@ chromium --version
|
||||
command -v Xvfb
|
||||
ffmpeg -version | head -n 1 || true
|
||||
ffprobe -version | head -n 1 || true
|
||||
echo "node $(node --version)"
|
||||
locale -a | grep -i '^it_IT\.utf8$'
|
||||
for strumento in setpriv getent stat chown sh; do command -v "$strumento" > /dev/null || { echo "Manca $strumento." >&2; exit 1; }; done
|
||||
for strumento in setpriv getent stat chown sh awk sort; do command -v "$strumento" > /dev/null || { echo "Manca $strumento." >&2; exit 1; }; done
|
||||
if command -v node > /dev/null; then
|
||||
echo "C'è node in questo contenitore: la CI non deve usarlo (nessuna azione JavaScript, nessuno script Node)." >&2
|
||||
exit 1
|
||||
fi
|
||||
getent passwd 65534 > /dev/null && getent group 65534 > /dev/null || { echo "Mancano l'utente o il gruppo 65534 (nobody)." >&2; exit 1; }
|
||||
@@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env bash
|
||||
# Artefatti della CI, al posto di actions/upload-artifact (un'azione JavaScript, che vuole Node): i file vanno nel
|
||||
# registro dei pacchetti di Gitea, pacchetto generico febe-ci, una versione per esecuzione:
|
||||
#
|
||||
# <versione>-ci.<numero> dal flusso verifica (come Febe-Setup-<versione>-ci.<numero>.exe)
|
||||
# <versione>-rilascio.<numero> dal flusso rilascio
|
||||
#
|
||||
# con <versione> da Directory.Build.props e <numero> il numero dell'esecuzione (NUMERO). Si scaricano dalla pagina del
|
||||
# pacchetto su Gitea (proprietario ▸ Pacchetti ▸ febe-ci). La pulizia del lunedì (pulizia-docker.sh completa) toglie le
|
||||
# versioni create più di 14 giorni prima, come faceva la scadenza degli artefatti.
|
||||
#
|
||||
# .gitea/scripts/artefatti.sh verifica|rilascio <file>...
|
||||
#
|
||||
# Variabili: REGISTRY_TOKEN (token con «package: read and write», solo nell'intestazione di curl, mai stampato), GITEA_URL
|
||||
# (l'indirizzo del server, gitea.server_url), PROPRIETARIO, NUMERO. Senza REGISTRY_TOKEN un avviso e nessun file
|
||||
# caricato: il lavoro resta verde, come per l'immagine. Un file che manca o un rifiuto del registro fanno fallire il
|
||||
# passo. Un file con lo stesso nome già caricato (un nuovo tentativo della stessa esecuzione) si sostituisce.
|
||||
set -euo pipefail
|
||||
|
||||
flusso="${1:-}"
|
||||
case "$flusso" in
|
||||
verifica) suffisso=ci ;;
|
||||
rilascio) suffisso=rilascio ;;
|
||||
*) echo "Uso: artefatti.sh verifica|rilascio <file>..." >&2; exit 2 ;;
|
||||
esac
|
||||
shift
|
||||
(($# > 0)) || { echo "Indica almeno un file da caricare." >&2; exit 2; }
|
||||
cd "$(git rev-parse --show-toplevel)"
|
||||
|
||||
numero="${NUMERO:-}"
|
||||
[[ "$numero" =~ ^[0-9]+$ ]] || { echo "Manca NUMERO, il numero dell'esecuzione, o non è un numero: «$numero»." >&2; exit 2; }
|
||||
v=$(sed -n 's:.*<Version>\(.*\)</Version>.*:\1:p' Directory.Build.props | head -n 1)
|
||||
versione="$v-$suffisso.$numero"
|
||||
[[ "$versione" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?-(ci|rilascio)\.[0-9]+$ ]] || { echo "Versione degli artefatti non valida: «$versione»." >&2; exit 2; }
|
||||
|
||||
for file in "$@"; do
|
||||
[[ -f "$file" ]] || { echo "Manca l'artefatto $file." >&2; exit 1; }
|
||||
[[ "$(basename "$file")" =~ ^[0-9A-Za-z._-]+$ ]] || { echo "Nome di file non adatto a un pacchetto: «$(basename "$file")»." >&2; exit 2; }
|
||||
done
|
||||
|
||||
if [[ -z "${REGISTRY_TOKEN:-}" ]]; then
|
||||
echo "::warning::Manca il segreto REGISTRY_TOKEN: gli artefatti ($*) non vanno sul registro dei pacchetti. Aggiungilo (token con package: read and write) per averli per 14 giorni."
|
||||
exit 0
|
||||
fi
|
||||
proprietario="${PROPRIETARIO:?Manca PROPRIETARIO.}"
|
||||
base="${GITEA_URL:?Manca GITEA_URL.}"
|
||||
base="${base%/}/api/packages/$proprietario/generic/febe-ci/$versione"
|
||||
|
||||
# Una chiamata al registro: il codice HTTP, 000 se Gitea non risponde. Il token sta solo nell'intestazione di curl.
|
||||
chiedi() {
|
||||
local codice
|
||||
codice=$(curl -sS --max-time 900 -H "Authorization: token $REGISTRY_TOKEN" -o /dev/null -w '%{http_code}' "$@") || true
|
||||
echo "${codice:-000}"
|
||||
}
|
||||
|
||||
for file in "$@"; do
|
||||
nome="$(basename "$file")"
|
||||
codice=$(chiedi -X PUT --upload-file "$file" "$base/$nome")
|
||||
if [[ "$codice" == 409 ]]; then
|
||||
codice=$(chiedi -X DELETE "$base/$nome")
|
||||
[[ "$codice" == 204 ]] || { echo "Il registro non toglie la copia precedente di $nome: risponde $codice." >&2; exit 1; }
|
||||
codice=$(chiedi -X PUT --upload-file "$file" "$base/$nome")
|
||||
fi
|
||||
[[ "$codice" == 201 ]] || { echo "Il registro non accetta $nome: risponde $codice." >&2; exit 1; }
|
||||
echo "$nome caricato ($(du -h "$file" | cut -f1))"
|
||||
done
|
||||
echo "Artefatti: ${GITEA_URL%/}/$proprietario/-/packages/generic/febe-ci/$versione"
|
||||
+47
-29
@@ -4,18 +4,21 @@
|
||||
#
|
||||
# bash .gitea/scripts/controlli.sh
|
||||
#
|
||||
# 1. ogni script di shell del repository è sintassi valida (bash -n; sh -n per quelli in sh) e ha le righe Unix; gli
|
||||
# script Node della CI (.gitea/scripts/*.js) sono JavaScript valido (node --check);
|
||||
# 2. i flussi della CI non hanno tabulazioni (YAML non le accetta come rientro);
|
||||
# 1. ogni script di shell del repository è sintassi valida (bash -n; sh -n per quelli in sh) e ha le righe Unix, come
|
||||
# i programmi awk della CI;
|
||||
# 2. i flussi della CI si leggono come YAML a blocchi: niente tabulazioni né righe Windows, rientri di due spazi fuori
|
||||
# dai blocchi di testo, «on:» e «jobs:» presenti; e sono fatti solo di comandi: nessun «uses:», cioè nessuna
|
||||
# azione (le azioni JavaScript vogliono Node, e la CI di Febe è scritta in casa: decisione del 18 novembre 2026);
|
||||
# 3. nessun file contiene segni di conflitto rimasti da un'unione;
|
||||
# 4. la versione di Directory.Build.props è nella forma x.y.z[-qualcosa], quella che installer/costruisci.sh accetta;
|
||||
# 5. ogni progetto elencato in Febe.slnx esiste;
|
||||
# 6. ogni file JSON del repository si legge (configurazioni, campioni ripuliti, criteri di Chromium).
|
||||
# 6. ogni file JSON del repository si legge (configurazioni, campioni ripuliti, criteri di Chromium), con json.awk.
|
||||
set -uo pipefail
|
||||
|
||||
radice="$(git rev-parse --show-toplevel)" || exit 2
|
||||
cd "$radice" || exit 2
|
||||
errori=0
|
||||
export LC_ALL=C
|
||||
|
||||
errore() {
|
||||
echo "ERRORE: $*" >&2
|
||||
@@ -35,25 +38,48 @@ while IFS= read -r -d '' script; do
|
||||
fi
|
||||
done < <(git ls-files -z -- '*.sh')
|
||||
echo " $quanti script controllati"
|
||||
|
||||
echo "== Script Node della CI"
|
||||
if command -v node > /dev/null; then
|
||||
quanti=0
|
||||
while IFS= read -r -d '' script; do
|
||||
quanti=$((quanti + 1))
|
||||
node --check "$script" || errore "$script: JavaScript non valido."
|
||||
done < <(git ls-files -z -- '.gitea/scripts/*.js')
|
||||
echo " $quanti script controllati"
|
||||
else
|
||||
errore "manca node: gli script Node della CI non si possono controllare."
|
||||
fi
|
||||
while IFS= read -r -d '' programma; do
|
||||
if grep -q $'\r' "$programma"; then
|
||||
errore "$programma ha righe Windows (CR) (.gitattributes chiede eol=lf)."
|
||||
fi
|
||||
done < <(git ls-files -z -- '*.awk')
|
||||
|
||||
echo "== Flussi della CI"
|
||||
quanti=0
|
||||
while IFS= read -r -d '' flusso; do
|
||||
quanti=$((quanti + 1))
|
||||
if grep -n $'\t' "$flusso" > /dev/null; then
|
||||
errore "$flusso contiene tabulazioni: in YAML il rientro si fa con gli spazi."
|
||||
fi
|
||||
# Un blocco di testo («run: |», «>-») tiene tutte le righe più rientrate della sua chiave; fuori, i rientri sono di
|
||||
# due spazi in due e nessuna riga chiama un'azione.
|
||||
if rilievi=$(awk '
|
||||
FNR == 1 { blocco = -1; on = 0; jobs = 0 }
|
||||
{
|
||||
riga = $0
|
||||
if (riga ~ /\r$/) { print FNR ": riga Windows (CR)"; next }
|
||||
match(riga, /^ */)
|
||||
rientro = RLENGTH
|
||||
vuota = riga ~ /^ *$/
|
||||
if (blocco >= 0) {
|
||||
if (vuota || rientro > blocco) next
|
||||
blocco = -1
|
||||
}
|
||||
if (vuota || riga ~ /^ *#/) next
|
||||
if (rientro % 2 == 1) print FNR ": rientro dispari"
|
||||
if (riga ~ /^ *(- +)?uses *:/) print FNR ": «uses:» (nessuna azione: solo comandi)"
|
||||
if (riga ~ /^on:/) on = 1
|
||||
if (riga ~ /^jobs:/) jobs = 1
|
||||
if (riga ~ /: *[|>][-+]?[0-9]? *(#.*)?$/) blocco = rientro
|
||||
}
|
||||
END {
|
||||
if (!on) print "manca «on:»"
|
||||
if (!jobs) print "manca «jobs:»"
|
||||
}' "$flusso") && [[ -n "$rilievi" ]]; then
|
||||
errore "$flusso:"$'\n'"$(sed 's/^/ riga /; s/^ riga manca/ manca/' <<< "$rilievi")"
|
||||
fi
|
||||
done < <(git ls-files -z -- '.gitea/workflows/*.yml' '.gitea/workflows/*.yaml')
|
||||
echo " $quanti flussi controllati"
|
||||
|
||||
echo "== Segni di conflitto"
|
||||
if conflitti=$(git grep -n -I -E '^(<{7}|>{7})( |$)' -- . ':!*.png' ':!*.jpg'); then
|
||||
@@ -78,21 +104,13 @@ done < <(sed -n 's:.*<Project Path="\([^"]*\)".*:\1:p' Febe.slnx)
|
||||
echo " $(grep -c '<Project Path=' Febe.slnx) progetti"
|
||||
|
||||
echo "== File JSON"
|
||||
if command -v node > /dev/null; then
|
||||
# Un solo processo per tutti i file; stampa i file che non si leggono, uno per riga.
|
||||
guasti=$(git ls-files -z -- '*.json' | node -e '
|
||||
const fs = require("fs");
|
||||
const files = fs.readFileSync(0, "utf8").split("\0").filter(Boolean);
|
||||
for (const f of files) {
|
||||
try { JSON.parse(fs.readFileSync(f, "utf8").replace(/^/, "")); } catch (e) { console.log(f + ": " + e.message); }
|
||||
}
|
||||
console.error(" " + files.length + " file controllati");')
|
||||
if [[ -n "$guasti" ]]; then
|
||||
# Un solo processo per tutti i file; stampa i file che non si leggono, uno per riga, con il motivo e la riga.
|
||||
mapfile -d '' json < <(git ls-files -z -- '*.json')
|
||||
if ((${#json[@]} > 0)); then
|
||||
if ! guasti=$(awk -f .gitea/scripts/json.awk -f .gitea/scripts/json-valido.awk "${json[@]}"); then
|
||||
errore "JSON non valido:"
|
||||
echo "$guasti" >&2
|
||||
echo "${guasti:-(nessun dettaglio)}" >&2
|
||||
fi
|
||||
else
|
||||
errore "manca node: i file JSON non si possono controllare."
|
||||
fi
|
||||
|
||||
if ((errori > 0)); then
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
# stessi argomenti e le stesse etichette: la costruzione che si pubblica esce intera dalla cache di quella che si è
|
||||
# provata e scansionata, quindi gli strati sono gli stessi.
|
||||
#
|
||||
# costruisci-immagine.sh builder <registro> il builder buildx dell'esecuzione (BUILDER), con il
|
||||
# driver docker-container e la configurazione di
|
||||
# buildkit che dice che il registro di casa risponde in
|
||||
# HTTP (al posto di docker/setup-buildx-action, un'azione
|
||||
# JavaScript); lo toglie pulizia-docker.sh esecuzione
|
||||
# costruisci-immagine.sh archivio <file.tar> <nome locale> archivio dell'immagine, per docker load e per Trivy
|
||||
# costruisci-immagine.sh pubblica <nome:etichetta>... spinta sul registro da buildx: le credenziali sono
|
||||
# già nella configurazione del client, il demone non
|
||||
@@ -20,10 +25,26 @@
|
||||
# lo controlla PipelineTests.
|
||||
set -euo pipefail
|
||||
|
||||
modo="${1:?Indica il modo: archivio o pubblica.}"
|
||||
modo="${1:?Indica il modo: builder, archivio o pubblica.}"
|
||||
shift
|
||||
cd "$(git rev-parse --show-toplevel)"
|
||||
|
||||
if [[ "$modo" == builder ]]; then
|
||||
registro="${1:?Indica il registro, per esempio 192.168.30.23:3000.}"
|
||||
# Solo un nome di host (o un indirizzo) con la porta: il valore finisce in un file TOML.
|
||||
[[ "$registro" =~ ^[A-Za-z0-9.-]+(:[0-9]+)?$ ]] || { echo "Registro non valido: «$registro»." >&2; exit 2; }
|
||||
configurazione="${RUNNER_TEMP:-/tmp}/buildkitd-${BUILDER:?}.toml"
|
||||
printf '[registry."%s"]\n http = true\n insecure = true\n' "$registro" > "$configurazione"
|
||||
# --buildkitd-config da buildx 0.13; prima si chiamava --config.
|
||||
opzione=--buildkitd-config
|
||||
aiuto=$(docker buildx create --help 2> /dev/null) || true
|
||||
[[ "$aiuto" == *--buildkitd-config* ]] || opzione=--config
|
||||
docker buildx create --name "$BUILDER" --driver docker-container "$opzione" "$configurazione" --bootstrap
|
||||
rm -f "$configurazione"
|
||||
docker buildx inspect "$BUILDER"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
comuni=(--builder "${BUILDER:?}" -f docker/Dockerfile --provenance=false --sbom=false
|
||||
--build-arg "VERSION=${VERSIONE:?}" --build-arg "GIT_COMMIT=${GIT_COMMIT:?}"
|
||||
--label "febe.ci.workflow=${FLUSSO:?}" --label "febe.ci.run=${ESECUZIONE:?}"
|
||||
@@ -47,7 +68,7 @@ case "$modo" in
|
||||
printf 'Pubblicata: %s\n' "$@"
|
||||
;;
|
||||
*)
|
||||
echo "Modo sconosciuto: «$modo» (archivio o pubblica)." >&2
|
||||
echo "Modo sconosciuto: «$modo» (builder, archivio o pubblica)." >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,56 @@
|
||||
# For dotnet.sh, with json.awk: in the release metadata of a .NET channel (releases.json of
|
||||
# builds.dotnet.microsoft.com/dotnet/release-metadata/<channel>/), the newest SDK («latest-sdk») and the address and
|
||||
# SHA-512 of its archive for the rid asked:
|
||||
#
|
||||
# LC_ALL=C awk -v rid=linux-x64 -f json.awk -f dotnet-sdk.awk releases.json
|
||||
#
|
||||
# Prints «<version><TAB><address><TAB><sha512>» and exits with 0, or says why on stderr and exits with 1. The archive
|
||||
# is the file object with that address: https, on one of Microsoft's two hosts of .NET builds, named
|
||||
# dotnet-sdk-<version>-<rid>.tar.gz, with a hash of 128 hexadecimal digits.
|
||||
|
||||
function json_begin(file) {}
|
||||
|
||||
function json_open(kind) {
|
||||
if (kind == "o") {
|
||||
address[json_depth] = ""
|
||||
hash[json_depth] = ""
|
||||
}
|
||||
}
|
||||
|
||||
function json_scalar(kind, value) {
|
||||
if (kind != "s" || json_depth == 0 || json_stack[json_depth] != "o") return
|
||||
if (json_depth == 1 && json_at[1] == "latest-sdk") latest = value
|
||||
if (json_at[json_depth] == "url") address[json_depth] = value
|
||||
if (json_at[json_depth] == "hash") hash[json_depth] = value
|
||||
}
|
||||
|
||||
function json_close(kind) {
|
||||
if (kind == "o" && address[json_depth] != "") sha512[address[json_depth]] = hash[json_depth]
|
||||
}
|
||||
|
||||
function json_end(file, error) {
|
||||
problem = error
|
||||
}
|
||||
|
||||
END {
|
||||
if (problem != "") {
|
||||
print "metadati dei rilasci .NET non validi: " problem > "/dev/stderr"
|
||||
exit 1
|
||||
}
|
||||
if (latest !~ /^[0-9]+[.][0-9]+[.][0-9]+(-[0-9A-Za-z.]+)?$/) {
|
||||
print "nei metadati dei rilasci .NET manca «latest-sdk» o non è una versione: «" substr(latest, 1, 40) "»" > "/dev/stderr"
|
||||
exit 1
|
||||
}
|
||||
name = "dotnet-sdk-" latest "-" rid ".tar.gz"
|
||||
for (candidate in sha512) {
|
||||
if (substr(candidate, length(candidate) - length(name)) != "/" name) continue
|
||||
if (candidate !~ /^https:[/][/](builds[.]dotnet[.]microsoft[.]com|dotnetcli[.]blob[.]core[.]windows[.]net)[/]/) continue
|
||||
if (sha512[candidate] !~ /^[0-9a-fA-F]+$/ || length(sha512[candidate]) != 128) continue
|
||||
found = candidate
|
||||
}
|
||||
if (found == "") {
|
||||
print "nei metadati dei rilasci .NET non c'è l'archivio " name " con la sua impronta" > "/dev/stderr"
|
||||
exit 1
|
||||
}
|
||||
print latest "\t" found "\t" tolower(sha512[found])
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env bash
|
||||
# Installa l'SDK .NET per un lavoro della CI, al posto di actions/setup-dotnet (un'azione JavaScript, che vuole Node).
|
||||
# Come quella prende l'ultimo SDK del canale (predefinito 10.0, come «10.0.x»), ma lo verifica: la versione e
|
||||
# l'impronta SHA-512 dell'archivio vengono dai metadati dei rilasci di Microsoft (letti con json.awk e dotnet-sdk.awk,
|
||||
# awk POSIX), l'archivio da builds.dotnet.microsoft.com, e si installa solo se l'impronta coincide. Mai uno script di
|
||||
# installazione scaricato al volo.
|
||||
#
|
||||
# .gitea/scripts/dotnet.sh [canale]
|
||||
#
|
||||
# Dove: nella cache degli strumenti del runner (RUNNER_TOOL_CACHE, il volume act-toolcache che act_runner monta in ogni
|
||||
# lavoro, anche nei contenitori), in febe-dotnet/<versione>; senza, nella cartella temporanea del lavoro. Una versione
|
||||
# già installata e verificata non si riscarica; le versioni più vecchie di febe-dotnet si tolgono. Aggiunge dotnet al
|
||||
# PATH dei passi seguenti (GITHUB_PATH) e scrive DOTNET_ROOT (GITHUB_ENV); fuori dalla CI stampa solo la cartella.
|
||||
# Serve curl, tar, sha512sum e awk; le librerie di sistema dell'SDK (ICU, OpenSSL) ci sono già nell'immagine del runner
|
||||
# e le installa ambiente-prove.sh nel contenitore Debian delle prove.
|
||||
set -euo pipefail
|
||||
|
||||
canale="${1:-10.0}"
|
||||
[[ "$canale" =~ ^[0-9]+\.[0-9]+$ ]] || { echo "Canale .NET non valido: «$canale» (per esempio 10.0)." >&2; exit 2; }
|
||||
qui="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
case "$(uname -s)-$(uname -m)" in
|
||||
Linux-x86_64) rid=linux-x64 ;;
|
||||
Linux-aarch64) rid=linux-arm64 ;;
|
||||
*) echo "Piattaforma non prevista per l'SDK .NET della CI: $(uname -s)-$(uname -m)." >&2; exit 2 ;;
|
||||
esac
|
||||
|
||||
radice="${RUNNER_TOOL_CACHE:-${RUNNER_TEMP:-/tmp}}/febe-dotnet"
|
||||
mkdir -p "$radice"
|
||||
temporanea="$(mktemp -d "$radice/.scarico-XXXXXX")"
|
||||
trap 'rm -rf "$temporanea"' EXIT
|
||||
|
||||
echo "== SDK .NET $canale"
|
||||
curl -fsSL --retry 3 --retry-delay 5 --max-time 120 -o "$temporanea/releases.json" \
|
||||
"https://builds.dotnet.microsoft.com/dotnet/release-metadata/$canale/releases.json"
|
||||
scelta=$(LC_ALL=C awk -v rid="$rid" -f "$qui/json.awk" -f "$qui/dotnet-sdk.awk" "$temporanea/releases.json")
|
||||
IFS=$'\t' read -r versione indirizzo sha512 <<< "$scelta"
|
||||
[[ "$versione" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$ ]] || { echo "Versione dell'SDK non valida: «$versione»." >&2; exit 1; }
|
||||
[[ "$versione" == "$canale".* ]] || { echo "L'SDK $versione non è del canale $canale." >&2; exit 1; }
|
||||
|
||||
cartella="$radice/$versione"
|
||||
if [[ -x "$cartella/dotnet" && -f "$cartella/.febe-sha512" && "$(cat "$cartella/.febe-sha512")" == "$sha512" ]]; then
|
||||
echo " $versione già installato in $cartella"
|
||||
else
|
||||
echo " $versione da $indirizzo"
|
||||
curl -fsSL --retry 3 --retry-delay 5 --max-time 900 -o "$temporanea/sdk.tar.gz" "$indirizzo"
|
||||
if ! echo "$sha512 $temporanea/sdk.tar.gz" | sha512sum -c --quiet -; then
|
||||
echo "L'impronta SHA-512 dell'SDK $versione non è quella dei metadati di Microsoft: non si installa." >&2
|
||||
exit 1
|
||||
fi
|
||||
mkdir "$temporanea/sdk"
|
||||
tar -xzf "$temporanea/sdk.tar.gz" -C "$temporanea/sdk"
|
||||
echo "$sha512" > "$temporanea/sdk/.febe-sha512"
|
||||
rm -rf "$cartella"
|
||||
mv "$temporanea/sdk" "$cartella"
|
||||
fi
|
||||
|
||||
# Le versioni precedenti, che nessun lavoro userà più (la CI fa un lavoro alla volta), e gli scarichi interrotti.
|
||||
for vecchia in "$radice"/* "$radice"/.scarico-*; do
|
||||
[[ -d "$vecchia" && "$vecchia" != "$cartella" && "$vecchia" != "$temporanea" ]] || continue
|
||||
rm -rf "$vecchia"
|
||||
done
|
||||
|
||||
"$cartella/dotnet" --version
|
||||
if [[ -n "${GITHUB_PATH:-}" ]]; then
|
||||
echo "$cartella" >> "$GITHUB_PATH"
|
||||
echo "DOTNET_ROOT=$cartella" >> "$GITHUB_ENV"
|
||||
else
|
||||
echo "$cartella"
|
||||
fi
|
||||
@@ -0,0 +1,22 @@
|
||||
# Checks that every file named is a valid JSON text (controlli.sh), with json.awk:
|
||||
#
|
||||
# LC_ALL=C awk -f json.awk -f json-valido.awk <file.json>...
|
||||
#
|
||||
# Prints «file: reason» for each file that is not, and on stderr how many were checked; exits with 1 if one is not.
|
||||
function json_begin(file) {}
|
||||
function json_open(kind) {}
|
||||
function json_close(kind) {}
|
||||
function json_scalar(kind, value) {}
|
||||
|
||||
function json_end(file, error) {
|
||||
checked++
|
||||
if (error != "") {
|
||||
print file ": " error
|
||||
broken++
|
||||
}
|
||||
}
|
||||
|
||||
END {
|
||||
printf " %d file controllati\n", checked > "/dev/stderr"
|
||||
exit (broken > 0 ? 1 : 0)
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
# Reader of JSON texts (RFC 8259) for the scripts of the CI, in plain POSIX awk (mawk, gawk, busybox awk): no jq, no
|
||||
# Node. Every file named on the command line is one JSON text. The program that includes this file (awk -f json.awk
|
||||
# -f <program>.awk) defines five hooks, called while a file is read:
|
||||
#
|
||||
# json_begin(file) before the first value of the file
|
||||
# json_open(kind) a container opens: kind "a" (array) or "o" (object); json_depth is now its level (the
|
||||
# root is level 1) and json_stack[d] the kind of the container at level d
|
||||
# json_close(kind) the container at level json_depth closes (json_depth drops after the call)
|
||||
# json_scalar(kind, value) a value that is not a container: kind "s" string (decoded), "n" number (its text), "t"
|
||||
# true, "f" false, "z" null
|
||||
# json_end(file, error) after the file: error is "" for a valid JSON text, otherwise the reason (with the line)
|
||||
#
|
||||
# Where a value is: inside the container at level d it is at json_at[d], its key (object, decoded) or its index from 0
|
||||
# (array). A scalar inside the container at level json_depth is at json_at[json_depth]; at the root json_depth is 0.
|
||||
# After an error the rest of that file is skipped and only json_end follows; an empty file is an error, as for every
|
||||
# JSON parser. The hooks must not call exit: the program records what it needs and decides in its own END, which runs
|
||||
# after the END of this file (it comes first on the command line).
|
||||
#
|
||||
# Run with LC_ALL=C: the text is read as bytes, a leading BOM is skipped and a string may hold any byte from 0x20 on
|
||||
# (UTF-8 is not checked). \uXXXX escapes below 0x80 are decoded; the others stay as they are written, which is enough
|
||||
# for the names, versions, dates and addresses the CI compares. Tokens never span lines in JSON (a string cannot hold a
|
||||
# raw line break), so each line is cut once at the quotes and once at the punctuation: the work grows with the size of
|
||||
# the text, never with its square.
|
||||
|
||||
BEGIN {
|
||||
json_file = ""
|
||||
json_control = "[" sprintf("%c", 1) "-" sprintf("%c", 31) "]"
|
||||
json_escape = "\\\\([\"\\\\/bfnrt]|u[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f])"
|
||||
json_number = "^-?(0|[1-9][0-9]*)([.][0-9]+)?([eE][-+]?[0-9]+)?$"
|
||||
}
|
||||
|
||||
FNR == 1 {
|
||||
if (json_file != "") json_finish()
|
||||
json_start(FILENAME)
|
||||
if (substr($0, 1, 3) == "\357\273\277") $0 = substr($0, 4)
|
||||
}
|
||||
|
||||
{
|
||||
if (json_error == "") json_line($0)
|
||||
}
|
||||
|
||||
END {
|
||||
if (json_file != "") json_finish()
|
||||
for (json_i = 1; json_i < ARGC; json_i++) {
|
||||
json_f = ARGV[json_i]
|
||||
if (json_f == "" || (json_f in json_seen) || json_f ~ /^[A-Za-z_][A-Za-z0-9_]*=/) continue
|
||||
json_start(json_f)
|
||||
json_fail("file vuoto")
|
||||
json_finish()
|
||||
}
|
||||
}
|
||||
|
||||
function json_start(file) {
|
||||
json_file = file
|
||||
json_seen[file] = 1
|
||||
json_depth = 0
|
||||
json_state = "V"
|
||||
json_error = ""
|
||||
json_instring = 0
|
||||
json_buffer = ""
|
||||
json_lineno = 0
|
||||
json_begin(file)
|
||||
}
|
||||
|
||||
function json_finish() {
|
||||
if (json_error == "") {
|
||||
if (json_instring) json_fail("stringa non chiusa")
|
||||
else if (json_state != "E") json_fail(json_depth > 0 || json_state != "V" ? "testo interrotto" : "file vuoto")
|
||||
}
|
||||
json_end(json_file, json_error)
|
||||
json_file = ""
|
||||
}
|
||||
|
||||
function json_fail(message) {
|
||||
if (json_error == "") json_error = (json_lineno > 0 ? "riga " json_lineno ": " : "") message
|
||||
return 0
|
||||
}
|
||||
|
||||
# One line: the parts between quotes alternate between text outside and inside strings, except where a quote is
|
||||
# escaped (an odd number of backslashes before it), which stays in the string.
|
||||
function json_line(line, n, parts, i) {
|
||||
json_lineno = FNR
|
||||
n = split(line, parts, "\"")
|
||||
for (i = 1; i <= n; i++) {
|
||||
if (json_instring) {
|
||||
json_buffer = json_buffer parts[i]
|
||||
if (i == n) return json_fail("stringa non chiusa a fine riga")
|
||||
if (json_escaped(json_buffer)) {
|
||||
json_buffer = json_buffer "\""
|
||||
continue
|
||||
}
|
||||
json_instring = 0
|
||||
json_string(json_buffer)
|
||||
} else {
|
||||
json_plain(parts[i])
|
||||
if (i < n && json_error == "") {
|
||||
json_instring = 1
|
||||
json_buffer = ""
|
||||
}
|
||||
}
|
||||
if (json_error != "") return 0
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
function json_escaped(text) {
|
||||
return match(text, /[\\]+$/) && RLENGTH % 2 == 1
|
||||
}
|
||||
|
||||
# Text outside strings: punctuation, numbers, true, false, null and the four blanks of JSON.
|
||||
function json_plain(text, n, tokens, i) {
|
||||
gsub(/\{/, " { ", text)
|
||||
gsub(/\}/, " } ", text)
|
||||
gsub(/\[/, " [ ", text)
|
||||
gsub(/\]/, " ] ", text)
|
||||
gsub(/,/, " , ", text)
|
||||
gsub(/:/, " : ", text)
|
||||
gsub(/\r/, " ", text)
|
||||
n = split(text, tokens, " ")
|
||||
for (i = 1; i <= n; i++) {
|
||||
json_token(tokens[i])
|
||||
if (json_error != "") return 0
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
function json_token(token, kind) {
|
||||
if (token == "{" || token == "[") {
|
||||
if (json_state != "V" && json_state != "VA") return json_fail("«" token "» inatteso")
|
||||
json_enter()
|
||||
json_depth++
|
||||
json_stack[json_depth] = token == "{" ? "o" : "a"
|
||||
json_index[json_depth] = 0
|
||||
json_at[json_depth] = ""
|
||||
json_state = token == "{" ? "KO" : "VA"
|
||||
json_open(json_stack[json_depth])
|
||||
return 1
|
||||
}
|
||||
if (token == "}" || token == "]") {
|
||||
kind = token == "}" ? "o" : "a"
|
||||
if (json_depth == 0 || json_stack[json_depth] != kind) return json_fail("«" token "» inatteso")
|
||||
if (json_state != "N" && !(kind == "o" && json_state == "KO") && !(kind == "a" && json_state == "VA")) return json_fail("«" token "» inatteso")
|
||||
json_close(kind)
|
||||
json_depth--
|
||||
json_state = json_depth > 0 ? "N" : "E"
|
||||
return 1
|
||||
}
|
||||
if (token == ",") {
|
||||
if (json_state != "N") return json_fail("«,» inattesa")
|
||||
if (json_stack[json_depth] == "o") {
|
||||
json_state = "K"
|
||||
} else {
|
||||
json_index[json_depth]++
|
||||
json_state = "V"
|
||||
}
|
||||
return 1
|
||||
}
|
||||
if (token == ":") {
|
||||
if (json_state != ":") return json_fail("«:» inattesi")
|
||||
json_state = "V"
|
||||
return 1
|
||||
}
|
||||
if (token == "true") kind = "t"
|
||||
else if (token == "false") kind = "f"
|
||||
else if (token == "null") kind = "z"
|
||||
else if (token ~ json_number) kind = "n"
|
||||
else return json_fail("«" substr(token, 1, 20) "» non è un valore JSON")
|
||||
if (json_state != "V" && json_state != "VA") return json_fail("«" substr(token, 1, 20) "» inatteso")
|
||||
json_enter()
|
||||
json_scalar(kind, token)
|
||||
json_state = json_depth > 0 ? "N" : "E"
|
||||
return 1
|
||||
}
|
||||
|
||||
# A whole string, without its quotes: a key or a value.
|
||||
function json_string(raw, rest, value) {
|
||||
if (raw ~ json_control) return json_fail("carattere di controllo in una stringa")
|
||||
rest = raw
|
||||
gsub(json_escape, "", rest)
|
||||
if (index(rest, "\\") > 0) return json_fail("sequenza «\\» non valida in una stringa")
|
||||
value = json_unescape(raw)
|
||||
if (json_state == "K" || json_state == "KO") {
|
||||
json_at[json_depth] = value
|
||||
json_state = ":"
|
||||
return 1
|
||||
}
|
||||
if (json_state != "V" && json_state != "VA") return json_fail("stringa inattesa")
|
||||
json_enter()
|
||||
json_scalar("s", value)
|
||||
json_state = json_depth > 0 ? "N" : "E"
|
||||
return 1
|
||||
}
|
||||
|
||||
# A value starts inside the current container: in an array its place is the running index.
|
||||
function json_enter() {
|
||||
if (json_depth > 0 && json_stack[json_depth] == "a") json_at[json_depth] = json_index[json_depth]
|
||||
}
|
||||
|
||||
function json_unescape(text, out, i, c, code) {
|
||||
if (index(text, "\\") == 0) return text
|
||||
out = ""
|
||||
while ((i = index(text, "\\")) > 0) {
|
||||
out = out substr(text, 1, i - 1)
|
||||
c = substr(text, i + 1, 1)
|
||||
if (c == "u") {
|
||||
code = json_hex(substr(text, i + 2, 4))
|
||||
out = out (code > 0 && code < 128 ? sprintf("%c", code) : "\\u" substr(text, i + 2, 4))
|
||||
text = substr(text, i + 6)
|
||||
} else {
|
||||
if (c == "b") c = "\b"
|
||||
else if (c == "f") c = "\f"
|
||||
else if (c == "n") c = "\n"
|
||||
else if (c == "r") c = "\r"
|
||||
else if (c == "t") c = "\t"
|
||||
out = out c
|
||||
text = substr(text, i + 2)
|
||||
}
|
||||
}
|
||||
return out text
|
||||
}
|
||||
|
||||
function json_hex(digits, value, i) {
|
||||
value = 0
|
||||
for (i = 1; i <= length(digits); i++) value = value * 16 + index("0123456789abcdef", tolower(substr(digits, i, 1))) - 1
|
||||
return value
|
||||
}
|
||||
@@ -36,8 +36,9 @@
|
||||
# stretta di prima del 21 ottobre 2026, ora solo a mano
|
||||
# pulizia-docker.sh completa residui, febe:ci, resti di act_runner, le immagini che nessun contenitore
|
||||
# usa create più di 24 ore fa, la cache di costruzione non usata da 24 ore e,
|
||||
# con REGISTRY_TOKEN, le etichette sha- del registro oltre le 10 più recenti
|
||||
# (flusso «pulizia», ogni lunedì e a mano)
|
||||
# con REGISTRY_TOKEN, le etichette sha- del registro oltre le 10 più recenti e
|
||||
# gli artefatti della CI (febe-ci) di più di 14 giorni (flusso «pulizia», ogni
|
||||
# lunedì e a mano)
|
||||
# pulizia-docker.sh <modo> --prova elenca che cosa toglierebbe e non toglie nulla: solo comandi che leggono
|
||||
# (sul registro solo GET)
|
||||
#
|
||||
@@ -49,7 +50,8 @@
|
||||
# il filtro delle 24 ore; mai un contenitore, un volume o una rete che non sia della CI. Le immagini le toglie Docker
|
||||
# stesso (image prune), che non toglie mai un'immagine usata da un contenitore, nemmeno fermo; con -a, però, le toglie i
|
||||
# nomi in più, e lo script li scrive (nella prova li stima, secondo lo store). Sul registro mai main, latest o una
|
||||
# versione X.Y.Z: solo le etichette sha-<esadecimale> della verifica.
|
||||
# versione X.Y.Z: solo le etichette sha-<esadecimale> della verifica e gli artefatti <x.y.z>-ci.<n> e
|
||||
# <x.y.z>-rilascio.<n> del pacchetto generico febe-ci.
|
||||
#
|
||||
# Nei modi «residui», «settimanale» e «completa» un contenitore di prova si toglie solo se è fermo. Uno ancora acceso
|
||||
# dopo 90 minuti (il suo lavoro è stato ucciso proprio durante la prova del contenitore) resta dov'è: lo si segnala, con
|
||||
@@ -63,7 +65,7 @@
|
||||
#
|
||||
# Variabili per il registro (modo «completa»): REGISTRY_TOKEN (token con «package: read and write», mai stampato),
|
||||
# GITEA_API (l'API del server, per esempio https://gitea.example/api/v1) e PROPRIETARIO (il proprietario del pacchetto
|
||||
# febe). La scelta delle versioni da togliere sta in versioni-registro.js, accanto a questo script.
|
||||
# febe). La scelta delle versioni da togliere sta in versioni-registro.sh, accanto a questo script.
|
||||
set -uo pipefail
|
||||
|
||||
uso() {
|
||||
@@ -103,9 +105,9 @@ tipi=()
|
||||
note=()
|
||||
|
||||
# La cache di costruzione che si pota è quella del builder del demone, «default». docker builder è un alias di docker
|
||||
# buildx quando c'è il plugin, e buildx lavora sul builder corrente: nel lavoro «immagine» è quello dell'esecuzione
|
||||
# (setup-buildx-action lo crea con --use), che il modo «esecuzione» ha appena tolto. Gli altri comandi buildx di questo
|
||||
# script indicano il builder per nome.
|
||||
# buildx quando c'è il plugin, e buildx lavora sul builder corrente: se qualcuno avesse reso corrente il builder
|
||||
# dell'esecuzione (costruisci-immagine.sh builder non lo fa), il modo «esecuzione» l'avrebbe appena tolto. Gli altri
|
||||
# comandi buildx di questo script indicano il builder per nome.
|
||||
export BUILDX_BUILDER=default
|
||||
|
||||
avviso() {
|
||||
@@ -693,11 +695,16 @@ spiega() {
|
||||
# ne arriva una vuota (il server può darne
|
||||
# meno di 50 per pagina)
|
||||
# DELETE /api/v1/packages/{proprietario}/container/febe/{versione} una versione (risponde 204)
|
||||
# Quali togliere lo sceglie versioni-registro.js; qui si ricontrolla la forma sha-<esadecimale> prima di ogni DELETE.
|
||||
# Ogni rifiuto dell'API è un avviso che non fa diventare rosso il lavoro. Le versioni sha256:… senza etichetta (i
|
||||
# Quali togliere lo sceglie versioni-registro.sh (awk POSIX con json.awk: niente Node, niente jq); qui si ricontrolla
|
||||
# la forma sha-<esadecimale> prima di ogni DELETE. Ogni rifiuto dell'API è un avviso che non fa diventare rosso il
|
||||
# lavoro, e dopo un rifiuto il registro non si tocca più (il token è lo stesso). Le versioni sha256:… senza etichetta (i
|
||||
# manifest figli di un indice, con gli strati) non si toccano mai: l'API non dice se un'etichetta le usa ancora. Si
|
||||
# dice solo quante sono; la CI pubblica manifest semplici (costruisci-immagine.sh), quindi non dovrebbero essercene, e
|
||||
# quelle che nessuna etichetta usa le toglie una regola di pulizia di Gitea (docs/processo.md, «Registro dei container»).
|
||||
# Poi gli artefatti della CI (artefatti.sh): le versioni del pacchetto generico febe-ci create più di 14 giorni fa,
|
||||
# GET /api/v1/packages/{proprietario}/generic/febe-ci?page=N&limit=50
|
||||
# DELETE /api/v1/packages/{proprietario}/generic/febe-ci/{versione} la versione con i suoi file (204)
|
||||
# solo con la forma <x.y.z>-ci.<n> o <x.y.z>-rilascio.<n>, ricontrollata prima di ogni DELETE.
|
||||
registro() {
|
||||
local tenere=10
|
||||
echo "== Registro: le etichette sha- del pacchetto febe oltre le $tenere più recenti"
|
||||
@@ -710,40 +717,58 @@ registro() {
|
||||
return 0
|
||||
fi
|
||||
local programma
|
||||
for programma in curl node; do
|
||||
for programma in curl awk sort; do
|
||||
command -v "$programma" > /dev/null || { segnala "Manca $programma: il registro non si tocca."; return 0; }
|
||||
done
|
||||
local base="${GITEA_API%/}/packages/$PROPRIETARIO/container/febe" cartella pagina codice scelte
|
||||
local base="${GITEA_API%/}/packages/$PROPRIETARIO/container/febe" cartella codice scelte esito
|
||||
cartella=$(mktemp -d) || { segnala "Non riesco a creare una cartella temporanea: il registro non si tocca."; return 0; }
|
||||
for ((pagina = 1; ; pagina++)); do
|
||||
if ((pagina > 200)); then
|
||||
segnala "Più di 200 pagine di versioni sul registro: il registro non si tocca."
|
||||
rm -rf "$cartella"
|
||||
return 0
|
||||
fi
|
||||
codice=$(chiedi GET "$base?page=$pagina&limit=50" "$cartella/pagina-$pagina.json")
|
||||
if [[ "$codice" == 404 && "$pagina" == 1 ]]; then
|
||||
echo " Il pacchetto febe non è ancora sul registro: niente da togliere."
|
||||
rm -rf "$cartella"
|
||||
return 0
|
||||
fi
|
||||
if [[ "$codice" != 200 ]]; then
|
||||
segnala "L'API dei pacchetti di Gitea risponde $(spiega "$codice") alla pagina $pagina delle versioni: il registro non si tocca."
|
||||
rm -rf "$cartella"
|
||||
return 0
|
||||
fi
|
||||
case "$(tr -d '[:space:]' < "$cartella/pagina-$pagina.json")" in
|
||||
"[]" | null) break ;;
|
||||
esac
|
||||
done
|
||||
local senza_etichetta quante
|
||||
if ! scelte=$(node "$cartella_script/versioni-registro.js" "$tenere" "$cartella"/pagina-*.json) \
|
||||
|| ! senza_etichetta=$(node "$cartella_script/versioni-registro.js" senza-etichetta "$cartella"/pagina-*.json); then
|
||||
segnala "Non riesco a leggere le versioni del pacchetto febe: il registro non si tocca."
|
||||
esito=0
|
||||
pagine "$base" "$cartella" febe || esito=$?
|
||||
if ((esito == 2)); then
|
||||
rm -rf "$cartella"
|
||||
return 0
|
||||
fi
|
||||
if ((esito == 1)); then
|
||||
echo " Il pacchetto febe non è ancora sul registro: niente da togliere."
|
||||
else
|
||||
contenitore "$base" "$cartella"
|
||||
fi
|
||||
rm -rf "$cartella"
|
||||
artefatti_della_ci
|
||||
}
|
||||
|
||||
# Le pagine delle versioni di un pacchetto nella cartella, pagina-<n>.json, fino alla prima vuota (il server può darne
|
||||
# meno di 50 per pagina). Esce con 0 se le ha lette, 1 se il pacchetto non c'è (404 alla prima pagina), 2 se l'API
|
||||
# rifiuta (e lo segnala).
|
||||
pagine() {
|
||||
local base="$1" cartella="$2" nome="$3" pagina codice
|
||||
for ((pagina = 1; ; pagina++)); do
|
||||
if ((pagina > 200)); then
|
||||
segnala "Più di 200 pagine di versioni di $nome sul registro: il registro non si tocca."
|
||||
return 2
|
||||
fi
|
||||
codice=$(chiedi GET "$base?page=$pagina&limit=50" "$cartella/pagina-$pagina.json")
|
||||
if [[ "$codice" == 404 && "$pagina" == 1 ]]; then
|
||||
return 1
|
||||
fi
|
||||
if [[ "$codice" != 200 ]]; then
|
||||
segnala "L'API dei pacchetti di Gitea risponde $(spiega "$codice") alla pagina $pagina delle versioni di $nome: il registro non si tocca."
|
||||
return 2
|
||||
fi
|
||||
case "$(tr -d '[:space:]' < "$cartella/pagina-$pagina.json")" in
|
||||
"[]" | null) return 0 ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Le etichette sha- del contenitore febe, dalle pagine già lette.
|
||||
contenitore() {
|
||||
local base="$1" cartella="$2" scelte senza_etichetta quante codice
|
||||
if ! scelte=$(bash "$cartella_script/versioni-registro.sh" "$tenere" "$cartella"/pagina-*.json) \
|
||||
|| ! senza_etichetta=$(bash "$cartella_script/versioni-registro.sh" senza-etichetta "$cartella"/pagina-*.json); then
|
||||
segnala "Non riesco a leggere le versioni del pacchetto febe: il registro non si tocca."
|
||||
return 0
|
||||
fi
|
||||
quante=$(grep -c . <<< "$senza_etichetta")
|
||||
if ((quante > 0)); then
|
||||
echo " $quante versioni senza etichetta (sha256:…, i manifest di un indice con i loro strati): restano, questa pulizia non le tocca mai (docs/processo.md, «Registro dei container»)"
|
||||
@@ -775,6 +800,47 @@ registro() {
|
||||
done <<< "$scelte"
|
||||
}
|
||||
|
||||
# Gli artefatti della CI (artefatti.sh): le versioni del pacchetto generico febe-ci create più di 14 giorni fa, come la
|
||||
# scadenza degli artefatti di una volta.
|
||||
artefatti_della_ci() {
|
||||
local giorni=14 base="${GITEA_API%/}/packages/$PROPRIETARIO/generic/febe-ci" cartella esito scelte versione creata codice
|
||||
echo "== Registro: gli artefatti della CI (pacchetto febe-ci) creati più di $giorni giorni fa"
|
||||
cartella=$(mktemp -d) || { segnala "Non riesco a creare una cartella temporanea: gli artefatti restano."; return 0; }
|
||||
esito=0
|
||||
pagine "$base" "$cartella" febe-ci || esito=$?
|
||||
if ((esito == 1)); then
|
||||
echo " Il pacchetto febe-ci non è ancora sul registro: niente da togliere."
|
||||
elif ((esito == 0)) && ! scelte=$(bash "$cartella_script/versioni-registro.sh" scadute "$giorni" "$(date +%s)" "$cartella"/pagina-*.json); then
|
||||
segnala "Non riesco a leggere le versioni del pacchetto febe-ci: gli artefatti restano."
|
||||
esito=3
|
||||
fi
|
||||
rm -rf "$cartella"
|
||||
((esito == 0)) || return 0
|
||||
if [[ -z "${scelte:-}" ]]; then
|
||||
echo " niente da togliere"
|
||||
return 0
|
||||
fi
|
||||
while IFS=$'\t' read -r versione creata; do
|
||||
[[ -n "${versione:-}" ]] || continue
|
||||
if [[ ! "$versione" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?-(ci|rilascio)\.[0-9]+$ ]]; then
|
||||
segnala "Versione inattesa «$versione» fra gli artefatti da togliere: resta."
|
||||
continue
|
||||
fi
|
||||
if ((prova)); then
|
||||
echo " toglierei febe-ci $versione (caricata il $creata)"
|
||||
conta "artefatti della CI sul registro"
|
||||
continue
|
||||
fi
|
||||
codice=$(chiedi DELETE "$base/$versione" /dev/null)
|
||||
if [[ "$codice" == 204 ]]; then
|
||||
echo " febe-ci $versione tolta (caricata il $creata)"
|
||||
conta "artefatti della CI sul registro"
|
||||
else
|
||||
segnala "Non riesco a togliere febe-ci $versione dal registro: l'API risponde $(spiega "$codice")."
|
||||
fi
|
||||
done <<< "$scelte"
|
||||
}
|
||||
|
||||
# La cache con lo stesso limite del lunedì: senza, a ogni push di ogni ramo se ne andrebbero gli strati intermedi e le
|
||||
# cache montate (RUN --mount=type=cache) che le costruzioni degli altri progetti hanno appena usato.
|
||||
penzolanti() {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
# .gitea/scripts/riepilogo-prove.sh <cartella dei .trx> [saltate ammesse]
|
||||
#
|
||||
# Esce con 1 se una prova è fallita, se le saltate sono più di quelle ammesse (predefinito 0: nella CI ci sono
|
||||
# Chromium, Xvfb, ffmpeg e Node, quindi nessuna prova ha motivo di saltarsi) o se non c'è nessun risultato.
|
||||
# Chromium, Xvfb e ffmpeg, quindi nessuna prova ha motivo di saltarsi) o se non c'è nessun risultato.
|
||||
set -euo pipefail
|
||||
|
||||
cartella="${1:?Indica la cartella con i file .trx.}"
|
||||
@@ -96,7 +96,7 @@ if (( fallite_totali > 0 )); then
|
||||
esito=1
|
||||
fi
|
||||
if (( saltate_totali > ammesse )); then
|
||||
echo "Prove saltate: $saltate_totali, più delle $ammesse ammesse. Qui ci sono Chromium, Xvfb, ffmpeg e Node: una prova che si salta segnala un ambiente rotto, non una prova superata." >&2
|
||||
echo "Prove saltate: $saltate_totali, più delle $ammesse ammesse. Qui ci sono Chromium, Xvfb e ffmpeg: una prova che si salta segnala un ambiente rotto, non una prova superata." >&2
|
||||
esito=1
|
||||
fi
|
||||
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
# For versioni-registro.sh, with json.awk: the versions of one package of Gitea's registry in the pages of
|
||||
# GET /api/v1/packages/{owner}/{type}/{name} of Gitea 28, given as files:
|
||||
#
|
||||
# LC_ALL=C awk -v tipo=container -v nome=febe -f json.awk -f versioni-registro.awk <page.json>...
|
||||
#
|
||||
# A page is a list of versions with «type», «name», «version», «created_at» and «id»; an empty page may be «[]» or
|
||||
# «null». Only the versions whose type and name are those asked count, and a version found in two pages counts once
|
||||
# (the last one read wins, in the place of the first). For each it prints, in the order first met:
|
||||
#
|
||||
# <milliseconds since 1970 UTC, or «-» when created_at is not a date that can be read><TAB><id><TAB><order>
|
||||
# <TAB><version><TAB><created_at as written>
|
||||
#
|
||||
# created_at is read as ISO 8601 / RFC 3339 like JavaScript's Date.parse: a date, or a date and time with «Z» or an
|
||||
# offset (+02:00), seconds and fractions optional. A time without a zone is local time for JavaScript and would depend
|
||||
# on the machine: here it is not a date, and in doubt nothing is removed. If a file is not JSON, or not a list (nor
|
||||
# null), it prints nothing, says why on stderr and exits with 2.
|
||||
|
||||
function json_begin(file) {
|
||||
root = ""
|
||||
inside = 0
|
||||
}
|
||||
|
||||
function json_open(kind) {
|
||||
if (json_depth == 1) {
|
||||
root = kind
|
||||
} else if (json_depth == 2 && root == "a" && kind == "o") {
|
||||
inside = 1
|
||||
split("", field)
|
||||
split("", seen)
|
||||
}
|
||||
}
|
||||
|
||||
function json_scalar(kind, value) {
|
||||
if (json_depth == 0) {
|
||||
root = kind == "z" ? "null" : "valore"
|
||||
} else if (json_depth == 2 && inside) {
|
||||
field[json_at[2]] = value
|
||||
seen[json_at[2]] = kind
|
||||
}
|
||||
}
|
||||
|
||||
function json_close(kind) {
|
||||
if (json_depth == 2 && inside) {
|
||||
inside = 0
|
||||
keep()
|
||||
}
|
||||
}
|
||||
|
||||
function json_end(file, error) {
|
||||
if (error != "") {
|
||||
problems = problems file ": " error "\n"
|
||||
} else if (root != "a" && root != "null") {
|
||||
problems = problems file ": non è un elenco di versioni\n"
|
||||
}
|
||||
}
|
||||
|
||||
function keep( version, created, id) {
|
||||
if (seen["type"] != "s" || field["type"] != tipo || seen["name"] != "s" || field["name"] != nome) return
|
||||
if (seen["version"] != "s") return
|
||||
version = field["version"]
|
||||
if (version ~ control) return
|
||||
if (!("created_at" in seen)) created = "undefined"
|
||||
else if (seen["created_at"] == "z") created = "null"
|
||||
else if (seen["created_at"] == "t") created = "true"
|
||||
else if (seen["created_at"] == "f") created = "false"
|
||||
else created = field["created_at"]
|
||||
gsub(control, "?", created)
|
||||
id = 0
|
||||
if (seen["id"] == "n" || (seen["id"] == "s" && field["id"] ~ /^[0-9]+$/)) id = field["id"] + 0
|
||||
if (!(version in order)) order[version] = ++count
|
||||
when[version] = seen["created_at"] == "s" ? milliseconds(field["created_at"]) : ""
|
||||
number[version] = id
|
||||
written[version] = created
|
||||
}
|
||||
|
||||
# Milliseconds since 1970 UTC of an ISO 8601 date as Date.parse reads it, or "" if it is not one.
|
||||
function milliseconds(text, y, mo, d, h, mi, s, ms, rest, offset, fraction) {
|
||||
if (text !~ /^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/) return ""
|
||||
y = substr(text, 1, 4) + 0
|
||||
mo = substr(text, 6, 2) + 0
|
||||
d = substr(text, 9, 2) + 0
|
||||
h = mi = s = ms = offset = 0
|
||||
rest = substr(text, 11)
|
||||
if (rest != "") {
|
||||
if (rest !~ /^T[0-9][0-9]:[0-9][0-9]/) return ""
|
||||
h = substr(rest, 2, 2) + 0
|
||||
mi = substr(rest, 5, 2) + 0
|
||||
rest = substr(rest, 7)
|
||||
if (rest ~ /^:[0-9][0-9]/) {
|
||||
s = substr(rest, 2, 2) + 0
|
||||
rest = substr(rest, 4)
|
||||
if (match(rest, /^[.][0-9]+/)) {
|
||||
fraction = substr(rest, 2, RLENGTH - 1) "00"
|
||||
ms = substr(fraction, 1, 3) + 0
|
||||
rest = substr(rest, RLENGTH + 1)
|
||||
}
|
||||
}
|
||||
if (rest == "Z") offset = 0
|
||||
else if (rest ~ /^[-+][0-9][0-9]:[0-9][0-9]$/) {
|
||||
offset = substr(rest, 2, 2) * 60 + substr(rest, 5, 2)
|
||||
if (substr(rest, 2, 2) + 0 > 23 || substr(rest, 5, 2) + 0 > 59) return ""
|
||||
if (substr(rest, 1, 1) == "-") offset = -offset
|
||||
} else return ""
|
||||
}
|
||||
if (mo < 1 || mo > 12 || d < 1 || d > days_in_month(y, mo)) return ""
|
||||
if (h > 24 || mi > 59 || s > 59 || (h == 24 && (mi > 0 || s > 0 || ms > 0))) return ""
|
||||
return ((days_from_civil(y, mo, d) * 86400 + h * 3600 + mi * 60 + s - offset * 60) * 1000 + ms)
|
||||
}
|
||||
|
||||
function leap(y) {
|
||||
return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0
|
||||
}
|
||||
|
||||
function days_in_month(y, m) {
|
||||
if (m == 2) return leap(y) ? 29 : 28
|
||||
return (m == 4 || m == 6 || m == 9 || m == 11) ? 30 : 31
|
||||
}
|
||||
|
||||
# Days from 1970-01-01 to a date of the proleptic Gregorian calendar (years 0 to 9999 here).
|
||||
function days_from_civil(y, m, d, era, yoe, doy, doe) {
|
||||
if (m <= 2) y--
|
||||
era = int(y / 400)
|
||||
if (y < 0 && y % 400 != 0) era--
|
||||
yoe = y - era * 400
|
||||
doy = int((153 * (m > 2 ? m - 3 : m + 9) + 2) / 5) + d - 1
|
||||
doe = yoe * 365 + int(yoe / 4) - int(yoe / 100) + doy
|
||||
return era * 146097 + doe - 719468
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
control = "[" sprintf("%c", 1) "-" sprintf("%c", 31) "]"
|
||||
if (tipo == "" || nome == "") {
|
||||
print "versioni-registro.awk: servono -v tipo=… -v nome=…" > "/dev/stderr"
|
||||
failed = 1
|
||||
exit 2
|
||||
}
|
||||
}
|
||||
|
||||
END {
|
||||
if (failed) exit 2
|
||||
if (problems != "") {
|
||||
printf "%s", problems > "/dev/stderr"
|
||||
exit 2
|
||||
}
|
||||
for (version in order) {
|
||||
printf "%s\t%.0f\t%d\t%s\t%s\n", when[version] == "" ? "-" : sprintf("%.0f", when[version]), number[version], order[version], version, written[version]
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
"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/febe 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 «febe» 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 === "febe" && 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`);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env bash
|
||||
# Sceglie le versioni da togliere dal registro dei pacchetti di Gitea (pulizia-docker.sh, modo «completa»). Legge solo
|
||||
# i file che riceve, con json.awk e versioni-registro.awk (awk POSIX: niente jq, niente Node): niente rete, niente
|
||||
# scritture, quindi si prova con un file JSON (PipelineTests).
|
||||
#
|
||||
# versioni-registro.sh <quante tenere> <pagina.json>... le etichette sha-<da 7 a 40 cifre esadecimali>
|
||||
# del contenitore febe oltre le N più recenti
|
||||
# versioni-registro.sh senza-etichetta <pagina.json>... le versioni sha256:<64 cifre> del contenitore
|
||||
# febe (i manifest di un indice: solo da contare)
|
||||
# versioni-registro.sh scadute <giorni> <adesso> <pagina.json>... le versioni <x.y.z>-ci.<n> e
|
||||
# <x.y.z>-rilascio.<n> del pacchetto generico
|
||||
# febe-ci (gli artefatti della CI, artefatti.sh)
|
||||
# create più di <giorni> giorni prima di <adesso>,
|
||||
# in secondi dal 1970
|
||||
#
|
||||
# Ogni pagina è una risposta di GET /api/v1/packages/{proprietario}/{tipo}/{nome} di Gitea 28. Stampa, dalla più
|
||||
# vecchia e una per riga, «versione<TAB>creata». Tutto il resto resta sempre: main, latest, le versioni X.Y.Z (anche
|
||||
# X.Y.Z-rc.N), i digest, ogni altra etichetta, una sha- o un artefatto senza una data che si legga. Fra le sha- contano
|
||||
# le date, non il testo; a parità di data l'identificativo. Se un file non è un elenco JSON esce con 2 e non stampa
|
||||
# nulla: nel dubbio non si toglie niente.
|
||||
set -euo pipefail
|
||||
|
||||
qui="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
uso() {
|
||||
echo "Uso: versioni-registro.sh <quante tenere> | senza-etichetta | scadute <giorni> <adesso> <pagina.json>..." >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
modo="${1:-}"
|
||||
(($# > 0)) && shift
|
||||
case "$modo" in
|
||||
senza-etichetta) tipo=container nome=febe ;;
|
||||
scadute)
|
||||
(($# >= 2)) || uso
|
||||
giorni="$1" adesso="$2"
|
||||
shift 2
|
||||
[[ "$giorni" =~ ^[0-9]{1,5}$ && "$adesso" =~ ^[0-9]{1,12}$ ]] || uso
|
||||
tipo=generic nome=febe-ci
|
||||
;;
|
||||
*)
|
||||
[[ "$modo" =~ ^[0-9]{1,6}$ ]] || uso
|
||||
tipo=container nome=febe
|
||||
;;
|
||||
esac
|
||||
(($# > 0)) || uso
|
||||
|
||||
export LC_ALL=C
|
||||
tab=$'\t'
|
||||
versioni=$(awk -v tipo="$tipo" -v nome="$nome" -f "$qui/json.awk" -f "$qui/versioni-registro.awk" "$@") || exit 2
|
||||
|
||||
# Righe: millisecondi (o «-»), identificativo, ordine, versione, data come scritta.
|
||||
case "$modo" in
|
||||
senza-etichetta)
|
||||
awk -F "$tab" -v OFS="$tab" '$4 ~ /^sha256:[0-9a-f]+$/ && length($4) == 71 { if ($1 == "-") $1 = 0; print }' <<< "$versioni" \
|
||||
| sort -t "$tab" -k1,1n -k2,2n -k3,3n | cut -f4,5
|
||||
;;
|
||||
scadute)
|
||||
awk -F "$tab" -v limite="$(((adesso - giorni * 86400) * 1000))" \
|
||||
'$1 != "-" && $1 + 0 < limite + 0 && $4 ~ /^[0-9]+[.][0-9]+[.][0-9]+(-[0-9A-Za-z.-]+)?-(ci|rilascio)[.][0-9]+$/' <<< "$versioni" \
|
||||
| sort -t "$tab" -k1,1n -k2,2n -k3,3n | cut -f4,5
|
||||
;;
|
||||
*)
|
||||
# Le più recenti prima (data, poi identificativo), si saltano le prime N, il resto dalla più vecchia.
|
||||
awk -F "$tab" '$1 != "-" && $4 ~ /^sha-[0-9a-f]+$/ && length($4) >= 11 && length($4) <= 44' <<< "$versioni" \
|
||||
| sort -t "$tab" -k1,1nr -k2,2nr -k3,3n | tail -n "+$((modo + 1))" \
|
||||
| awk '{ righe[NR] = $0 } END { for (i = NR; i > 0; i--) print righe[i] }' | cut -f4,5
|
||||
;;
|
||||
esac
|
||||
Reference in new issue
Block a user