-
Notifications
You must be signed in to change notification settings - Fork 1
445 lines (398 loc) · 16.3 KB
/
zig-release.yml
File metadata and controls
445 lines (398 loc) · 16.3 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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
name: Zig Release
on:
workflow_call:
inputs:
binary_name:
description: Binary name produced under zig-out/bin.
required: true
type: string
artifact_prefix:
description: Prefix for release artifact names.
required: false
type: string
default: ""
zig_version:
description: Zig version to install.
required: false
type: string
default: "0.16.0"
android_api_level:
description: Android API level for Android targets.
required: false
type: string
default: "24"
android_ndk_version:
description: Android NDK version for Android targets.
required: false
type: string
default: "29.0.14206865"
targets_json:
description: JSON array of release target matrix entries.
required: false
type: string
default: >-
[
{"os":"ubuntu-latest","target":"linux-x86_64","zig_target":"x86_64-linux-musl","zig_cpu":"","ext":""},
{"os":"ubuntu-latest","target":"linux-aarch64","zig_target":"aarch64-linux-musl","zig_cpu":"","ext":""},
{"os":"ubuntu-latest","target":"linux-arm32-gnu","zig_target":"arm-linux-gnueabihf","zig_cpu":"","ext":""},
{"os":"ubuntu-latest","target":"linux-arm32-musl","zig_target":"arm-linux-musleabihf","zig_cpu":"","ext":""},
{"os":"ubuntu-latest","target":"linux-riscv64","zig_target":"riscv64-linux-musl","zig_cpu":"","ext":""},
{"os":"ubuntu-latest","target":"android-aarch64","zig_target":"aarch64-linux-android","zig_cpu":"","ext":""},
{"os":"ubuntu-latest","target":"android-armv7","zig_target":"arm-linux-androideabi","zig_cpu":"baseline+v7a","ext":""},
{"os":"ubuntu-latest","target":"android-x86_64","zig_target":"x86_64-linux-android","zig_cpu":"","ext":""},
{"os":"macos-latest","target":"macos-aarch64","zig_target":"aarch64-macos","zig_cpu":"","ext":""},
{"os":"macos-latest","target":"macos-x86_64","zig_target":"x86_64-macos","zig_cpu":"","ext":""},
{"os":"windows-latest","target":"windows-x86_64","zig_target":"x86_64-windows","zig_cpu":"","ext":".exe"},
{"os":"windows-latest","target":"windows-aarch64","zig_target":"aarch64-windows","zig_cpu":"","ext":".exe"}
]
node_version:
description: Optional Node.js version to install before custom commands.
required: false
type: string
default: ""
node_cache_dependency_path:
description: Optional npm dependency path for setup-node caching.
required: false
type: string
default: ""
pre_build_command:
description: Optional command run before each ReleaseSmall build. BUILD_VERSION is available.
required: false
type: string
default: ""
build_args:
description: Extra arguments appended to zig build.
required: false
type: string
default: ""
source_archive:
description: Build and attach a source archive.
required: false
type: boolean
default: false
source_prepare_command:
description: Optional command run before creating the source archive. BUILD_VERSION is available.
required: false
type: string
default: ""
source_archive_name:
description: Source archive filename. Defaults to artifact-prefix-source-${GITHUB_REF_NAME}.tar.gz.
required: false
type: string
default: ""
source_archive_excludes:
description: Newline-separated tar exclude patterns for source archives.
required: false
type: string
default: |
.git
.zig-cache
zig-out
generate_release_notes:
description: Generate GitHub release notes.
required: false
type: boolean
default: true
publish_docker:
description: Build and push ghcr.io image on tag releases.
required: false
type: boolean
default: false
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
jobs:
build:
name: Build (${{ matrix.target }})
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(inputs.targets_json) }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Install Zig
uses: nullclaw/nullbuilder/.github/actions/setup-zig@v1
with:
version: ${{ inputs.zig_version }}
- name: Set up Node.js
if: inputs.node_version != '' && inputs.node_cache_dependency_path == ''
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: ${{ inputs.node_version }}
- name: Set up Node.js with npm cache
if: inputs.node_version != '' && inputs.node_cache_dependency_path != ''
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: ${{ inputs.node_version }}
cache: npm
cache-dependency-path: ${{ inputs.node_cache_dependency_path }}
- name: Resolve build version
id: version
run: |
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
echo "value=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
else
echo "value=dev" >> "$GITHUB_OUTPUT"
fi
- name: Resolve artifact prefix
id: artifact
run: |
artifact_prefix="${{ inputs.artifact_prefix }}"
if [ -z "${artifact_prefix}" ]; then
artifact_prefix="${{ inputs.binary_name }}"
fi
echo "prefix=${artifact_prefix}" >> "$GITHUB_OUTPUT"
- name: Set up JDK 17
if: startsWith(matrix.target, 'android-')
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
distribution: temurin
java-version: '17'
- name: Set up Android SDK
if: startsWith(matrix.target, 'android-')
uses: android-actions/setup-android@40fd30fb8d7440372e1316f5d1809ec01dcd3699 # v4.0.1
with:
packages: ''
- name: Install Android NDK
if: startsWith(matrix.target, 'android-')
env:
ANDROID_NDK_VERSION: ${{ inputs.android_ndk_version }}
run: sdkmanager --install "ndk;${ANDROID_NDK_VERSION}"
- name: Export Android NDK paths
if: startsWith(matrix.target, 'android-')
env:
ANDROID_API_LEVEL: ${{ inputs.android_api_level }}
ANDROID_NDK_VERSION: ${{ inputs.android_ndk_version }}
run: |
NDK_ROOT="${ANDROID_SDK_ROOT}/ndk/${ANDROID_NDK_VERSION}"
SYSROOT="${NDK_ROOT}/toolchains/llvm/prebuilt/linux-x86_64/sysroot"
LIBC_FILE="$RUNNER_TEMP/android-libc-${{ matrix.target }}.txt"
echo "ANDROID_NDK_ROOT=${NDK_ROOT}" >> "$GITHUB_ENV"
echo "ZIG_ANDROID_SYSROOT=${SYSROOT}" >> "$GITHUB_ENV"
echo "ZIG_ANDROID_LIBC_FILE=${LIBC_FILE}" >> "$GITHUB_ENV"
cat > "${LIBC_FILE}" <<EOF
include_dir=${SYSROOT}/usr/include/${{ matrix.zig_target }}
sys_include_dir=${SYSROOT}/usr/include
crt_dir=${SYSROOT}/usr/lib/${{ matrix.zig_target }}/${ANDROID_API_LEVEL}
msvc_lib_dir=
kernel32_lib_dir=
gcc_dir=
EOF
- name: Run pre-build command
if: inputs.pre_build_command != ''
env:
BUILD_VERSION: ${{ steps.version.outputs.value }}
PRE_BUILD_COMMAND: ${{ inputs.pre_build_command }}
run: bash -euo pipefail -c "$PRE_BUILD_COMMAND"
- name: Build ReleaseSmall
env:
ANDROID_API_LEVEL: ${{ inputs.android_api_level }}
EXTRA_BUILD_ARGS: ${{ inputs.build_args }}
run: |
zig_target="${{ matrix.zig_target }}"
if [[ "${{ matrix.target }}" == android-* ]]; then
zig_target="${zig_target}.${ANDROID_API_LEVEL}"
fi
zig_args=(
-Doptimize=ReleaseSmall
-Dtarget=${zig_target}
-Dversion=${{ steps.version.outputs.value }}
)
if [ -n "${{ matrix.zig_cpu }}" ]; then
zig_args+=(-Dcpu=${{ matrix.zig_cpu }})
fi
if [[ "${{ matrix.target }}" == android-* ]]; then
zig_args+=(--libc "${ZIG_ANDROID_LIBC_FILE}")
fi
if [ -n "${EXTRA_BUILD_ARGS}" ]; then
read -r -a extra_args <<< "${EXTRA_BUILD_ARGS}"
zig_args+=("${extra_args[@]}")
fi
zig build "${zig_args[@]}"
- name: Upload artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: ${{ steps.artifact.outputs.prefix }}-${{ matrix.target }}
path: zig-out/bin/${{ inputs.binary_name }}${{ matrix.ext }}
source:
name: Prepare source archive
if: inputs.source_archive
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Set up Node.js
if: inputs.node_version != '' && inputs.node_cache_dependency_path == ''
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: ${{ inputs.node_version }}
- name: Set up Node.js with npm cache
if: inputs.node_version != '' && inputs.node_cache_dependency_path != ''
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: ${{ inputs.node_version }}
cache: npm
cache-dependency-path: ${{ inputs.node_cache_dependency_path }}
- name: Resolve source version
id: version
run: |
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
echo "value=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
else
echo "value=dev" >> "$GITHUB_OUTPUT"
fi
- name: Resolve artifact prefix
id: artifact
run: |
artifact_prefix="${{ inputs.artifact_prefix }}"
if [ -z "${artifact_prefix}" ]; then
artifact_prefix="${{ inputs.binary_name }}"
fi
echo "prefix=${artifact_prefix}" >> "$GITHUB_OUTPUT"
- name: Run source prepare command
if: inputs.source_prepare_command != ''
env:
BUILD_VERSION: ${{ steps.version.outputs.value }}
SOURCE_PREPARE_COMMAND: ${{ inputs.source_prepare_command }}
run: bash -euo pipefail -c "$SOURCE_PREPARE_COMMAND"
- name: Create source archive
env:
RAW_ARCHIVE_NAME: ${{ inputs.source_archive_name }}
SOURCE_ARCHIVE_EXCLUDES: ${{ inputs.source_archive_excludes }}
ARTIFACT_PREFIX: ${{ steps.artifact.outputs.prefix }}
run: |
archive_name="${RAW_ARCHIVE_NAME}"
if [ -z "${archive_name}" ]; then
archive_name="${ARTIFACT_PREFIX}-source-${GITHUB_REF_NAME}.tar.gz"
fi
tar_args=()
while IFS= read -r pattern; do
[ -n "${pattern}" ] || continue
tar_args+=("--exclude=${pattern}")
done <<< "${SOURCE_ARCHIVE_EXCLUDES}"
tar "${tar_args[@]}" -czf "/tmp/${archive_name}" .
mv "/tmp/${archive_name}" .
echo "archive_name=${archive_name}" >> "$GITHUB_ENV"
- name: Upload source archive
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: ${{ steps.artifact.outputs.prefix }}-source
path: ${{ env.archive_name }}
release:
needs: [build, source]
if: always() && github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') && needs.build.result == 'success' && (needs.source.result == 'success' || needs.source.result == 'skipped')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
- name: Prepare release assets
env:
BINARY_NAME: ${{ inputs.binary_name }}
RAW_ARTIFACT_PREFIX: ${{ inputs.artifact_prefix }}
run: |
set -euo pipefail
shopt -s nullglob
artifact_prefix="${RAW_ARTIFACT_PREFIX}"
if [ -z "${artifact_prefix}" ]; then
artifact_prefix="${BINARY_NAME}"
fi
mkdir -p release-output release-zips
for artifact_dir in "${artifact_prefix}"-*; do
[ -d "${artifact_dir}" ] || continue
if [[ "${artifact_dir}" == "${artifact_prefix}-source" ]]; then
cp "${artifact_dir}"/*.tar.gz release-output/
continue
fi
target="${artifact_dir#${artifact_prefix}-}"
if [[ "${target}" == windows-* ]]; then
cp "${artifact_dir}/${BINARY_NAME}.exe" "release-output/${artifact_prefix}-${target}.exe"
else
cp "${artifact_dir}/${BINARY_NAME}" "release-output/${artifact_prefix}-${target}.bin"
fi
done
for exe in release-output/"${artifact_prefix}"-windows-*.exe; do
[ -f "${exe}" ] || continue
file_name="$(basename "${exe}")"
target="${file_name%.exe}"
target="${target#${artifact_prefix}-}"
mkdir -p "release-zips/${target}"
cp "${exe}" "release-zips/${target}/${BINARY_NAME}.exe"
(
cd "release-zips/${target}"
zip -9 "../../release-output/${artifact_prefix}-${target}.zip" "${BINARY_NAME}.exe"
)
done
if ! compgen -G "release-output/*" >/dev/null; then
echo "no release assets were prepared" >&2
exit 1
fi
- name: Check whether release already exists
id: release_exists
env:
GH_TOKEN: ${{ github.token }}
run: |
if gh release view "${GITHUB_REF_NAME}" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1; then
echo "value=true" >> "$GITHUB_OUTPUT"
else
echo "value=false" >> "$GITHUB_OUTPUT"
fi
- name: Create GitHub release
if: steps.release_exists.outputs.value != 'true'
uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3.0.0
with:
files: release-output/*
generate_release_notes: ${{ inputs.generate_release_notes }}
- name: Update existing release assets
if: steps.release_exists.outputs.value == 'true'
uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3.0.0
with:
files: release-output/*
docker:
needs: release
if: inputs.publish_docker && github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Set up QEMU
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4
- name: Log in to ghcr.io
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ github.token }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf # v6
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{raw}}
type=raw,value=latest
- name: Resolve docker version
id: docker_version
run: echo "value=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
- name: Build and push
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
build-args: |
VERSION=${{ steps.docker_version.outputs.value }}
ZIG_VERSION=${{ inputs.zig_version }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max