-
Notifications
You must be signed in to change notification settings - Fork 237
337 lines (296 loc) · 9.71 KB
/
release.yml
File metadata and controls
337 lines (296 loc) · 9.71 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
name: Release
permissions:
contents: read
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build:
name: Build binaries
runs-on: ubuntu-latest
strategy:
matrix:
include:
- goos: linux
goarch: amd64
cgo: 0
- goos: linux
goarch: arm64
cgo: 0
- goos: linux
goarch: 386
cgo: 0
- goos: linux
goarch: arm
goarm: "7"
cgo: 0
- goos: linux
goarch: mipsle
gomips: softfloat
cgo: 0
- goos: linux
goarch: mips
gomips: softfloat
cgo: 0
- goos: linux
goarch: mips64le
gomips: softfloat
cgo: 0
- goos: linux
goarch: riscv64
cgo: 0
- goos: darwin
goarch: amd64
cgo: 0
- goos: darwin
goarch: arm64
cgo: 0
- goos: windows
goarch: amd64
cgo: 0
- goos: windows
goarch: arm64
cgo: 0
- goos: windows
goarch: 386
cgo: 0
- goos: android
goarch: arm64
cgo: 1
api: 21
- goos: android
goarch: arm
cgo: 1
api: 21
- goos: freebsd
goarch: amd64
cgo: 0
steps:
- name: Check out code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: "1.25.5"
# Install Android NDK only for android rows
- name: Setup Android NDK
if: matrix.goos == 'android'
id: setup-ndk
uses: nttld/setup-ndk@v1
with:
ndk-version: r26d
add-to-path: false
- name: Build
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
GOMIPS: ${{ matrix.gomips }}
GOARM: ${{ matrix.goarm }}
CGO_ENABLED: ${{ matrix.cgo }}
ANDROID_API: ${{ matrix.api }}
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
VERSION: ${{ github.ref_name }}
run: |
echo "Building for $GOOS/$GOARCH${GOARM:+/arm$GOARM} (CGO_ENABLED=$CGO_ENABLED)"
if [ "$GOOS" = "android" ]; then
if [ -z "$ANDROID_NDK_HOME" ]; then
echo "ANDROID_NDK_HOME is not set – did setup-ndk run?"
exit 1
fi
TOOLCHAIN_BIN="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin"
if [ "$GOARCH" = "arm64" ]; then
export CC="$TOOLCHAIN_BIN/aarch64-linux-android${ANDROID_API}-clang"
elif [ "$GOARCH" = "arm" ]; then
export CC="$TOOLCHAIN_BIN/armv7a-linux-androideabi${ANDROID_API}-clang"
else
echo "Unsupported ANDROID GOARCH=$GOARCH"
exit 1
fi
echo "Using Android NDK CC=$CC"
fi
mkdir -p dist
# Set extension for windows
if [ "${GOOS}" = "windows" ]; then
EXT=.exe
else
EXT=
fi
GOOS=$GOOS GOARCH=$GOARCH GOARM=$GOARM GOMIPS=$GOMIPS \
go build -ldflags "-s -w -checklinkname=0" -trimpath \
-o "dist/client-${GOOS}-${GOARCH}${EXT}" \
./client
GOOS=$GOOS GOARCH=$GOARCH GOARM=$GOARM GOMIPS=$GOMIPS \
go build -ldflags "-s -w -checklinkname=0" -trimpath \
-o "dist/server-${GOOS}-${GOARCH}${EXT}" \
./server
- name: Upload artifact
uses: actions/upload-artifact@v6
with:
name: good-turn-${{ matrix.goos }}-${{ matrix.goarch }}
path: dist/**
release:
name: Create GitHub Release
needs: build
runs-on: ubuntu-latest
outputs:
should_release: ${{ steps.meta.outputs.should_release }}
tag_name: ${{ steps.meta.outputs.tag_name }}
permissions:
contents: write
steps:
- name: Check out code
uses: actions/checkout@v6
with:
fetch-depth: 0
fetch-tags: true
- name: Download build artifacts
uses: actions/download-artifact@v7
with:
path: dist
- name: Prepare release metadata
id: meta
run: |
LATEST_TAG="$(git tag -l | grep -E '^(v)?[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1 || true)"
PREFIX=""
BASE_VERSION="$LATEST_TAG"
if [ -z "$LATEST_TAG" ]; then
BASE_VERSION="0.0.0"
elif [ "${LATEST_TAG#v}" != "$LATEST_TAG" ]; then
PREFIX="v"
BASE_VERSION="${LATEST_TAG#v}"
fi
IFS=. read -r MAJOR MINOR PATCH <<< "$BASE_VERSION"
if [ -n "$LATEST_TAG" ]; then
RANGE="$LATEST_TAG..HEAD"
else
RANGE="HEAD"
fi
COMMITS="$(git log --no-merges --format='%s' "$RANGE")"
BUMP=""
if printf '%s\n' "$COMMITS" | grep -Eiq '^break([(:! ]|$)'; then
BUMP="major"
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
elif printf '%s\n' "$COMMITS" | grep -Eiq '^feat([(:! ]|$)'; then
BUMP="minor"
MINOR=$((MINOR + 1))
PATCH=0
elif printf '%s\n' "$COMMITS" | grep -Eiq '^fix([(:! ]|$)'; then
BUMP="patch"
PATCH=$((PATCH + 1))
fi
NEXT_VERSION="${MAJOR}.${MINOR}.${PATCH}"
NEXT_TAG="${PREFIX}${NEXT_VERSION}"
{
echo "previous_tag=$LATEST_TAG"
echo "range=$RANGE"
echo "bump=$BUMP"
echo "should_release=$([ -n "$BUMP" ] && echo true || echo false)"
echo "tag_name=$NEXT_TAG"
echo "release_name=$NEXT_TAG"
echo "body_path=release-notes.md"
} >> "$GITHUB_OUTPUT"
- name: Generate release notes from commit messages
id: notes
if: steps.meta.outputs.should_release == 'true'
env:
PREVIOUS_TAG: ${{ steps.meta.outputs.previous_tag }}
NEXT_TAG: ${{ steps.meta.outputs.tag_name }}
BUMP: ${{ steps.meta.outputs.bump }}
RANGE: ${{ steps.meta.outputs.range }}
run: |
strip_prefix() {
sed -E 's/^(feat|fix|break)([(!:]|[[:space:]])+[[:space:]]*//I'
}
FEATURES="$(git log --no-merges --format='%s (%h)' "$RANGE" | grep -Ei '^feat([(:! ]|$)' | strip_prefix | LC_ALL=C sort -f || true)"
FIXES="$(git log --no-merges --format='%s (%h)' "$RANGE" | grep -Ei '^fix([(:! ]|$)' | strip_prefix | LC_ALL=C sort -f || true)"
BREAKING="$(git log --no-merges --format='%s (%h)' "$RANGE" | grep -Ei '^break([(:! ]|$)' | strip_prefix | LC_ALL=C sort -f || true)"
{
echo "body_path=release-notes.md"
} >> "$GITHUB_OUTPUT"
{
if [ -n "$BREAKING" ]; then
echo "### Breaking Changes"
echo
printf '%s\n' "$BREAKING" | sed 's/^/- /'
echo
fi
if [ -n "$FEATURES" ]; then
echo "### Features"
echo
printf '%s\n' "$FEATURES" | sed 's/^/- /'
echo
fi
if [ -n "$FIXES" ]; then
echo "### Bug Fixes"
echo
printf '%s\n' "$FIXES" | sed 's/^/- /'
echo
fi
} > release-notes.md
- name: Create Release
if: steps.meta.outputs.should_release == 'true'
uses: softprops/action-gh-release@v2
with:
# upload every file in dist/ including nested files
files: |
dist/**
tag_name: ${{ steps.meta.outputs.tag_name }}
target_commitish: ${{ github.sha }}
name: ${{ steps.meta.outputs.release_name }}
body_path: ${{ steps.meta.outputs.body_path }}
overwrite_files: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Skip release when no semantic commit is found
if: steps.meta.outputs.should_release != 'true'
run: |
echo "No new semantic release created."
echo "Add a commit starting with break, feat, or fix after the latest tag."
docker:
name: Publish Docker image
needs: release
if: needs.release.outputs.should_release == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Check out code
uses: actions/checkout@v6
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Prepare image name
id: image
env:
REPOSITORY: ${{ github.repository }}
run: |
echo "name=ghcr.io/$(echo "$REPOSITORY" | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ steps.image.outputs.name }}
tags: |
type=raw,value=latest
type=raw,value=${{ needs.release.outputs.tag_name }}
- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}