|
5 | 5 | branches: |
6 | 6 | - trunk |
7 | 7 | tags: |
8 | | - - 'v*' # Active le workflow pour les tags commençant par v |
| 8 | + - 'v*' |
9 | 9 | pull_request: |
10 | 10 | branches: |
11 | 11 | - trunk |
12 | 12 | branches-ignore: |
13 | 13 | - main |
14 | 14 |
|
| 15 | +env: |
| 16 | + # Configuration du versionnement sémantique |
| 17 | + MAJOR_LABELS: "breaking" |
| 18 | + MINOR_LABELS: "enhancement,feat" |
| 19 | + PATCH_LABELS: "bugfix,fix" |
| 20 | + DEFAULT_VERSION: "0.1.0" |
| 21 | + VERSION_FILE: "VERSION" |
| 22 | + |
15 | 23 | jobs: |
16 | 24 | release: |
17 | 25 | runs-on: ubuntu-latest |
| 26 | + env: |
| 27 | + # Configuration du versionnement sémantique |
| 28 | + MAJOR_LABELS: "breaking" |
| 29 | + MINOR_LABELS: "enhancement,feat" |
| 30 | + PATCH_LABELS: "bugfix,fix" |
| 31 | + DEFAULT_VERSION: "0.1.0" |
| 32 | + VERSION_FILE: "VERSION" |
| 33 | + |
18 | 34 | strategy: |
19 | 35 | matrix: |
20 | | - go-version: ['1.21'] |
21 | 36 | platform: [linux, darwin] |
22 | 37 | arch: [amd64, arm64] |
23 | 38 |
|
24 | 39 | steps: |
25 | 40 | - uses: actions/checkout@v3 |
| 41 | + with: |
| 42 | + fetch-depth: 0 # Pour récupérer l'historique complet |
26 | 43 |
|
27 | 44 | - name: Set up Go |
28 | 45 | uses: actions/setup-go@v4 |
29 | 46 | with: |
30 | | - go-version: ${{ matrix.go-version }} |
| 47 | + go-version: '1.21' |
| 48 | + |
| 49 | + - name: Get Current Version |
| 50 | + id: version |
| 51 | + run: | |
| 52 | + # Si le fichier VERSION existe, on utilise sa version |
| 53 | + if [ -f ${{ env.VERSION_FILE }} ]; then |
| 54 | + echo "CURRENT_VERSION=$(cat ${{ env.VERSION_FILE }})" >> $GITHUB_OUTPUT |
| 55 | + else |
| 56 | + echo "CURRENT_VERSION=${{ env.DEFAULT_VERSION }}" >> $GITHUB_OUTPUT |
| 57 | + fi |
| 58 | +
|
| 59 | + - name: Get Git Tags |
| 60 | + id: tags |
| 61 | + run: | |
| 62 | + echo "TAGS=$(git describe --tags --abbrev=0 2>/dev/null || echo '')" >> $GITHUB_OUTPUT |
| 63 | +
|
| 64 | + - name: Get PR Labels |
| 65 | + id: labels |
| 66 | + run: | |
| 67 | + if [ -n "${{ github.event.pull_request }}" ]; then |
| 68 | + echo "LABELS=$(jq -r '.pull_request.labels[].name' <<< '${{ toJson(github.event) }}' | tr '\n' ',')" >> $GITHUB_OUTPUT |
| 69 | + else |
| 70 | + echo "LABELS=" >> $GITHUB_OUTPUT |
| 71 | + fi |
| 72 | +
|
| 73 | + - name: Determine Next Version |
| 74 | + id: next_version |
| 75 | + run: | |
| 76 | + CURRENT_VERSION=${{ steps.version.outputs.CURRENT_VERSION }} |
| 77 | + TAGS=${{ steps.tags.outputs.TAGS }} |
| 78 | + LABELS=${{ steps.labels.outputs.LABELS }} |
| 79 | + |
| 80 | + # Si on a des tags, on utilise la dernière version |
| 81 | + if [ -n "$TAGS" ]; then |
| 82 | + CURRENT_VERSION=$TAGS |
| 83 | + fi |
| 84 | + |
| 85 | + # Par défaut, on fait une version PATCH |
| 86 | + TYPE="patch" |
| 87 | + |
| 88 | + # Si on a des labels, on détermine le type de version |
| 89 | + if [ -n "$LABELS" ]; then |
| 90 | + if echo "$LABELS" | grep -qE "(${{ env.MAJOR_LABELS }})"; then |
| 91 | + TYPE="major" |
| 92 | + elif echo "$LABELS" | grep -qE "(${{ env.MINOR_LABELS }})"; then |
| 93 | + TYPE="minor" |
| 94 | + fi |
| 95 | + fi |
| 96 | + |
| 97 | + # Extraire les numéros de version |
| 98 | + MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1) |
| 99 | + MINOR=$(echo $CURRENT_VERSION | cut -d. -f2) |
| 100 | + PATCH=$(echo $CURRENT_VERSION | cut -d. -f3) |
| 101 | + |
| 102 | + # Calculer la nouvelle version |
| 103 | + case $TYPE in |
| 104 | + major) |
| 105 | + MAJOR=$((MAJOR + 1)) |
| 106 | + MINOR=0 |
| 107 | + PATCH=0 |
| 108 | + ;; |
| 109 | + minor) |
| 110 | + MINOR=$((MINOR + 1)) |
| 111 | + PATCH=0 |
| 112 | + ;; |
| 113 | + patch) |
| 114 | + PATCH=$((PATCH + 1)) |
| 115 | + ;; |
| 116 | + esac |
| 117 | + |
| 118 | + NEXT_VERSION="$MAJOR.$MINOR.$PATCH" |
| 119 | + echo "NEXT_VERSION=$NEXT_VERSION" >> $GITHUB_OUTPUT |
31 | 120 |
|
32 | | - - name: Build |
| 121 | + - name: Create Version File |
33 | 122 | run: | |
34 | | - GOOS=${{ matrix.platform }} GOARCH=${{ matrix.arch }} go build -o persona_${{ matrix.platform }}_${{ matrix.arch }} ./cmd |
| 123 | + echo "${{ steps.next_version.outputs.NEXT_VERSION }}" > ${{ env.VERSION_FILE }} |
35 | 124 |
|
36 | 125 | - name: Create Release |
37 | 126 | id: create_release |
38 | 127 | uses: actions/create-release@v1 |
39 | 128 | env: |
40 | 129 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
41 | 130 | with: |
42 | | - tag_name: ${{ github.ref }} |
43 | | - release_name: Release ${{ github.ref }} |
| 131 | + tag_name: v${{ steps.next_version.outputs.NEXT_VERSION }} |
| 132 | + release_name: Release v${{ steps.next_version.outputs.NEXT_VERSION }} |
| 133 | + body: | |
| 134 | + ## Changelog |
| 135 | + |
| 136 | + $(git log --pretty=format:'- %s (%h)' ${{ steps.tags.outputs.TAGS }}..HEAD) |
44 | 137 | draft: false |
45 | 138 | prerelease: false |
46 | 139 |
|
|
50 | 143 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
51 | 144 | with: |
52 | 145 | upload_url: ${{ steps.create_release.outputs.upload_url }} |
53 | | - asset_path: ./persona_${{ matrix.platform }}_${{ matrix.arch }} |
| 146 | + asset_path: persona_${{ matrix.platform }}_${{ matrix.arch }} |
54 | 147 | asset_name: persona_${{ matrix.platform }}_${{ matrix.arch }} |
55 | 148 | asset_content_type: application/octet-stream |
0 commit comments