-
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathbuild-and-package-application.yml
More file actions
408 lines (362 loc) · 12.4 KB
/
build-and-package-application.yml
File metadata and controls
408 lines (362 loc) · 12.4 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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
---
name: Build and package application
# yamllint disable-line rule:truthy
on:
push:
branches:
- master
pull_request:
types:
- opened
- synchronize
release:
types:
- published
workflow_dispatch: {}
env:
STATIC_EXPORT: "true"
concurrency:
group: ${{ github.workflow }}-${{ github.ref_type == 'tag' && format('tag-{0}', github.ref_name) || github.ref }}
cancel-in-progress: ${{ github.ref_type != 'tag' }}
jobs:
build-linux:
name: Build linux
container:
image: ghcr.io/${{ github.repository }}/ci-build-arch:latest
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Mark workspace safe for git
run: git config --global --add safe.directory .
- name: Setup Go
uses: ./.github/actions/setup-go
- name: Build web client
uses: ./.github/actions/build-client-web
- name: Get version
id: get_version
shell: bash
run: |
if [[ "${{ github.ref_type }}" == "tag" ]]; then
VERSION="${{ github.ref_name }}"
else
VERSION="5.0.0-dev+${{ github.sha }}"
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Write version to file
run: echo "${{ env.VERSION }}" > VERSION
- name: Build application
env:
GOOS: linux
GOARCH: amd64
CGO_ENABLED: 1
run: |
go build -v -ldflags="-X 'github.com/timmo001/system-bridge/version.Version=${{ env.VERSION }}'" -o "system-bridge-linux"
- name: Verify CSS in Linux binary
run: |
chmod +x ./.scripts/verify-css.sh
./.scripts/verify-css.sh ./system-bridge-linux
- name: Upload application
uses: actions/upload-artifact@v6
with:
name: system-bridge-linux-${{ env.VERSION }}
path: system-bridge-linux
package-linux:
name: Package ${{ matrix.build.package }} (${{ matrix.build.distro }})
needs:
- build-linux
container:
image: ghcr.io/${{ github.repository }}/ci-build-${{ matrix.build.distro }}:latest
options: "--privileged --cap-add=SYS_ADMIN --device=/dev/fuse"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
build:
- distro: arch
package: arch
- distro: ubuntu
package: deb
- distro: ubuntu
package: rpm
- distro: ubuntu
package: flatpak
env:
VERSION: ${{ needs.build-linux.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Download application
uses: actions/download-artifact@v7
with:
name: system-bridge-linux-${{ env.VERSION }}
path: .
- name: Package for linux
run: |
echo "::group::Setup"
mkdir -p dist
chmod +x ./system-bridge-linux
chmod +x ./.scripts/linux/create-*.sh
echo "::endgroup::"
echo "::group::List files"
ls -la
echo "::endgroup::"
echo "::group::List scripts"
ls -la ./.scripts/linux/
echo "::endgroup::"
echo "::group::Create ${{ matrix.build.package }} package"
./.scripts/linux/create-${{ matrix.build.package }}.sh
echo "::endgroup::"
echo "::group::List dist"
ls -la dist
echo "::endgroup::"
- name: Upload packages
uses: actions/upload-artifact@v6
with:
name: system-bridge-linux-packages-${{ matrix.build.package }}-${{ env.VERSION }}
path: dist/**
retention-days: ${{ github.ref_type == 'tag' && 90 || 7 }}
build-package-windows:
name: Build and package windows
runs-on: windows-latest
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Download NowPlaying helper
shell: pwsh
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
if: ${{ env.GH_TOKEN != '' }}
run: ./.scripts/windows/download-now-playing.ps1
- name: Setup Go
uses: ./.github/actions/setup-go
- name: Build web client
uses: ./.github/actions/build-client-web
- name: Setup MinGW
uses: egor-tensin/setup-mingw@v3
with:
platform: x64
# https://github.com/egor-tensin/setup-mingw/issues/17#issuecomment-1890253793
version: 12.2.0
- name: Install NSIS
run: choco install nsis -y --no-progress --limit-output
- name: Get version
id: get_version
shell: bash
run: |
if [[ "${{ github.ref_type }}" == "tag" ]]; then
VERSION="${{ github.ref_name }}"
else
VERSION="5.0.0-dev+${{ github.sha }}"
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Generate resource file
run: |
powershell -ExecutionPolicy Bypass -File ./.scripts/windows/generate-rc.ps1
windres system-bridge.rc -O coff -o system-bridge.syso
- name: Build application
env:
GOOS: windows
GOARCH: amd64
CGO_ENABLED: 1
CC: gcc
run: |
go build -v -ldflags="-H windowsgui -X 'github.com/timmo001/system-bridge/version.Version=${{ env.VERSION }}'" -o "system-bridge.exe"
- name: Verify CSS in Windows binary
shell: pwsh
run: |
./.scripts/windows/create-installer.ps1 -VerifyBinaryOnly
- name: Package for Windows
run: |
echo "::group::Setup"
New-Item -ItemType Directory -Force -Path dist | Out-Null
Move-Item system-bridge.exe dist/system-bridge.exe -Force
echo "::endgroup::"
echo "::group::Create installer"
./.scripts/windows/create-installer.ps1
echo "::endgroup::"
echo "::group::List dist"
Get-ChildItem dist -Recurse | Format-Table -AutoSize
echo "::endgroup::"
- name: Upload packages
uses: actions/upload-artifact@v6
with:
name: system-bridge-windows-packages-${{ env.VERSION }}
path: dist/**
retention-days: ${{ github.ref_type == 'tag' && 90 || 7 }}
outputs:
version: ${{ steps.get_version.outputs.version }}
update-aur:
name: Update AUR Package
if: (github.ref == 'refs/heads/master' && github.event_name == 'push') || github.ref_type == 'tag'
container:
image: ghcr.io/${{ github.repository }}/ci-build-arch:latest
runs-on: ubuntu-latest
needs:
- build-linux
env:
VERSION: ${{ needs.build-linux.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Update AUR package
env:
AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
GITHUB_SHA: ${{ github.sha }}
GITHUB_WORKSPACE: ${{ github.workspace }}
VERSION: ${{ env.VERSION }}
run: |
echo "::group::Setup"
if [[ "${{ github.ref_type }}" == "tag" ]]; then
GIT_BUILD="0"
else
GIT_BUILD="1"
fi
export GIT_BUILD
chmod +x .scripts/linux/update-aur.sh
if [ "$(id -u)" -eq 0 ] && id -u builduser >/dev/null 2>&1; then
echo "Switching to builduser..."
chown -R builduser:builduser "$(pwd)"
exec sudo --preserve-env=VERSION,AUR_SSH_PRIVATE_KEY,GITHUB_SHA,GITHUB_WORKSPACE,GIT_BUILD -u builduser -H bash ./.scripts/linux/update-aur.sh
fi
echo "::endgroup::"
echo "::group::Update AUR package"
./.scripts/linux/update-aur.sh
echo "::endgroup::"
- name: Report AUR update status
if: always()
run: |
if [ "${{ job.status }}" == 'success' ]; then
echo "✅ AUR package updated successfully!"
if [[ "${{ github.ref_type }}" == "tag" ]]; then
echo "Package: https://aur.archlinux.org/packages/system-bridge"
else
echo "Package: https://aur.archlinux.org/packages/system-bridge-git"
fi
else
echo "❌ Failed to update AUR package"
echo "Check the logs above for details"
fi
update-release:
name: Update release
if: github.event_name == 'release'
needs:
- build-linux
- package-linux
- build-package-windows
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download linux arch packages
uses: actions/download-artifact@v7
with:
name: system-bridge-linux-packages-arch-${{ needs.build-linux.outputs.version }}
path: dist/linux/arch
- name: Download linux deb packages
uses: actions/download-artifact@v7
with:
name: system-bridge-linux-packages-deb-${{ needs.build-linux.outputs.version }}
path: dist/linux/deb
- name: Download linux rpm packages
uses: actions/download-artifact@v7
with:
name: system-bridge-linux-packages-rpm-${{ needs.build-linux.outputs.version }}
path: dist/linux/rpm
- name: Download linux flatpak packages
uses: actions/download-artifact@v7
with:
name: system-bridge-linux-packages-flatpak-${{ needs.build-linux.outputs.version }}
path: dist/linux/flatpak
- name: Download windows packages
uses: actions/download-artifact@v7
with:
name: system-bridge-windows-packages-${{ needs.build-package-windows.outputs.version }}
path: dist/windows
- name: Update release
uses: softprops/action-gh-release@v2
with:
files: |
dist/linux/arch/*.pkg.tar.zst
dist/linux/deb/*.deb
dist/linux/rpm/*.rpm
dist/linux/flatpak/*.flatpak
dist/windows/*-setup.exe
compute-next-patch:
name: Compute next patch tag
runs-on: ubuntu-latest
needs:
- update-release
if: github.event_name == 'release'
outputs:
next_tag: ${{ steps.compute.outputs.next_tag }}
steps:
- name: Compute next patch tag
id: compute
shell: bash
run: |
set -euo pipefail
PREV_TAG="${{ github.event.release.tag_name }}"
if [[ -z "${PREV_TAG}" ]]; then
echo "Release tag not available in context." >&2
exit 1
fi
echo "Previous tag: ${PREV_TAG}"
NEXT_TAG=""
if [[ "${PREV_TAG}" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)-beta\.([0-9]+)$ ]]; then
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
PATCH="${BASH_REMATCH[3]}"
NEXT_TAG="${MAJOR}.${MINOR}.${PATCH}"
elif [[ "${PREV_TAG}" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
PATCH="${BASH_REMATCH[3]}"
NEXT_PATCH=$((PATCH+1))
NEXT_TAG="${MAJOR}.${MINOR}.${NEXT_PATCH}"
else
# Fallback: strip common prerelease suffix and try to bump patch
CLEAN_TAG="${PREV_TAG%%-*}"
if [[ "${CLEAN_TAG}" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
PATCH="${BASH_REMATCH[3]}"
NEXT_TAG="${MAJOR}.${MINOR}.$((PATCH+1))"
else
NEXT_TAG="${PREV_TAG}"
fi
fi
echo "Next patch tag: ${NEXT_TAG}"
echo "next_tag=${NEXT_TAG}" >> "$GITHUB_OUTPUT"
create-prerelease:
name: Create draft release
runs-on: ubuntu-latest
needs:
- compute-next-patch
if: github.event_name == 'release'
permissions:
contents: write
steps:
- name: Create draft prerelease
uses: softprops/action-gh-release@v2
with:
draft: true
prerelease: false
make_latest: true
name: ${{ needs.compute-next-patch.outputs.next_tag }}
tag_name: ${{ needs.compute-next-patch.outputs.next_tag }}
generate_release_notes: false