Feat/89 collection championships #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 'Release Automatisation' | |
| permissions: | |
| contents: write | |
| on: | |
| pull_request: | |
| types: [closed] | |
| branches: | |
| - main | |
| jobs: | |
| release: | |
| if: > | |
| github.event.pull_request.merged == true && | |
| github.event.pull_request.head.ref == 'dev' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 'Checkout code' | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| - name: 'Configurer Git' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: 'Déterminer la nouvelle version' | |
| id: semver | |
| run: | | |
| set -e | |
| LATEST_TAG=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1) | |
| if [[ -z "$LATEST_TAG" ]]; then | |
| VERSION="0.1.0" | |
| else | |
| VERSION="${LATEST_TAG#v}" | |
| MAJOR=$(echo "$VERSION" | cut -d. -f1) | |
| MINOR=$(echo "$VERSION" | cut -d. -f2) | |
| PATCH=$(echo "$VERSION" | cut -d. -f3) | |
| MINOR=$((MINOR + 1)) | |
| PATCH=0 | |
| VERSION="$MAJOR.$MINOR.$PATCH" | |
| fi | |
| TAG="v$VERSION" | |
| echo "Nouvelle release : $TAG" | |
| if git rev-parse "$TAG" >/dev/null 2>&1; then | |
| echo "❌ Le tag $TAG existe déjà" | |
| exit 1 | |
| fi | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| - name: 'Vérifier le CHANGELOG' | |
| id: changelog_check | |
| run: | | |
| set -e | |
| VERSION="${{ steps.semver.outputs.version }}" | |
| if [[ ! -f CHANGELOG.md ]]; then | |
| echo "❌ CHANGELOG.md est manquant" | |
| exit 1 | |
| fi | |
| # Extraire uniquement la section de la version | |
| SECTION=$(awk " | |
| BEGIN {found=0} | |
| /^## \\[$VERSION\\]/ {found=1} | |
| found {print} | |
| found && /^## \\[[0-9]/ && !/^## \\[$VERSION\\]/ {exit} | |
| " CHANGELOG.md) | |
| if [[ -z "$SECTION" ]]; then | |
| echo "❌ Aucune entrée de changelog pour la version $VERSION" | |
| exit 1 | |
| fi | |
| # Vérifier que la section contient du contenu réel | |
| CONTENT=$(echo "$SECTION" | grep -Ev '^(## |\s*$|### )') | |
| if [[ -z "$CONTENT" ]]; then | |
| echo "❌ Le changelog pour la version $VERSION est vide" | |
| exit 1 | |
| fi | |
| echo "✅ Changelog valide pour la version $VERSION" | |
| echo "release_notes<<EOF" >> $GITHUB_OUTPUT | |
| echo "$SECTION" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: 'Créer le tag' | |
| run: | | |
| git tag "${{ steps.semver.outputs.tag }}" | |
| git push origin "${{ steps.semver.outputs.tag }}" | |
| - name: 'Créer la GitHub Release' | |
| uses: ncipollo/release-action@v1 | |
| with: | |
| tag: '${{ steps.semver.outputs.tag }}' | |
| name: '${{ steps.semver.outputs.tag }}' | |
| body: '${{ steps.changelog_check.outputs.release_notes }}' |