Skip to content

Commit a351dfe

Browse files
committed
add: automatic release
1 parent 30a56b6 commit a351dfe

File tree

2 files changed

+236
-8
lines changed

2 files changed

+236
-8
lines changed

.github/workflows/release.yml

Lines changed: 101 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,135 @@ on:
55
branches:
66
- trunk
77
tags:
8-
- 'v*' # Active le workflow pour les tags commençant par v
8+
- 'v*'
99
pull_request:
1010
branches:
1111
- trunk
1212
branches-ignore:
1313
- main
1414

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+
1523
jobs:
1624
release:
1725
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+
1834
strategy:
1935
matrix:
20-
go-version: ['1.21']
2136
platform: [linux, darwin]
2237
arch: [amd64, arm64]
2338

2439
steps:
2540
- uses: actions/checkout@v3
41+
with:
42+
fetch-depth: 0 # Pour récupérer l'historique complet
2643

2744
- name: Set up Go
2845
uses: actions/setup-go@v4
2946
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
31120
32-
- name: Build
121+
- name: Create Version File
33122
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 }}
35124
36125
- name: Create Release
37126
id: create_release
38127
uses: actions/create-release@v1
39128
env:
40129
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41130
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)
44137
draft: false
45138
prerelease: false
46139

@@ -50,6 +143,6 @@ jobs:
50143
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51144
with:
52145
upload_url: ${{ steps.create_release.outputs.upload_url }}
53-
asset_path: ./persona_${{ matrix.platform }}_${{ matrix.arch }}
146+
asset_path: persona_${{ matrix.platform }}_${{ matrix.arch }}
54147
asset_name: persona_${{ matrix.platform }}_${{ matrix.arch }}
55148
asset_content_type: application/octet-stream

.github/workflows/semver.yml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: Semantic Versioning
2+
3+
on:
4+
push:
5+
branches:
6+
- trunk
7+
tags:
8+
- 'v*'
9+
pull_request:
10+
branches:
11+
- trunk
12+
branches-ignore:
13+
- main
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+
23+
jobs:
24+
version:
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- uses: actions/checkout@v3
29+
with:
30+
fetch-depth: 0 # Pour récupérer l'historique complet
31+
32+
- name: Get Current Version
33+
id: version
34+
run: |
35+
# Si le fichier VERSION existe, on utilise sa version
36+
if [ -f ${{ env.VERSION_FILE }} ]; then
37+
echo "CURRENT_VERSION=$(cat ${{ env.VERSION_FILE }})" >> $GITHUB_OUTPUT
38+
else
39+
echo "CURRENT_VERSION=${{ env.DEFAULT_VERSION }}" >> $GITHUB_OUTPUT
40+
fi
41+
42+
- name: Get Git Tags
43+
id: tags
44+
run: |
45+
echo "TAGS=$(git describe --tags --abbrev=0 2>/dev/null || echo '')" >> $GITHUB_OUTPUT
46+
47+
- name: Get PR Labels
48+
id: labels
49+
run: |
50+
if [ -n "${{ github.event.pull_request }}" ]; then
51+
echo "LABELS=$(jq -r '.pull_request.labels[].name' <<< '${{ toJson(github.event) }}' | tr '\n' ',')" >> $GITHUB_OUTPUT
52+
else
53+
echo "LABELS=" >> $GITHUB_OUTPUT
54+
fi
55+
56+
- name: Determine Next Version
57+
id: next_version
58+
run: |
59+
CURRENT_VERSION=${{ steps.version.outputs.CURRENT_VERSION }}
60+
TAGS=${{ steps.tags.outputs.TAGS }}
61+
LABELS=${{ steps.labels.outputs.LABELS }}
62+
63+
# Si on a des tags, on utilise la dernière version
64+
if [ -n "$TAGS" ]; then
65+
CURRENT_VERSION=$TAGS
66+
fi
67+
68+
# Par défaut, on fait une version PATCH
69+
TYPE="patch"
70+
71+
# Si on a des labels, on détermine le type de version
72+
if [ -n "$LABELS" ]; then
73+
if echo "$LABELS" | grep -qE "(${{ env.MAJOR_LABELS }})"; then
74+
TYPE="major"
75+
elif echo "$LABELS" | grep -qE "(${{ env.MINOR_LABELS }})"; then
76+
TYPE="minor"
77+
fi
78+
fi
79+
80+
# Extraire les numéros de version
81+
MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1)
82+
MINOR=$(echo $CURRENT_VERSION | cut -d. -f2)
83+
PATCH=$(echo $CURRENT_VERSION | cut -d. -f3)
84+
85+
# Calculer la nouvelle version
86+
case $TYPE in
87+
major)
88+
MAJOR=$((MAJOR + 1))
89+
MINOR=0
90+
PATCH=0
91+
;;
92+
minor)
93+
MINOR=$((MINOR + 1))
94+
PATCH=0
95+
;;
96+
patch)
97+
PATCH=$((PATCH + 1))
98+
;;
99+
esac
100+
101+
NEXT_VERSION="$MAJOR.$MINOR.$PATCH"
102+
echo "NEXT_VERSION=$NEXT_VERSION" >> $GITHUB_OUTPUT
103+
104+
- name: Create Version File
105+
run: |
106+
echo "${{ steps.next_version.outputs.NEXT_VERSION }}" > ${{ env.VERSION_FILE }}
107+
108+
- name: Create Release
109+
id: create_release
110+
uses: actions/create-release@v1
111+
env:
112+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
113+
with:
114+
tag_name: v${{ steps.next_version.outputs.NEXT_VERSION }}
115+
release_name: Release v${{ steps.next_version.outputs.NEXT_VERSION }}
116+
body: |
117+
## Changelog
118+
119+
$(git log --pretty=format:'- %s (%h)' ${{ steps.tags.outputs.TAGS }}..HEAD)
120+
draft: false
121+
prerelease: false
122+
123+
- name: Build
124+
run: |
125+
go build -o persona ./cmd
126+
127+
- name: Upload Release Asset
128+
uses: actions/upload-release-asset@v1
129+
env:
130+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
131+
with:
132+
upload_url: ${{ steps.create_release.outputs.upload_url }}
133+
asset_path: persona
134+
asset_name: persona
135+
asset_content_type: application/octet-stream

0 commit comments

Comments
 (0)