chore(workflow): Fixes #8 - hotfix du workflow #6
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: 'Workflow Hotfix' | |
| permissions: | |
| contents: write | |
| on: | |
| push: | |
| branches: | |
| - 'hotfix/*' | |
| jobs: | |
| hotfix: | |
| 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 version hotfix' | |
| id: semver | |
| run: | | |
| set -e | |
| # Dernier tag vX.Y.Z | |
| LATEST_TAG=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1) | |
| if [[ -z "$LATEST_TAG" ]]; then | |
| echo "Aucun tag trouvé, initialisation à v0.0.1" | |
| VERSION="0.0.1" | |
| else | |
| VERSION="${LATEST_TAG#v}" | |
| MAJOR=$(echo "$VERSION" | cut -d. -f1) | |
| MINOR=$(echo "$VERSION" | cut -d. -f2) | |
| PATCH=$(echo "$VERSION" | cut -d. -f3) | |
| PATCH=$((PATCH + 1)) | |
| VERSION="$MAJOR.$MINOR.$PATCH" | |
| fi | |
| TAG="v$VERSION" | |
| echo "Nouvelle version candidate : $TAG" | |
| # Vérifie si le tag existe déjà | |
| if git rev-parse "$TAG" >/dev/null 2>&1; then | |
| echo "⚠️ Le tag $TAG existe déjà, skip." | |
| echo "skip=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "skip=false" >> $GITHUB_OUTPUT | |
| fi | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| - name: 'Créer le tag git' | |
| if: steps.semver.outputs.skip != 'true' | |
| run: | | |
| git tag "${{ steps.semver.outputs.tag }}" | |
| git push origin "${{ steps.semver.outputs.tag }}" | |
| - name: 'Extraire la section du changelog' | |
| if: steps.semver.outputs.skip != 'true' | |
| id: changelog | |
| run: | | |
| VERSION="${{ steps.semver.outputs.version }}" | |
| if [[ -f CHANGELOG.md ]]; then | |
| sed -n "/## \[$VERSION\]/,/^## /p" CHANGELOG.md > release_notes.txt | |
| else | |
| echo "No CHANGELOG.md found" > release_notes.txt | |
| fi | |
| echo "release_notes<<EOF" >> $GITHUB_OUTPUT | |
| cat release_notes.txt >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: 'Créer une release GitHub' | |
| if: steps.semver.outputs.skip != 'true' | |
| uses: ncipollo/release-action@v1 | |
| with: | |
| tag: '${{ steps.semver.outputs.tag }}' | |
| name: 'Hotfix ${{ steps.semver.outputs.tag }}' | |
| body: '${{ steps.changelog.outputs.release_notes }}' |