Files
Febe/.gitea/scripts/artefatti.sh
T
Alby96andClaude Opus 5.5 009e7d6710 CI e installatore: commenti degli script in inglese (#43)
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>
2026-11-29 12:03:13 +01:00

68 lines
3.4 KiB
Bash

#!/usr/bin/env bash
# CI artifacts, instead of actions/upload-artifact (a JavaScript action, which needs Node): the files go to the Gitea
# package registry, generic package febe-ci, one version per run:
#
# <versione>-ci.<numero> from the verifica workflow (like Febe-Setup-<versione>-ci.<numero>.exe)
# <versione>-rilascio.<numero> from the rilascio workflow
#
# with <versione> from Directory.Build.props and <numero> the run number (NUMERO). They are downloaded from the package
# page on Gitea (owner ▸ Packages ▸ febe-ci). The Monday cleanup (full pulizia-docker.sh) removes the versions created
# more than 14 days earlier, as the artifact expiry used to do.
#
# .gitea/scripts/artefatti.sh verifica|rilascio <file>...
#
# Variables: REGISTRY_TOKEN (token with «package: read and write», only in the curl header, never printed), GITEA_URL
# (the server address, gitea.server_url), PROPRIETARIO, NUMERO. Without REGISTRY_TOKEN a warning and no file uploaded:
# the job stays green, as for the image. A missing file or a refusal by the registry fails the step. A file with the
# same name already uploaded (a new attempt of the same run) is replaced.
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"
# One call to the registry: the HTTP code, 000 if Gitea does not answer. The token is only in the curl header.
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"