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>
This commit is contained in:
1 parent
ef30e5563e
commit
bddb624f5e
22 files changed
+1785
-19
No files matched your search
@@ -0,0 +1,53 @@
|
||||
# Pulizia notturna (alle 4:47, ora del server di Gitea) e a mano (Actions ▸ pulizia ▸ Esegui) di ciò che la CI di
|
||||
# Mimante lascia: contenitori, reti, nomi locali e builder delle esecuzioni interrotte, ed etichette sha- del pacchetto
|
||||
# mimante oltre le 10 più recenti (mai main, latest o X.Y.Z). A mano, con «Solo prova», elenca e non toglie nulla.
|
||||
# Il resto del demone Docker di Unraid (immagini senza nome, cache di tutti i progetti, resti di act_runner) lo pulisce
|
||||
# la pulizia di Febe: qui non si tocca nulla che non porti i segni della CI di Mimante (pulizia-docker.sh).
|
||||
name: pulizia
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "47 4 * * *"
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
prova:
|
||||
description: "Solo prova: elenca che cosa toglierebbe e non toglie nulla"
|
||||
type: boolean
|
||||
required: false
|
||||
default: false
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
concurrency:
|
||||
group: pulizia
|
||||
cancel-in-progress: false
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 20
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
# Gitea mette nell'evento la casella «prova» come testo, "true" o "false"; di notte l'evento non ha input. Il token
|
||||
# del registro va solo nell'ambiente di questo passo e non si stampa mai.
|
||||
- name: Resti della CI e registro
|
||||
env:
|
||||
PROVA: ${{ gitea.event.inputs.prova }}
|
||||
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||
GITEA_API: ${{ gitea.server_url }}/api/v1
|
||||
PROPRIETARIO: ${{ gitea.repository_owner }}
|
||||
run: |
|
||||
case "${PROVA:-}" in
|
||||
true) bash .gitea/scripts/pulizia-docker.sh completa --prova ;;
|
||||
"" | false) bash .gitea/scripts/pulizia-docker.sh completa ;;
|
||||
*)
|
||||
echo "::error::La casella «prova» vale true o false: non tolgo nulla."
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,261 @@
|
||||
# Rilascio a ogni tag vX.Y.Z (vX.Y.Z-rc.N per una prova del rilascio):
|
||||
# 1. prove: il tag coincide con <Version> di Directory.Build.props (la parte prima del trattino per un rc), la
|
||||
# soluzione si compila con gli avvisi come errori e tutte le prove passano, anche quelle su PostgreSQL;
|
||||
# 2. immagine: costruita, provata su una rete interna e scansionata come nella verifica, poi pubblicata come
|
||||
# <registro>/<proprietario>/mimante:X.Y.Z e :latest. Un tag con il trattino pubblica solo :X.Y.Z-rc.N: :latest
|
||||
# non si sposta. Alla fine toglie sempre ciò che ha creato;
|
||||
# 3. release: solo dopo prove e immagine. Crea la release (o ne aggiorna le note) con la sezione del CHANGELOG e il
|
||||
# modello Unraid mimante-unraid-X.Y.Z.xml; un rc è una pre-release.
|
||||
#
|
||||
# Segreto (del repository o dell'utente): REGISTRY_TOKEN, token di Gitea con «package» e «repository» in lettura e
|
||||
# scrittura. Senza, l'immagine si costruisce e si prova ma non si pubblica, e le note lo dicono.
|
||||
# Variabile facoltativa: REGISTRY (per esempio 192.168.30.23:3000); se manca, l'host dell'indirizzo del server.
|
||||
name: rilascio
|
||||
|
||||
on:
|
||||
push:
|
||||
tags: ["v*"]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
env:
|
||||
DOTNET_NOLOGO: "1"
|
||||
DOTNET_CLI_TELEMETRY_OPTOUT: "1"
|
||||
|
||||
jobs:
|
||||
prove:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
container:
|
||||
image: node:24-trixie
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:18
|
||||
env:
|
||||
POSTGRES_USER: admin
|
||||
POSTGRES_DB: mimante_test
|
||||
POSTGRES_HOST_AUTH_METHOD: trust
|
||||
options: >-
|
||||
--health-cmd "pg_isready -U admin -d mimante_test"
|
||||
--health-interval 5s
|
||||
--health-timeout 5s
|
||||
--health-retries 20
|
||||
env:
|
||||
TEST_DB_HOST: postgres
|
||||
TEST_DB_USER: admin
|
||||
TEST_DB_NAME: mimante_test
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Versione coerente con il tag
|
||||
run: |
|
||||
V=$(sed -n 's:.*<Version>\(.*\)</Version>.*:\1:p' Directory.Build.props | head -n 1)
|
||||
T="${GITHUB_REF_NAME#v}"
|
||||
case "$T" in
|
||||
"$V") echo "Rilascio $T" ;;
|
||||
"$V"-rc.[0-9]*) echo "Prova del rilascio $T (immagine :$T, :latest resta dov'è)" ;;
|
||||
*) echo "Il tag ${GITHUB_REF_NAME} non coincide con <Version> $V (né con $V-rc.N)."; exit 1 ;;
|
||||
esac
|
||||
grep -Eq "^## ${V//./\\.}( |$)" CHANGELOG.md || { echo "CHANGELOG.md non ha la sezione ## $V."; exit 1; }
|
||||
|
||||
- uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: "10.0.x"
|
||||
|
||||
- name: Compilazione (avvisi = errori)
|
||||
run: dotnet build Mimante.slnx -c Release -nologo -warnaserror
|
||||
|
||||
- name: Prove
|
||||
run: >-
|
||||
dotnet test tests/Mimante.Tests -c Release --no-build --nologo
|
||||
--logger "trx;LogFileName=prove.trx" --results-directory out/prove
|
||||
|
||||
- name: Riepilogo delle prove (nessuna saltata)
|
||||
if: ${{ !cancelled() }}
|
||||
run: bash .gitea/scripts/riepilogo-prove.sh out/prove 0
|
||||
|
||||
- name: Risultati
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: risultati-prove
|
||||
path: out/prove/*.trx
|
||||
if-no-files-found: ignore
|
||||
|
||||
immagine:
|
||||
runs-on: ubuntu-latest
|
||||
needs: prove
|
||||
timeout-minutes: 60
|
||||
env:
|
||||
FLUSSO: rilascio
|
||||
ESECUZIONE: ${{ gitea.run_id }}
|
||||
BUILDER: mimante-ci-${{ gitea.run_id }}
|
||||
PROVA: mimante-ci:${{ gitea.run_id }}
|
||||
outputs:
|
||||
immagine: ${{ steps.nome.outputs.immagine }}
|
||||
pubblicata: ${{ steps.pubblicazione.outputs.pubblicata }}
|
||||
motivo: ${{ steps.segreto.outputs.motivo }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Resti di esecuzioni interrotte
|
||||
run: |
|
||||
bash .gitea/scripts/pulizia-docker.sh residui 90
|
||||
bash .gitea/scripts/pulizia-docker.sh esecuzione "$ESECUZIONE"
|
||||
|
||||
- name: Versione, registro e nome dell'immagine
|
||||
id: nome
|
||||
env:
|
||||
REGISTRO_SCELTO: ${{ vars.REGISTRY }}
|
||||
SERVER: ${{ gitea.server_url }}
|
||||
PROPRIETARIO: ${{ gitea.repository_owner }}
|
||||
run: |
|
||||
V="${GITHUB_REF_NAME#v}"
|
||||
REGISTRY="$REGISTRO_SCELTO"
|
||||
[ -n "$REGISTRY" ] || REGISTRY=$(echo "$SERVER" | sed -E 's#^https?://##; s#/.*$##')
|
||||
OWNER=$(echo "$PROPRIETARIO" | tr '[:upper:]' '[:lower:]')
|
||||
{
|
||||
echo "VERSION=$V"
|
||||
echo "VERSIONE=$V"
|
||||
echo "GIT_COMMIT=${GITHUB_SHA::12}"
|
||||
echo "ARCHIVIO=${RUNNER_TEMP:-/tmp}/mimante-$ESECUZIONE.tar"
|
||||
echo "REGISTRY=$REGISTRY"
|
||||
echo "IMAGE=$REGISTRY/$OWNER/mimante"
|
||||
} >> "$GITHUB_ENV"
|
||||
echo "registro=$REGISTRY" >> "$GITHUB_OUTPUT"
|
||||
echo "immagine=$REGISTRY/$OWNER/mimante" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
name: mimante-ci-${{ gitea.run_id }}
|
||||
driver: docker-container
|
||||
buildkitd-config-inline: |
|
||||
[registry."${{ steps.nome.outputs.registro }}"]
|
||||
http = true
|
||||
insecure = true
|
||||
|
||||
- name: Costruzione dell'immagine
|
||||
run: |
|
||||
bash .gitea/scripts/costruisci-immagine.sh archivio "$ARCHIVIO" "$PROVA"
|
||||
docker load -i "$ARCHIVIO"
|
||||
|
||||
- name: Prova del contenitore su una rete interna
|
||||
run: bash .gitea/scripts/prova-immagine.sh "$PROVA" "$ESECUZIONE"
|
||||
|
||||
- name: Vulnerabilità dell'immagine (Trivy)
|
||||
run: bash .gitea/scripts/scansione-immagine.sh "$ARCHIVIO" out/sicurezza
|
||||
|
||||
- name: Rapporto di Trivy
|
||||
if: ${{ !cancelled() }}
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: sicurezza-immagine
|
||||
path: out/sicurezza/trivy.json
|
||||
if-no-files-found: ignore
|
||||
|
||||
- name: Segreto per il registro
|
||||
id: segreto
|
||||
env:
|
||||
TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||
run: |
|
||||
if [ -z "$TOKEN" ]; then
|
||||
echo "::warning::Manca il segreto REGISTRY_TOKEN: l'immagine è stata costruita e provata ma non pubblicata. La release esce lo stesso e lo dice."
|
||||
echo "presente=no" >> "$GITHUB_OUTPUT"
|
||||
echo "motivo=manca il segreto REGISTRY_TOKEN" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "presente=si" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Pubblicazione sul registro di Gitea
|
||||
id: pubblicazione
|
||||
if: steps.segreto.outputs.presente == 'si'
|
||||
env:
|
||||
TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||
UTENTE: ${{ gitea.actor }}
|
||||
run: |
|
||||
set -eu
|
||||
CONFIG="${DOCKER_CONFIG:-$HOME/.docker}"
|
||||
mkdir -p "$CONFIG"
|
||||
[ -s "$CONFIG/config.json" ] || echo '{}' > "$CONFIG/config.json"
|
||||
AUTH=$(printf '%s:%s' "$UTENTE" "$TOKEN" | base64 -w0)
|
||||
jq --arg r "$REGISTRY" --arg a "$AUTH" '.auths[$r].auth = $a' "$CONFIG/config.json" > "$CONFIG/config.json.nuovo"
|
||||
mv "$CONFIG/config.json.nuovo" "$CONFIG/config.json"
|
||||
NOMI=("$IMAGE:$VERSION")
|
||||
case "$VERSION" in
|
||||
*-*) echo "Prova del rilascio: :latest non si sposta." ;;
|
||||
*) NOMI+=("$IMAGE:latest") ;;
|
||||
esac
|
||||
bash .gitea/scripts/costruisci-immagine.sh pubblica "${NOMI[@]}"
|
||||
echo "pubblicata=si" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Pulizia (sempre)
|
||||
if: always()
|
||||
run: |
|
||||
CONFIG="${DOCKER_CONFIG:-$HOME/.docker}/config.json"
|
||||
if [ -s "$CONFIG" ] && [ -n "${REGISTRY:-}" ]; then
|
||||
jq --arg r "$REGISTRY" 'if .auths then .auths |= del(.[$r]) else . end' "$CONFIG" > "$CONFIG.nuovo" && mv "$CONFIG.nuovo" "$CONFIG"
|
||||
fi
|
||||
if [ -n "${ARCHIVIO:-}" ]; then rm -f "$ARCHIVIO"; fi
|
||||
bash .gitea/scripts/pulizia-docker.sh esecuzione "$ESECUZIONE"
|
||||
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [prove, immagine]
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Release con le note del CHANGELOG e il modello Unraid
|
||||
env:
|
||||
TOKEN: ${{ github.token }}
|
||||
API: ${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}
|
||||
IMMAGINE: ${{ needs.immagine.outputs.immagine }}
|
||||
PUBBLICATA: ${{ needs.immagine.outputs.pubblicata }}
|
||||
MOTIVO: ${{ needs.immagine.outputs.motivo }}
|
||||
run: |
|
||||
set -eu
|
||||
TAG="${GITHUB_REF_NAME}"
|
||||
VERSION="${TAG#v}"
|
||||
BASE="${VERSION%%-*}"
|
||||
case "$VERSION" in *-*) PRE=true ;; *) PRE=false ;; esac
|
||||
NOTE=$(awk -v v="$BASE" '/^## /{p=($2==v)} p' CHANGELOG.md || true)
|
||||
[ -n "$NOTE" ] || NOTE="Mimante $VERSION"
|
||||
if [ "$PUBBLICATA" = "si" ]; then
|
||||
case "$VERSION" in
|
||||
*-*) DOVE="\`$IMMAGINE:$VERSION\` (prova del rilascio: \`:latest\` resta sulla versione precedente)" ;;
|
||||
*) DOVE="\`$IMMAGINE:$VERSION\` e \`$IMMAGINE:latest\`" ;;
|
||||
esac
|
||||
IMMAGINE_NOTA="Immagine Docker: $DOVE. Il registro risponde in HTTP: su Unraid serve \`--insecure-registry\` (docs/docker.md)."
|
||||
else
|
||||
IMMAGINE_NOTA="**L'immagine di questa versione non è stata pubblicata** (${MOTIVO:-motivo sconosciuto}): Unraid resta sulla versione precedente. Rilancia il flusso di questo tag dopo aver risolto: le note si aggiornano."
|
||||
fi
|
||||
NOTE=$(printf '%s\n\n### Immagine Docker\n\n%s\n' "$NOTE" "$IMMAGINE_NOTA")
|
||||
|
||||
ID=$(curl -sf -H "Authorization: token $TOKEN" "$API/releases/tags/$TAG" | jq -r '.id // empty' || true)
|
||||
if [ -z "$ID" ]; then
|
||||
ID=$(jq -n --arg t "$TAG" --arg n "Mimante $VERSION" --arg b "$NOTE" --argjson p "$PRE" \
|
||||
'{tag_name:$t, name:$n, body:$b, draft:false, prerelease:$p}' \
|
||||
| curl -sf -X POST -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
||||
--data-binary @- "$API/releases" | jq -r .id)
|
||||
echo "Release $TAG creata (id $ID)"
|
||||
else
|
||||
jq -n --arg b "$NOTE" '{body:$b}' \
|
||||
| curl -sf -X PATCH -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
||||
--data-binary @- "$API/releases/$ID" > /dev/null
|
||||
echo "Release $TAG già presente (id $ID): note aggiornate"
|
||||
fi
|
||||
|
||||
mkdir -p out
|
||||
cp docker/unraid/mimante.xml "out/mimante-unraid-$VERSION.xml"
|
||||
ESISTENTI=$(curl -sf -H "Authorization: token $TOKEN" "$API/releases/$ID/assets" | jq -r '.[].name')
|
||||
for f in "out/mimante-unraid-$VERSION.xml"; do
|
||||
n=$(basename "$f")
|
||||
if echo "$ESISTENTI" | grep -qx "$n"; then echo "$n già allegato"; continue; fi
|
||||
curl -sf -X POST -H "Authorization: token $TOKEN" -F "attachment=@$f" "$API/releases/$ID/assets?name=$n" > /dev/null
|
||||
echo "$n allegato"
|
||||
done
|
||||
@@ -0,0 +1,243 @@
|
||||
# Verifica: a ogni push su qualunque ramo (i tag li prende rilascio.yml) e a mano (Actions ▸ verifica ▸ Esegui).
|
||||
# I suoi tre lavori sono i controlli richiesti per unire in main (docs/processo.md):
|
||||
# controlli sintassi di script e flussi, segni di conflitto, versione ed esempi, sezione del CHANGELOG, progetti della
|
||||
# soluzione, elenco chiuso dei pacchetti, niente risorse esterne nell'interfaccia, JSON; segreti in tutta
|
||||
# la storia con gitleaks (versione e impronta fissate);
|
||||
# prove compilazione con gli avvisi come errori e TUTTE le prove di tests/Mimante.Tests, con un PostgreSQL 18 di
|
||||
# servizio: nessuna prova deve saltarsi (anche quelle sul database girano);
|
||||
# immagine l'immagine Docker costruita con buildx (dentro girano compilazione e prove di logica), provata su una
|
||||
# rete interna con un PostgreSQL usa e getta (salute, file di /config, arresto) e scansionata con Trivy
|
||||
# (si ferma per una CRITICAL con correzione); solo dopo un push su main la pubblica come :main e
|
||||
# :sha-<7 caratteri> (:latest resta ai rilasci). Alla fine, sempre, toglie ciò che ha creato.
|
||||
#
|
||||
# Niente «pull_request»: in Gitea una richiesta di unione mostra lo stato del suo ultimo commit, già verificato dal push.
|
||||
# Runner: act_runner ubuntu-latest su Unraid, che parla con il demone Docker di Unraid, lo stesso del PostgreSQL vero
|
||||
# di Mimante. Per questo nessun servizio e nessun contenitore di prova pubblica porte (niente «ports:»), e le prove
|
||||
# dell'immagine stanno su una rete interna (PipelineTests lo controlla).
|
||||
name: verifica
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["**"]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
# Su un ramo conta l'ultimo push: l'esecuzione precedente si annulla. Su main ogni commit ha il suo gruppo, così ogni
|
||||
# unione arriva fino in fondo e pubblica la sua :sha-.
|
||||
concurrency:
|
||||
group: verifica-${{ gitea.event_name }}-${{ gitea.ref }}${{ gitea.ref == 'refs/heads/main' && format('-{0}', gitea.sha) || '' }}
|
||||
cancel-in-progress: ${{ gitea.ref != 'refs/heads/main' }}
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
env:
|
||||
DOTNET_NOLOGO: "1"
|
||||
DOTNET_CLI_TELEMETRY_OPTOUT: "1"
|
||||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: "1"
|
||||
|
||||
jobs:
|
||||
controlli:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
steps:
|
||||
# Tutta la storia: gitleaks legge ogni commit da cui discende quello verificato.
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Script, flussi, conflitti, versione, soluzione, pacchetti, interfaccia e JSON
|
||||
run: bash .gitea/scripts/controlli.sh
|
||||
|
||||
- name: Segreti in tutta la storia (gitleaks)
|
||||
run: bash .gitea/scripts/segreti.sh out/sicurezza
|
||||
|
||||
- name: Rapporto di gitleaks (segreti oscurati)
|
||||
if: failure()
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: rapporto-gitleaks
|
||||
path: out/sicurezza/gitleaks.json
|
||||
retention-days: 14
|
||||
if-no-files-found: ignore
|
||||
|
||||
prove:
|
||||
needs: controlli
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
# Debian 13 con Node 24 (per le azioni): lo stesso Debian dell'immagine di Mimante.
|
||||
container:
|
||||
image: node:24-trixie
|
||||
# PostgreSQL 18 come su Unraid, raggiungibile solo dal lavoro con il nome «postgres». Nessuna porta pubblicata: il
|
||||
# demone è quello di Unraid. Accesso senza password: il database vive quanto il lavoro e nessuno fuori lo vede.
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:18
|
||||
env:
|
||||
POSTGRES_USER: admin
|
||||
POSTGRES_DB: mimante_test
|
||||
POSTGRES_HOST_AUTH_METHOD: trust
|
||||
options: >-
|
||||
--health-cmd "pg_isready -U admin -d mimante_test"
|
||||
--health-interval 5s
|
||||
--health-timeout 5s
|
||||
--health-retries 20
|
||||
env:
|
||||
TEST_DB_HOST: postgres
|
||||
TEST_DB_USER: admin
|
||||
TEST_DB_NAME: mimante_test
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: "10.0.x"
|
||||
|
||||
- name: Compilazione di tutta la soluzione (avvisi = errori)
|
||||
run: dotnet build Mimante.slnx -c Release -nologo -warnaserror
|
||||
|
||||
- name: Prove (anche quelle su PostgreSQL)
|
||||
run: >-
|
||||
dotnet test tests/Mimante.Tests -c Release --no-build --nologo
|
||||
--logger "trx;LogFileName=prove.trx" --results-directory out/prove
|
||||
|
||||
- name: Riepilogo delle prove (nessuna saltata)
|
||||
if: ${{ !cancelled() }}
|
||||
run: bash .gitea/scripts/riepilogo-prove.sh out/prove 0
|
||||
|
||||
- name: Risultati delle prove
|
||||
if: ${{ !cancelled() }}
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: risultati-prove
|
||||
path: out/prove/*.trx
|
||||
retention-days: 14
|
||||
if-no-files-found: warn
|
||||
|
||||
immagine:
|
||||
needs: prove
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
env:
|
||||
FLUSSO: verifica
|
||||
ESECUZIONE: ${{ gitea.run_id }}
|
||||
NUMERO: ${{ gitea.run_number }}
|
||||
BUILDER: mimante-ci-${{ gitea.run_id }}
|
||||
PROVA: mimante-ci:${{ gitea.run_id }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Resti di esecuzioni interrotte
|
||||
run: |
|
||||
bash .gitea/scripts/pulizia-docker.sh residui 90
|
||||
bash .gitea/scripts/pulizia-docker.sh esecuzione "$ESECUZIONE"
|
||||
|
||||
# Registro: la variabile REGISTRY delle Actions, se c'è, altrimenti l'host dell'indirizzo del server (ROOT_URL).
|
||||
- name: Versione, registro e nomi
|
||||
id: nome
|
||||
env:
|
||||
REGISTRO_SCELTO: ${{ vars.REGISTRY }}
|
||||
SERVER: ${{ gitea.server_url }}
|
||||
PROPRIETARIO: ${{ gitea.repository_owner }}
|
||||
run: |
|
||||
V=$(sed -n 's:.*<Version>\(.*\)</Version>.*:\1:p' Directory.Build.props | head -n 1)
|
||||
REGISTRY="$REGISTRO_SCELTO"
|
||||
[ -n "$REGISTRY" ] || REGISTRY=$(echo "$SERVER" | sed -E 's#^https?://##; s#/.*$##')
|
||||
OWNER=$(echo "$PROPRIETARIO" | tr '[:upper:]' '[:lower:]')
|
||||
{
|
||||
echo "VERSIONE=$V-ci.$NUMERO"
|
||||
echo "GIT_COMMIT=${GITHUB_SHA::12}"
|
||||
echo "REGISTRY=$REGISTRY"
|
||||
echo "IMAGE=$REGISTRY/$OWNER/mimante"
|
||||
echo "ARCHIVIO=${RUNNER_TEMP:-/tmp}/mimante-$ESECUZIONE.tar"
|
||||
} >> "$GITHUB_ENV"
|
||||
echo "registro=$REGISTRY" >> "$GITHUB_OUTPUT"
|
||||
echo "Immagine $V-ci.$NUMERO del commit ${GITHUB_SHA::12}, provata come $PROVA; registro $REGISTRY/$OWNER/mimante"
|
||||
|
||||
# Un builder buildx di questa esecuzione, che sa che il registro di casa risponde in HTTP.
|
||||
- name: Builder buildx dell'esecuzione
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
name: mimante-ci-${{ gitea.run_id }}
|
||||
driver: docker-container
|
||||
buildkitd-config-inline: |
|
||||
[registry."${{ steps.nome.outputs.registro }}"]
|
||||
http = true
|
||||
insecure = true
|
||||
|
||||
- name: Costruzione dell'immagine (dentro girano compilazione e prove di logica)
|
||||
run: |
|
||||
bash .gitea/scripts/costruisci-immagine.sh archivio "$ARCHIVIO" "$PROVA"
|
||||
docker load -i "$ARCHIVIO"
|
||||
|
||||
- name: Prova del contenitore su una rete interna
|
||||
run: bash .gitea/scripts/prova-immagine.sh "$PROVA" "$ESECUZIONE"
|
||||
|
||||
- name: Vulnerabilità dell'immagine (Trivy)
|
||||
run: bash .gitea/scripts/scansione-immagine.sh "$ARCHIVIO" out/sicurezza
|
||||
|
||||
- name: Rapporto di Trivy
|
||||
if: ${{ !cancelled() }}
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: sicurezza-immagine
|
||||
path: out/sicurezza/trivy.json
|
||||
retention-days: 14
|
||||
if-no-files-found: ignore
|
||||
|
||||
- name: Pubblicare?
|
||||
id: segreto
|
||||
env:
|
||||
TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||
EVENTO: ${{ gitea.event_name }}
|
||||
RIFERIMENTO: ${{ gitea.ref }}
|
||||
run: |
|
||||
if [ "$EVENTO" != push ] || [ "$RIFERIMENTO" != refs/heads/main ]; then
|
||||
echo "Si pubblica solo dopo un push su main: qui l'immagine è costruita, provata e scansionata."
|
||||
echo "presente=no" >> "$GITHUB_OUTPUT"
|
||||
elif [ -z "$TOKEN" ]; then
|
||||
echo "::warning::Manca il segreto REGISTRY_TOKEN: l'immagine di main è costruita, provata e scansionata ma non pubblicata."
|
||||
echo "presente=no" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "presente=si" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Pubblicazione come :main e :sha-<commit>
|
||||
if: steps.segreto.outputs.presente == 'si'
|
||||
env:
|
||||
TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||
UTENTE: ${{ gitea.actor }}
|
||||
run: |
|
||||
# Le credenziali vanno nella configurazione del client: buildx le passa al builder, il demone non c'entra (e
|
||||
# proverebbe HTTPS). Non si stampano mai.
|
||||
CONFIG="${DOCKER_CONFIG:-$HOME/.docker}"
|
||||
mkdir -p "$CONFIG"
|
||||
[ -s "$CONFIG/config.json" ] || echo '{}' > "$CONFIG/config.json"
|
||||
AUTH=$(printf '%s:%s' "$UTENTE" "$TOKEN" | base64 -w0)
|
||||
jq --arg r "$REGISTRY" --arg a "$AUTH" '.auths[$r].auth = $a' "$CONFIG/config.json" > "$CONFIG/config.json.nuovo"
|
||||
mv "$CONFIG/config.json.nuovo" "$CONFIG/config.json"
|
||||
NOMI=("$IMAGE:sha-${GITHUB_SHA::7}")
|
||||
# :main solo se main è ancora a questo commit: un'esecuzione arrivata in ritardo non lo riporta indietro.
|
||||
CIMA=$(git ls-remote origin refs/heads/main 2> /dev/null | cut -f1) || CIMA=""
|
||||
if [ "$CIMA" = "$GITHUB_SHA" ]; then
|
||||
NOMI+=("$IMAGE:main")
|
||||
elif [ -z "$CIMA" ]; then
|
||||
echo "::warning::Non riesco a leggere la cima di main: si pubblica solo :sha-${GITHUB_SHA::7}."
|
||||
else
|
||||
echo "main è già andato avanti (${CIMA::7}): si pubblica solo :sha-${GITHUB_SHA::7}."
|
||||
fi
|
||||
bash .gitea/scripts/costruisci-immagine.sh pubblica "${NOMI[@]}"
|
||||
|
||||
- name: Pulizia (sempre)
|
||||
if: always()
|
||||
run: |
|
||||
CONFIG="${DOCKER_CONFIG:-$HOME/.docker}/config.json"
|
||||
if [ -s "$CONFIG" ] && [ -n "${REGISTRY:-}" ]; then
|
||||
jq --arg r "$REGISTRY" 'if .auths then .auths |= del(.[$r]) else . end' "$CONFIG" > "$CONFIG.nuovo" \
|
||||
&& mv "$CONFIG.nuovo" "$CONFIG" || echo "::warning::Non riesco a togliere le credenziali da $CONFIG."
|
||||
fi
|
||||
if [ -n "${ARCHIVIO:-}" ]; then rm -f "$ARCHIVIO"; fi
|
||||
bash .gitea/scripts/pulizia-docker.sh esecuzione "$ESECUZIONE"
|
||||
Reference in new issue
Block a user