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