La regola del progetto è «codice e commenti in inglese; interfaccia, documenti e messaggi in italiano», e gli script di .gitea/ (script e flussi), di installer/ e docker/entrypoint.sh avevano ancora i commenti in italiano (decisione di Alberto del 29 novembre 2026). Cambiano solo i commenti: i messaggi che una persona legge (echo, ::warning::, ::error::, nomi dei passi, note della release) restano in italiano e nessun comando cambia. I programmi awk e gli script finti delle prove erano già in inglese. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
70 lines
3.5 KiB
Bash
70 lines
3.5 KiB
Bash
#!/usr/bin/env bash
|
|
# Chooses the versions to remove from Gitea's package registry (pulizia-docker.sh, «completa» mode). It reads only the
|
|
# files it is given, with json.awk and versioni-registro.awk (POSIX awk: no jq, no Node): no network, no writes, so it
|
|
# is tested with a JSON file (PipelineTests).
|
|
#
|
|
# versioni-registro.sh <quante tenere> <pagina.json>... the sha-<7 to 40 hexadecimal digits> tags of
|
|
# the febe container beyond the N most recent
|
|
# versioni-registro.sh senza-etichetta <pagina.json>... the sha256:<64 digits> versions of the febe
|
|
# container (the manifests of an index: only to
|
|
# be counted)
|
|
# versioni-registro.sh scadute <giorni> <adesso> <pagina.json>... the <x.y.z>-ci.<n> and <x.y.z>-rilascio.<n>
|
|
# versions of the generic febe-ci package (the CI
|
|
# artifacts, artefatti.sh) created more than
|
|
# <giorni> days before <adesso>, in seconds since
|
|
# 1970
|
|
#
|
|
# Each page is a response of GET /api/v1/packages/{owner}/{type}/{name} of Gitea 28. Prints, oldest first and one per
|
|
# line, «version<TAB>created». Everything else always stays: main, latest, the X.Y.Z versions (also X.Y.Z-rc.N), the
|
|
# digests, every other tag, a sha- tag or an artifact without a readable date. Among the sha- tags the dates count,
|
|
# not the text; with equal dates the identifier. If a file is not a JSON list it exits with 2 and prints nothing: when
|
|
# in doubt nothing is removed.
|
|
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
|
|
|
|
# Lines: milliseconds (or «-»), identifier, order, version, date as written.
|
|
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
|
|
;;
|
|
*)
|
|
# The most recent first (date, then identifier), the first N are skipped, the rest from the oldest.
|
|
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
|