mcServerWebsite/.forgejo/workflows/deploy.yml
Ploush bfcc83db24
All checks were successful
Build & Deploy / Validation, build et push (push) Successful in 13m54s
fix: build
2026-06-07 18:52:19 +02:00

135 lines
No EOL
5.8 KiB
YAML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ============================================================
# Forgejo Actions — Build + Push image → Registre Forgejo
# Déclenché uniquement sur un tag A.B.C poussé sur master
# ============================================================
#
# Prérequis : créer un jeton Forgejo dans
# Paramètres → Applications → Jetons d'accès personnel
# Permissions requises : read:packages, write:packages
# Puis l'ajouter dans le dépôt :
# Paramètres → Actions → Secrets → FORGEJO_TOKEN
# ============================================================
name: Build & Deploy
on:
push:
tags:
# Pré-filtre glob (validation stricte faite dans le job)
- '[0-9]*.[0-9]*.[0-9]*'
jobs:
build-and-push:
name: Validation, build et push
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
# ── 1. Checkout complet (historique + tags) ───────────────────────
- name: Checkout du code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Indispensable pour comparer les tags existants
# ── 2. Le tag doit pointer sur un commit présent dans master ─────────
- name: Vérification — tag sur master
run: |
git fetch origin master --no-tags
if ! git merge-base --is-ancestor "${{ github.sha }}" origin/master; then
echo "Le tag '${{ github.ref_name }}' ne pointe pas sur un commit de master."
exit 1
fi
echo "Commit du tag présent dans master."
# ── 3. Validation du format + progression de version ──────────────
- name: Validation du tag et calcul des tags Docker
id: semver
run: |
TAG="${{ github.ref_name }}"
# ── Format : A.B.C avec A, B, C entiers >= 0, sans zéro initial ──
if ! echo "$TAG" | grep -qE '^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$'; then
echo "❌ Format invalide : '$TAG'"
echo " Attendu : A.B.C avec A, B, C entiers >= 0 (ex: 1.0.1)"
exit 1
fi
IFS='.' read -r A B C <<< "$TAG"
# ── Trouver le tag valide le plus élevé (hors tag courant) ───
# Les tags sont triés numériquement par composant : le dernier
# de la boucle est donc le maximum courant.
PREV_TAG=""
while IFS= read -r t; do
[ "$t" = "$TAG" ] && continue
if echo "$t" | grep -qE '^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$'; then
PREV_TAG="$t"
fi
done < <(git tag -l | sort -t. -k1,1n -k2,2n -k3,3n)
# ── Vérification de la progression stricte ───────────────────
if [ -n "$PREV_TAG" ]; then
IFS='.' read -r PA PB PC <<< "$PREV_TAG"
echo " Tag précédent le plus élevé : $PREV_TAG"
OK=false
if [ "$A" -gt "$PA" ]; then
OK=true
elif [ "$A" -eq "$PA" ] && [ "$B" -gt "$PB" ]; then
OK=true
elif [ "$A" -eq "$PA" ] && [ "$B" -eq "$PB" ] && [ "$C" -gt "$PC" ]; then
OK=true
fi
if [ "$OK" = false ]; then
echo "❌ '$TAG' ne respecte pas la règle de progression :"
echo " A > PA"
echo " OU ( A = PA ET B > PB )"
echo " OU ( A = PA ET B = PB ET C > PC )"
echo " Tag précédent : $PREV_TAG / Tag proposé : $TAG"
exit 1
fi
else
echo " Aucun tag valide précédent. Première version, pas de vérification de progression."
fi
echo "✅ Tag '$TAG' validé."
# ── Outputs réutilisés par les étapes suivantes ───────────────
echo "full=${A}.${B}.${C}" >> "$GITHUB_OUTPUT"
echo "minor=${A}.${B}" >> "$GITHUB_OUTPUT"
echo "major=${A}" >> "$GITHUB_OUTPUT"
# ── 4. Extraction du hostname du registre Forgejo ─────────────────
- name: Extraction de l'URL du registre
id: registry
run: |
echo "host=git.ploush.top" >> "$GITHUB_OUTPUT"
# ── 5. Authentification ───────────────────────────────────────────
- name: Connexion au registre Forgejo
uses: docker/login-action@v3
with:
registry: ${{ steps.registry.outputs.host }}
username: ${{ github.actor }}
password: ${{ secrets.FORGEJO_TOKEN }}
# ── 6. Build et push (4 tags) ─────────────────────────────────────
- name: Build et push de l'image Docker
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/apache/Dockerfile
push: true
provenance: false
tags: |
${{ steps.registry.outputs.host }}/${{ github.repository_owner }}/mcserverwebsite:${{ steps.semver.outputs.full }}
${{ steps.registry.outputs.host }}/${{ github.repository_owner }}/mcserverwebsite:${{ steps.semver.outputs.minor }}
${{ steps.registry.outputs.host }}/${{ github.repository_owner }}/mcserverwebsite:${{ steps.semver.outputs.major }}
${{ steps.registry.outputs.host }}/${{ github.repository_owner }}/mcserverwebsite:latest