|
1 | 1 | name: 'Release workflow' |
2 | 2 |
|
3 | | -on: |
4 | | - push: |
5 | | - branches: |
6 | | - - 'release/*' |
7 | | - |
8 | 3 | permissions: |
9 | 4 | contents: write |
10 | 5 |
|
| 6 | +on: |
| 7 | + pull_request: |
| 8 | + types: [closed] |
| 9 | + branches: |
| 10 | + - main |
| 11 | + |
11 | 12 | jobs: |
12 | 13 | release: |
| 14 | + if: > |
| 15 | + github.event.pull_request.merged == true && |
| 16 | + github.event.pull_request.head.ref == 'dev' |
| 17 | +
|
13 | 18 | runs-on: ubuntu-latest |
14 | 19 |
|
15 | 20 | steps: |
16 | | - # 🔹 1. Checkout complet pour récupérer tous les commits et tags |
17 | 21 | - name: 'Checkout code' |
18 | 22 | uses: actions/checkout@v3 |
19 | 23 | with: |
20 | 24 | fetch-depth: 0 |
21 | 25 |
|
22 | | - # 🔹 2. Configurer Git pour les commits/tag du bot |
23 | | - - name: 'Set up Git' |
| 26 | + - name: 'Configurer Git' |
24 | 27 | run: | |
25 | 28 | git config user.name "github-actions[bot]" |
26 | 29 | git config user.email "github-actions[bot]@users.noreply.github.com" |
27 | 30 |
|
28 | | - # 🔹 3. Déterminer la version de release depuis le nom de branche |
29 | | - - name: 'Determine release version' |
| 31 | + - name: 'Déterminer la nouvelle version' |
30 | 32 | id: semver |
31 | 33 | run: | |
32 | | - BRANCH_NAME="${GITHUB_REF#refs/heads/}" |
33 | | - if [[ "$BRANCH_NAME" =~ ^release/([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then |
34 | | - VERSION="${BASH_REMATCH[1]}" |
35 | | - echo "Release version: $VERSION" |
| 34 | + set -e |
| 35 | +
|
| 36 | + # Récupérer le dernier tag vX.Y.Z |
| 37 | + LATEST_TAG=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1) |
| 38 | +
|
| 39 | + if [[ -z "$LATEST_TAG" ]]; then |
| 40 | + VERSION="0.1.0" |
36 | 41 | else |
37 | | - echo "❌ Branch name does not match release/x.y.z" |
38 | | - exit 1 |
| 42 | + VERSION="${LATEST_TAG#v}" |
| 43 | + MAJOR=$(echo "$VERSION" | cut -d. -f1) |
| 44 | + MINOR=$(echo "$VERSION" | cut -d. -f2) |
| 45 | + PATCH=$(echo "$VERSION" | cut -d. -f3) |
| 46 | + MINOR=$((MINOR + 1)) |
| 47 | + PATCH=0 |
| 48 | + VERSION="$MAJOR.$MINOR.$PATCH" |
39 | 49 | fi |
40 | | - echo "version=$VERSION" >> $GITHUB_OUTPUT |
41 | 50 |
|
42 | | - # 🔹 4. Créer le tag Git (supprime ancien tag si besoin) |
43 | | - - name: 'Create git tag' |
44 | | - run: | |
45 | | - VERSION="v${{ steps.semver.outputs.version }}" |
46 | | - echo "Creating tag $VERSION" |
| 51 | + TAG="v$VERSION" |
| 52 | + echo "Nouvelle release : $TAG" |
47 | 53 |
|
48 | | - # Supprimer tag local s'il existe |
49 | | - git tag -d $VERSION || true |
| 54 | + # Vérifier si le tag existe déjà |
| 55 | + if git rev-parse "$TAG" >/dev/null 2>&1; then |
| 56 | + echo "❌ Le tag $TAG existe déjà" |
| 57 | + exit 1 |
| 58 | + fi |
50 | 59 |
|
51 | | - # Supprimer tag distant s'il existe |
52 | | - git push --delete origin $VERSION || true |
| 60 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 61 | + echo "tag=$TAG" >> $GITHUB_OUTPUT |
53 | 62 |
|
54 | | - # Créer et pousser le tag |
55 | | - git tag $VERSION |
56 | | - git push origin $VERSION |
| 63 | + - name: 'Créer le tag' |
| 64 | + run: | |
| 65 | + git tag "${{ steps.semver.outputs.tag }}" |
| 66 | + git push origin "${{ steps.semver.outputs.tag }}" |
57 | 67 |
|
58 | | - # 🔹 5. Extraire la section correspondante dans le CHANGELOG.md |
59 | | - - name: 'Extract changelog section' |
| 68 | + - name: 'Extraire le changelog' |
60 | 69 | id: changelog |
61 | 70 | run: | |
62 | 71 | VERSION="${{ steps.semver.outputs.version }}" |
63 | 72 | if [[ -f CHANGELOG.md ]]; then |
| 73 | + # Extraire la section du changelog correspondant à cette version |
64 | 74 | sed -n "/## \[$VERSION\]/,/^## /p" CHANGELOG.md > release_notes.txt |
65 | 75 | else |
66 | | - echo "No CHANGELOG.md found" > release_notes.txt |
| 76 | + echo "Release $VERSION" > release_notes.txt |
67 | 77 | fi |
| 78 | +
|
| 79 | + # Préparer la sortie pour GitHub Actions |
68 | 80 | echo "release_notes<<EOF" >> $GITHUB_OUTPUT |
69 | 81 | cat release_notes.txt >> $GITHUB_OUTPUT |
70 | 82 | echo "EOF" >> $GITHUB_OUTPUT |
71 | 83 |
|
72 | | - # 🔹 6. Créer la GitHub Release |
73 | | - - name: 'Create GitHub Release' |
| 84 | + - name: 'Créer la GitHub Release' |
74 | 85 | uses: ncipollo/release-action@v1 |
75 | 86 | with: |
76 | | - tag: v${{ steps.semver.outputs.version }} |
77 | | - name: Release v${{ steps.semver.outputs.version }} |
78 | | - body: ${{ steps.changelog.outputs.release_notes }} |
| 87 | + tag: '${{ steps.semver.outputs.tag }}' |
| 88 | + name: 'Release ${{ steps.semver.outputs.tag }}' |
| 89 | + body: '${{ steps.changelog.outputs.release_notes }}' |
0 commit comments