-
-
Notifications
You must be signed in to change notification settings - Fork 26
524 lines (435 loc) · 20.5 KB
/
ci.yml
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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
name: CI
on:
push:
pull_request:
types:
- opened
- synchronize
release:
types:
- published
env:
DEBIAN_FRONTEND: noninteractive
CONST_RANDOM_SEED: ${{ secrets.CONST_RANDOM_SEED }}
jobs:
static-analysis:
name: Static analysis
runs-on: ubuntu-latest
timeout-minutes: 15
# Exclude in-repo PRs from running this job
if: github.event_name != 'pull_request' ||
github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
steps:
- name: 📥 Checkout source
uses: actions/checkout@v3
# Necessary due to Tauri macro expectations. See: https://github.com/tauri-apps/tauri/issues/3142
- name: 📁 Create GUI package frontend dist directory
run: mkdir packages/packsquash_gui/dist
- name: 🧰 Install development packages
run: |
sudo apt-get update
sudo apt-get install desktop-file-utils libwebkit2gtk-4.0-dev
- name: 🧰 Install Rust toolchain
uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt, clippy
- name: 🔍 Clippy check
uses: giraffate/clippy-action@v1
if: github.event_name != 'release'
with:
clippy_flags: --all-targets
reporter: github-check
fail_on_error: true
- name: 🔍 ESLint check
working-directory: packages/packsquash_gui
run: |
npm ci
npm run lint
- name: 🔍 Cargo deny check
uses: EmbarkStudios/cargo-deny-action@v1
- name: 🔍 Check PackSquash Linux desktop entries correctness
run: bash -ce 'shopt -s globstar; desktop-file-validate **/*.desktop'
- name: 🔍 Check Rust source code format
run: cargo fmt --all --check
- name: 🔍 Check TypeScript source code format
working-directory: packages/packsquash_gui
run: npm run format
build:
name: Build
strategy:
fail-fast: false
matrix:
target:
- x86_64-unknown-linux-gnu
- x86_64-unknown-linux-musl
- x86_64-pc-windows-gnu
- aarch64-unknown-linux-gnu
- aarch64-unknown-linux-musl
- x86_64-apple-darwin
- aarch64-apple-darwin
include:
- target: x86_64-unknown-linux-gnu
host-target: x86_64-unknown-linux-gnu
rust-toolchain-targets: x86_64-unknown-linux-gnu
appimage-arch: x86_64
runner: ubuntu-latest
container: node:16-bullseye-slim
excluded-workspace-packages: none
apt-arch: amd64
- target: x86_64-unknown-linux-musl
host-target: x86_64-unknown-linux-gnu
rust-toolchain-targets: x86_64-unknown-linux-musl
runner: ubuntu-latest
container: debian:sid-slim
# The GUI dynamically links to system webview components,
# so building it statically does not make sense
excluded-workspace-packages: packsquash_gui
apt-arch: amd64
- target: aarch64-unknown-linux-gnu
host-target: x86_64-unknown-linux-gnu
rust-toolchain-targets: aarch64-unknown-linux-gnu
appimage-arch: aarch64
runner: ubuntu-latest
container: node:16-bullseye-slim
pkg-config-path: /usr/lib/aarch64-linux-gnu/pkgconfig
excluded-workspace-packages: none
apt-arch: arm64
- target: aarch64-unknown-linux-musl
host-target: x86_64-unknown-linux-gnu
rust-toolchain-targets: aarch64-unknown-linux-musl
runner: ubuntu-latest
container: debian:sid-slim
excluded-workspace-packages: packsquash_gui
apt-arch: arm64
- target: x86_64-unknown-linux-musl
host-target: x86_64-unknown-linux-gnu
runner: ubuntu-latest
container: debian:sid-slim
apt-arch: amd64
- target: aarch64-unknown-linux-gnu
host-target: x86_64-unknown-linux-gnu
rust-toolchain-targets: aarch64-unknown-linux-gnu
runner: ubuntu-latest
container: node:16-bullseye-slim
pkg-config-path: /usr/lib/aarch64-linux-gnu/pkgconfig
apt-arch: arm64
appimage-arch: aarch64
- target: aarch64-unknown-linux-musl
host-target: x86_64-unknown-linux-gnu
runner: ubuntu-latest
container: debian:sid-slim
apt-arch: arm64
- target: x86_64-pc-windows-gnu
host-target: x86_64-pc-windows-gnu
runner: windows-latest
excluded-workspace-packages: none
executable-extension: .exe
- target: x86_64-apple-darwin
host-target: x86_64-apple-darwin
rust-toolchain-targets: aarch64-apple-darwin
tauri-target: universal-apple-darwin
runner: macos-latest
excluded-workspace-packages: none
- target: aarch64-apple-darwin
host-target: x86_64-apple-darwin
rust-toolchain-targets: aarch64-apple-darwin
runner: macos-latest
excluded-workspace-packages: none
runs-on: ${{ matrix.runner }}
timeout-minutes: 60
container: ${{ matrix.container }}
env:
CARGO_BUILD_TARGET: ${{ matrix.target }}
RUSTUP_TOOLCHAIN: nightly-${{ matrix.host-target }}
TARGET_APPIMAGE_ARCH: ${{ matrix.appimage-arch }}
TARGET_APPIMAGE_APT_ARCH: ${{ matrix.apt-arch }}
PKG_CONFIG_ALLOW_CROSS: 1
PKG_CONFIG_PATH: ${{ matrix.pkg-config-path }}
# Exclude in-repo PRs from running this job
if: github.event_name != 'pull_request' ||
github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
steps:
- name: 🧰 Install Linux toolchain packages
if: contains(matrix.target, '-linux-')
run: |
apt-get update
# curl is required by rustup and Tauri.
# markdown and html2text are required to generate the Debian package only.
# The third line contains packages necessary for appimage-builder only.
# The fourth line contains packages necessary for Tauri.
# The fifth line contains packages necessary for build-time JSON Schema generation
# and the packsquash package build script
apt-get install -yq build-essential musl-tools git curl \
markdown html2text \
python3-venv file zsync desktop-file-utils gtk-update-icon-cache fakeroot squashfs-tools gstreamer1.0-tools \
libwebkit2gtk-4.0-dev:${{ matrix.apt-arch }} \
jq zlib1g-dev
# The GitHub Windows and macOS images already have jq, git and the build-essential equivalents installed,
# so we don't need to install them explicitly. However, that may not be the case in different environments
- name: 🧰 Install Linux ARM64 cross-compilation toolchain
if: startsWith(matrix.target, 'aarch64-unknown-linux')
run: |
dpkg --add-architecture arm64
apt-get update
# libgcc-s1:arm64 is a dependency of libc6:arm64 that Aptitude
# installs as usual, but for some reason the latest sid-slim image
# as of 2023-06-13 refers to broken repositories or packages where
# apt-get install fails
apt-get install -yq gcc-aarch64-linux-gnu qemu-user libc6:arm64 libgcc-s1:arm64
# As of 2023-05-24, only the Debian unstable musl-dev ARM64 package ships with an
# aarch64-linux-musl-gcc script that wraps the aarch64-linux-gnu-gcc cross-compiler
# provided by the gcc-aarch64-linux-gnu package to link against musl
- name: 🧰 Install Linux ARM64 cross-compilation musl development files
if: matrix.target == 'aarch64-unknown-linux-musl'
run: apt-get install -yq musl-dev:arm64
- name: 🧰 Install Rust toolchain
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly-${{ matrix.host-target }}
targets: ${{ env.CARGO_BUILD_TARGET }}
components: rust-src
- name: 💨 Cache Rust artifacts
uses: Swatinem/rust-cache@v2
- name: 🧰 Install nextest
if: startsWith(matrix.target, 'x86_64-') || contains(matrix.target, '-linux-')
uses: taiki-e/install-action@v2
with:
tool: nextest
- name: 🧰 Install cargo-deb
if: endsWith(matrix.target, '-linux-gnu')
uses: taiki-e/install-action@v2
with:
tool: cargo-deb
- name: 🧰 Install tauri-cli
if: matrix.tauri-target != ''
uses: taiki-e/install-action@v2
with:
crate: tauri-cli
# Debian Bullseye distributes a too old Node.js version, so set up a more modern one externally
- name: 🧰 Install Node.js
if: endsWith(matrix.target, '-linux-gnu')
uses: actions/setup-node@v3
with:
node-version: latest
cache: npm
cache-dependency-path: packages/packsquash_gui/package-lock.json
- name: 📥 Checkout source
uses: actions/checkout@v3
with:
fetch-depth: 0 # Keep the commit history for proper version information
# Necessary for steps that invoke Git commands to work properly on workflows run on containers.
# See: https://github.com/actions/checkout/issues/766
- name: 📥 Set source ownership to current user
if: startsWith(matrix.runner, 'ubuntu')
run: chown -R "$(id -u):$(id -g)" "$GITHUB_WORKSPACE"
# Necessary due to Tauri macro expectations. See: https://github.com/tauri-apps/tauri/issues/3142
- name: 📁 Create GUI package frontend dist directory
run: mkdir packages/packsquash_gui/dist
# Our build container is minimal, and it doesn't contain any systemd package.
# systemd is responsible for setting up the machine ID files we use for
# testing the system ID retrieval code, so copy a dummy one
- name: 📏 Set up a dummy D-Bus machine ID for tests
if: startsWith(matrix.runner, 'ubuntu')
run: cat /proc/sys/kernel/random/uuid | tr -d '-' > /run/machine-id
# The default npm cache directory resides at the home directory. Because our Linux
# jobs run on containers, that directory is bind-mounted from the host runner, which
# is owned by an unprivileged user. Change the cache directory to be within the container
# to avoid permission issues
- name: 📏 Change npm cache directory to one with appropriate permissions
if: startsWith(matrix.runner, 'ubuntu') && !endsWith(matrix.target, '-musl')
run: npm config --global set cache /tmp/.npm
- name: 📥 Checkout source
uses: actions/checkout@v3
with:
fetch-depth: 0 # Keep the commit history for proper version information
# Necessary due to Tauri macro expectations. See: https://github.com/tauri-apps/tauri/issues/3142
- name: 📁 Create GUI package frontend dist directory
run: mkdir packages/packsquash_gui/dist
# We can only run tests if the target architecture matches the host architecture,
# or if the target (and therefore host) OS is Linux, as we can leverage QEMU there
- name: ✔️ Run tests
if: startsWith(matrix.target, 'x86_64-') || contains(matrix.target, '-linux-')
run: |
cargo nextest run --release --workspace --exclude '${{ matrix.excluded-workspace-packages }}'
cargo test --doc --release --workspace --exclude '${{ matrix.excluded-workspace-packages }}'
- name: 🔨 Build with optimized standard library
run: cargo rbuild --target ${{ matrix.target }} --workspace --exclude '${{ matrix.excluded-workspace-packages }}'
- name: 🔨 Build GUI frontend
if: matrix.tauri-target == '' && !endsWith(matrix.target, '-musl')
working-directory: packages/packsquash_gui
run: |
npm ci
npm run build
- name: 🔨 Build GUI frontend, installers and updater artifacts
if: matrix.tauri-target != ''
working-directory: packages/packsquash_gui
env:
TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
run: |
npm ci
cargo tauri build --target ${{ matrix.tauri-target }} -- -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort
- name: 🔨 Generate CLI Debian package
if: endsWith(matrix.target, '-linux-gnu')
run: packages/packsquash_cli/bundles/deb/build.sh --target ${{ env.CARGO_BUILD_TARGET }}
- name: 🔨 Generate GUI Debian package
if: endsWith(matrix.target, '-linux-gnu')
run: packages/packsquash_gui/src-tauri/bundles/deb/build.sh --target ${{ env.CARGO_BUILD_TARGET }}
- name: 🔨 Generate GUI AppImage
if: endsWith(matrix.target, '-linux-gnu')
run: packages/packsquash_gui/src-tauri/bundles/appimage/build.sh
- name: 🔨 Generate multilingual GUI MSI installer
if: startsWith(matrix.runner, 'windows')
run: packages/packsquash_gui/src-tauri/bundles/wix/build_multilingual_installer.ps1
- name: 📤 Upload CLI binary
if: ${{ !contains(matrix.target, '-linux-') || endsWith(matrix.target, '-linux-musl') }}
uses: actions/upload-artifact@v3
with:
name: PackSquash CLI executable (${{ matrix.target }})
path: target/${{ env.CARGO_BUILD_TARGET }}/release/packsquash${{ matrix.executable-extension }}
- name: 📤 Upload CLI Debian package
if: endsWith(matrix.target, '-linux-gnu')
uses: actions/upload-artifact@v3
with:
name: PackSquash CLI Debian package (${{ matrix.apt-arch }})
path: target/${{ env.CARGO_BUILD_TARGET }}/debian/packsquash_*.deb
- name: 📤 Upload GUI Debian package
if: endsWith(matrix.target, '-linux-gnu')
uses: actions/upload-artifact@v3
with:
name: PackSquash GUI Debian package (${{ matrix.apt-arch }})
path: target/${{ env.CARGO_BUILD_TARGET }}/debian/packsquash-gui_*.deb
- name: 📤 Upload GUI AppImage
if: endsWith(matrix.target, '-linux-gnu')
uses: actions/upload-artifact@v3
with:
name: PackSquash GUI AppImage (${{ matrix.appimage-arch }})
path: target/appimage/PackSquash (GUI)-*-${{ matrix.appimage-arch }}.AppImage
- name: 📤 Upload GUI AppImage update diff
if: endsWith(matrix.target, '-linux-gnu')
uses: actions/upload-artifact@v3
with:
name: PackSquash GUI AppImage zsync (${{ matrix.appimage-arch }})
path: target/appimage/PackSquash (GUI)-*-${{ matrix.appimage-arch }}.AppImage.zsync
- name: 📤 Upload GUI MSI installer
if: startsWith(matrix.runner, 'windows')
uses: actions/upload-artifact@v3
with:
name: PackSquash GUI MSI installer (${{ matrix.target }})
path: target/${{ env.CARGO_BUILD_TARGET }}/release/bundle/msi/PackSquash_*_x64.msi
- name: 📤 Upload GUI MSI update bundle
if: startsWith(matrix.runner, 'windows')
uses: actions/upload-artifact@v3
with:
name: PackSquash GUI MSI update bundle (${{ matrix.target }})
path: target/${{ env.CARGO_BUILD_TARGET }}/release/bundle/msi/PackSquash_*_x64_en-US.msi.zip
- name: 📤 Upload GUI MSI update bundle signature
if: startsWith(matrix.runner, 'windows')
uses: actions/upload-artifact@v3
with:
name: PackSquash GUI MSI update bundle signature (${{ matrix.target }})
path: target/${{ env.CARGO_BUILD_TARGET }}/release/bundle/msi/PackSquash_*_x64_en-US.msi.zip.sig
- name: 📤 Upload GUI Apple Disk Image
if: startsWith(matrix.runner, 'macos') && matrix.tauri-target != ''
uses: actions/upload-artifact@v3
with:
name: PackSquash GUI Apple Disk Image (${{ matrix.tauri-target }})
path: target/${{ matrix.tauri-target }}/release/bundle/dmg/PackSquash_*.dmg
- name: 📤 Upload GUI macOS update bundle
if: startsWith(matrix.runner, 'macos') && matrix.tauri-target != ''
uses: actions/upload-artifact@v3
with:
name: PackSquash GUI macOS update bundle (${{ matrix.tauri-target }})
path: target/${{ matrix.tauri-target }}/release/bundle/macos/PackSquash.app.tar.gz
- name: 📤 Upload GUI macOS update bundle signature
if: startsWith(matrix.runner, 'macos') && matrix.tauri-target != ''
uses: actions/upload-artifact@v3
with:
name: PackSquash GUI macOS update bundle signature (${{ matrix.tauri-target }})
path: target/${{ matrix.tauri-target }}/release/bundle/macos/PackSquash.app.tar.gz.sig
build-universal-macos-binaries:
name: Build universal macOS binaries
runs-on: macos-latest
needs: build
steps:
- name: 📥 Download PackSquash CLI x64 macOS executable
uses: actions/download-artifact@v3
with:
name: PackSquash CLI executable (x86_64-apple-darwin)
path: packsquash-x64
- name: 📥 Download PackSquash CLI ARM64 macOS executable
uses: actions/download-artifact@v3
with:
name: PackSquash CLI executable (aarch64-apple-darwin)
path: packsquash-aarch64
- name: 🔨 Generate universal CLI binary
run: lipo -create -output packsquash packsquash-x64/packsquash packsquash-aarch64/packsquash
- name: 📤 Upload universal CLI binary
uses: actions/upload-artifact@v3
with:
name: PackSquash CLI executable (universal-apple-darwin)
path: packsquash
build-docker-images:
name: Build Docker images
runs-on: ubuntu-latest
env:
# Defaults to docker.io (Docker Hub)
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
needs: build
steps:
- name: 📥 Checkout source
uses: actions/checkout@v3
- name: 🧰 Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: ⚙️ Generate Docker image metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Tag the image as "edge" for every commit on master.
# Tag the image by its ref for every commit on non-master branches.
# Maintain the "latest", full and major and minor semver tags for each semver tag push
tags: |
type=edge,branch=master
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=ref,event=branch
labels: |
org.opencontainers.image.description=Docker image for PackSquash, the Minecraft resource and data pack optimizer.
- name: 📥 Download PackSquash CLI x64 musl executable
uses: actions/download-artifact@v3
with:
name: PackSquash CLI executable (x86_64-unknown-linux-musl)
- name: 📁 Rename PackSquash CLI x64 musl executable
run: mv packsquash packsquash-amd64
- name: 📥 Download PackSquash CLI ARM64 musl executable
uses: actions/download-artifact@v3
with:
name: PackSquash CLI executable (aarch64-unknown-linux-musl)
- name: 📁 Rename PackSquash CLI ARM64 musl executable
run: mv packsquash packsquash-arm64
- name: 🔍 Check workflow package write permission
id: check_write_permission
uses: assaferan/action-has-permission@3d96069159254de543039461dc5a9c20fadbd6e6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# The GitHub token needs the package:write permission for the push to work.
# This permission is not given to PRs from forked repositories.
# See: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
- name: ⚙️ Login to ${{ env.REGISTRY }}
uses: docker/login-action@v2
if: steps.check_write_permission.outputs.has-permission
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 🔨 Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ steps.check_write_permission.outputs.has-permission == '1' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}