-
Notifications
You must be signed in to change notification settings - Fork 5
232 lines (208 loc) · 7.24 KB
/
release.yml
File metadata and controls
232 lines (208 loc) · 7.24 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
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "Target release tag (e.g., v0.2.2). Binaries and Docker image are published to this release."
required: true
from_master:
description: "Build from master instead of the tag's code"
type: boolean
default: false
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
resolve:
runs-on: ubuntu-latest
outputs:
build_ref: ${{ steps.refs.outputs.build_ref }}
release_tag: ${{ steps.refs.outputs.release_tag }}
docker_tags: ${{ steps.refs.outputs.docker_tags }}
steps:
- name: Resolve refs
id: refs
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="${{ inputs.tag }}"
if [ "${{ inputs.from_master }}" = "true" ]; then
echo "build_ref=master" >> "$GITHUB_OUTPUT"
else
echo "build_ref=${TAG}" >> "$GITHUB_OUTPUT"
fi
echo "release_tag=${TAG}" >> "$GITHUB_OUTPUT"
VERSION="${TAG#v}"
MAJOR="${VERSION%%.*}"
MINOR="${VERSION#*.}"; MINOR="${MINOR%%.*}"
echo "docker_tags<<EOF" >> "$GITHUB_OUTPUT"
echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG}" >> "$GITHUB_OUTPUT"
echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:v${MAJOR}.${MINOR}" >> "$GITHUB_OUTPUT"
echo "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:v${MAJOR}" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
else
TAG="${GITHUB_REF#refs/tags/}"
echo "build_ref=${GITHUB_REF}" >> "$GITHUB_OUTPUT"
echo "release_tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "docker_tags=" >> "$GITHUB_OUTPUT"
fi
binaries:
needs: resolve
strategy:
fail-fast: false
matrix:
include:
- goos: linux
goarch: amd64
runner: ubuntu-latest
- goos: linux
goarch: arm64
runner: ubuntu-latest
cross: true
zig_target: aarch64-linux-gnu
- goos: darwin
goarch: arm64
runner: macos-latest
- goos: windows
goarch: amd64
runner: ubuntu-latest
cross: true
zig_target: x86_64-windows-gnu
runs-on: ${{ matrix.runner }}
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.resolve.outputs.build_ref }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Build frontend
run: |
cd frontend/admin-ui && npm install --silent && npx vite build && cd ../..
cd frontend/voice-ui && npm install --silent && npx vite build && cd ../..
rm -rf server/frontend/admin-ui && cp -r frontend/admin-ui/dist server/frontend/admin-ui
rm -rf server/frontend/voice-ui && cp -r frontend/voice-ui/dist server/frontend/voice-ui
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: server/go.mod
cache-dependency-path: server/go.sum
- name: Embed models
run: |
go run scripts/download-model.go
rm -rf server/models/wakeword server/models/auxiliary
cp -r models/wakeword server/models/wakeword
cp -r models/auxiliary server/models/auxiliary
- name: Setup Zig
if: matrix.cross
uses: mlugg/setup-zig@v2
with:
version: 0.14.1
- name: Create zig wrapper scripts
if: matrix.cross
run: |
mkdir -p /tmp/zigcc
printf '#!/bin/sh\nexec zig cc -target %s "$@"\n' "${{ matrix.zig_target }}" > /tmp/zigcc/zcc
printf '#!/bin/sh\nexec zig c++ -target %s "$@"\n' "${{ matrix.zig_target }}" > /tmp/zigcc/zxx
chmod +x /tmp/zigcc/zcc /tmp/zigcc/zxx
- name: Build binary
working-directory: server
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: "1"
CC: ${{ matrix.cross && '/tmp/zigcc/zcc' || '' }}
CXX: ${{ matrix.cross && '/tmp/zigcc/zxx' || '' }}
run: |
EXT=""
if [ "${{ matrix.goos }}" = "windows" ]; then EXT=".exe"; fi
go build -trimpath -ldflags="-s -w" -o ../magec-${{ matrix.goos }}-${{ matrix.goarch }}${EXT} .
- name: Package
run: |
GOOS="${{ matrix.goos }}"
GOARCH="${{ matrix.goarch }}"
NAME="magec-${GOOS}-${GOARCH}"
mkdir -p dist
if [ "$GOOS" = "windows" ]; then
cp "magec-${GOOS}-${GOARCH}.exe" dist/magec.exe
else
cp "magec-${GOOS}-${GOARCH}" dist/magec
fi
cp config.example.yaml dist/
if [ "$GOOS" = "windows" ]; then
cd dist && zip -r "../${NAME}.zip" . && cd ..
else
tar czf "${NAME}.tar.gz" -C dist .
fi
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: magec-${{ matrix.goos }}-${{ matrix.goarch }}
path: magec-${{ matrix.goos }}-${{ matrix.goarch }}.*
docker:
needs: resolve
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.resolve.outputs.build_ref }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tag push)
if: github.event_name == 'push'
id: meta_push
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern=v{{version}}
type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern=v{{major}}
type=sha
- name: Build and push image
uses: docker/build-push-action@v5
with:
context: .
file: docker/build/Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ github.event_name == 'push' && steps.meta_push.outputs.tags || needs.resolve.outputs.docker_tags }}
labels: ${{ steps.meta_push.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
release:
runs-on: ubuntu-latest
needs: [resolve, binaries, docker]
permissions:
contents: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Upload assets to GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release upload --repo "${{ github.repository }}" \
"${{ needs.resolve.outputs.release_tag }}" \
artifacts/*.tar.gz artifacts/*.zip --clobber