Repository navigation
1004 lines (882 loc) · 38.8 KB
/
Copy pathrelease.yml
File metadata and controls
1004 lines (882 loc) · 38.8 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
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
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
name: Release
on:
push:
tags:
- "v*"
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
jobs:
build-platforms:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
runner: ubuntu-22.04
bundles: appimage
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24
cache: pnpm
- name: Install Linux dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
curl \
file \
libayatana-appindicator3-dev \
libfuse2 \
libssl-dev \
librsvg2-dev \
libwebkit2gtk-4.1-dev \
libxdo-dev \
patchelf \
wget
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Update version from tag
shell: bash
run: |
set -euo pipefail
VERSION="${GITHUB_REF_NAME#v}"
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
pkg.version = '${VERSION}';
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
const confPath = 'src-tauri/tauri.conf.json';
const conf = JSON.parse(fs.readFileSync(confPath, 'utf8'));
conf.version = '${VERSION}';
fs.writeFileSync(confPath, JSON.stringify(conf, null, 2) + '\n');
"
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Rust cache
uses: swatinem/rust-cache@v2
with:
workspaces: |
src-tauri -> target
- name: Build bundles and updater artifacts
env:
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
run: pnpm tauri build --target "${{ matrix.target }}" --bundles "${{ matrix.bundles }}" --ignore-version-mismatches
- name: Upload platform bundles
uses: actions/upload-artifact@v4
with:
name: platform-bundles-${{ matrix.target }}
path: target/${{ matrix.target }}/release/bundle/**/*
if-no-files-found: error
retention-days: 1
build-android:
name: Build Android release APKs
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24
cache: pnpm
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
- name: Setup Android SDK
uses: android-actions/setup-android@v4
with:
# Override the action default: Google delisted the deprecated `tools`
# package, so requesting it makes sdkmanager exit 1 (android-actions/setup-android#537).
packages: 'platform-tools'
- name: Install Android SDK and NDK
shell: bash
run: |
set -euo pipefail
sdkmanager "platforms;android-36" "build-tools;36.0.0" "ndk;27.2.12479018"
echo "NDK_HOME=${ANDROID_HOME}/ndk/27.2.12479018" >> "${GITHUB_ENV}"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Update version from tag
shell: bash
run: |
set -euo pipefail
VERSION="${GITHUB_REF_NAME#v}"
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
pkg.version = '${VERSION}';
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
const confPath = 'src-tauri/tauri.conf.json';
const conf = JSON.parse(fs.readFileSync(confPath, 'utf8'));
conf.version = '${VERSION}';
fs.writeFileSync(confPath, JSON.stringify(conf, null, 2) + '\n');
"
# Only the two ABIs that ship as separate APKs. Dropping armv7/i686 removes
# 32-bit support from the Android release; keeping them would mean four
# splits, and the 32-bit ones are what forced the old universal bundle to
# carry ~52 MB of extra native libraries. Re-add armv7-linux-androideabi /
# i686-linux-android here and to the `--target` list below if 32-bit
# devices have to be supported again.
- name: Setup Rust Android targets
uses: dtolnay/rust-toolchain@stable
with:
targets: aarch64-linux-android, x86_64-linux-android
- name: Rust cache
uses: swatinem/rust-cache@v2
with:
workspaces: |
src-tauri -> target
- name: Initialize Android project
run: pnpm tauri android init --ci
# `android init` scaffolds `gen/android` from the CLI template, which ships
# its own placeholder launcher artwork (the blue/yellow mark) and no
# adaptive-icon descriptor at all. Nothing else copies the project icons in,
# so without this step the released APK keeps the template icon. The tracked
# set under `src-tauri/icons/android/` is the one that has been scaled into
# the 66dp adaptive safe zone, so install it verbatim instead of regenerating
# it from `icon.png` (which would push the glyph back past the mask).
- name: Install project launcher icons
shell: bash
run: |
set -euo pipefail
RES="src-tauri/gen/android/app/src/main/res"
if [[ ! -d "${RES}" ]]; then
echo "::error::${RES} is missing; 'tauri android init' did not scaffold the project."
exit 1
fi
# Drop the template's launcher artwork (density PNGs, the adaptive-icon
# descriptor, and the vector drawables it referenced) so nothing from the
# scaffold can win resource resolution, then install ours verbatim.
rm -rf "${RES}"/mipmap-* \
"${RES}"/values/ic_launcher_background.xml \
"${RES}"/drawable/ic_launcher_background.xml \
"${RES}"/drawable-v24/ic_launcher_foreground.xml
cp -R src-tauri/icons/android/. "${RES}"/
test -f "${RES}/mipmap-anydpi-v26/ic_launcher.xml"
test -f "${RES}/values/ic_launcher_background.xml"
- name: Configure Android release signing
shell: bash
env:
ANDROID_KEY_BASE64: ${{ secrets.ANDROID_KEY_BASE64 }}
ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
run: |
set -euo pipefail
if [[ -z "${ANDROID_KEY_BASE64}" || -z "${ANDROID_KEY_ALIAS}" || -z "${ANDROID_KEY_PASSWORD}" ]]; then
echo "::error::Configure ANDROID_KEY_BASE64, ANDROID_KEY_ALIAS and ANDROID_KEY_PASSWORD GitHub Actions secrets before publishing Android releases."
exit 1
fi
KEYSTORE_PATH="${RUNNER_TEMP}/endprotocol-release.jks"
printf '%s' "${ANDROID_KEY_BASE64}" | base64 --decode > "${KEYSTORE_PATH}"
node <<'NODE'
const fs = require('node:fs');
const path = 'src-tauri/gen/android/app/build.gradle.kts';
let source = fs.readFileSync(path, 'utf8');
// AGP 9 script compilation resolves `java` to the project's java
// extension, so a fully-qualified java.util.Properties reference fails
// with "Unresolved reference 'util'". Use the simple name and make
// sure the import is present (the Tauri template already has it).
if (!/^import java\.util\.Properties$/m.test(source)) {
source = `import java.util.Properties\n${source}`;
}
const signingConfig = `
signingConfigs {
create("release") {
val keystorePropertiesFile = rootProject.file("keystore.properties")
val keystoreProperties = Properties().apply {
keystorePropertiesFile.inputStream().use { load(it) }
}
keyAlias = keystoreProperties["keyAlias"] as String
keyPassword = keystoreProperties["password"] as String
storeFile = file(keystoreProperties["storeFile"] as String)
storePassword = keystoreProperties["password"] as String
}
}
`;
const signingAssignment = ' signingConfig = signingConfigs.getByName("release")\n';
if (!source.includes('signingConfigs.create("release")') &&
!source.includes('create("release")')) {
if (!/^\s*buildTypes\s*\{/m.test(source)) {
throw new Error(`Could not find buildTypes block in ${path}`);
}
source = source.replace(/^\s*buildTypes\s*\{/m, `${signingConfig}\n buildTypes {`);
}
const releaseBlock = /getByName\("release"\)\s*\{/;
if (!releaseBlock.test(source)) {
throw new Error(`Could not find release build type in ${path}`);
}
source = source.replace(releaseBlock, (match) =>
`${match}\n${signingAssignment}`,
);
fs.writeFileSync(path, source);
NODE
{
printf 'keyAlias=%s\n' "${ANDROID_KEY_ALIAS}"
printf 'password=%s\n' "${ANDROID_KEY_PASSWORD}"
printf 'storeFile=%s\n' "${KEYSTORE_PATH}"
} > src-tauri/gen/android/keystore.properties
# `--split-per-abi` maps to the CLI's own `assemble<Arch>Release` Gradle
# task per target, i.e. one APK per ABI instead of one APK carrying every
# `jniLibs/<abi>/*.so`. `--apk` without `--debug` builds the release build
# type, which is where the R8 / resource-shrinking rules apply.
#
# `CARGO_PROFILE_RELEASE_STRIP` is what makes the APKs small: a release
# `libendprotocol_lib.so` otherwise keeps `.symtab` and `.debug_line`, and
# that is essentially the whole APK — arm64 ships a ~100 MB `.so`
# unstripped vs ~18 MB with symbols stripped. AGP's own strip step does not
# remove them here, so strip at link time instead, i.e. before AGP merges
# the `jniLibs`. Desktop builds are unaffected because the variable is
# scoped to this step.
- name: Build signed per-ABI release APKs
env:
CARGO_PROFILE_RELEASE_STRIP: symbols
run: pnpm tauri android build --ci --apk --split-per-abi --target aarch64 x86_64
- name: Prepare release APKs
shell: bash
run: |
set -euo pipefail
mkdir -p android-release
# One flavor directory per target (`arm64`, `x86_64`); the universal
# flavor is not built because `--split-per-abi` was passed.
for ARCH in arm64 x86_64; do
SRC="src-tauri/gen/android/app/build/outputs/apk/${ARCH}/release/app-${ARCH}-release.apk"
if [[ ! -f "${SRC}" ]]; then
# An unsigned build only produces the `-unsigned` suffix; the
# signing config injected above should prevent that.
echo "::error::Missing ${SRC}; the per-ABI release APK was not signed and packaged."
ls -R src-tauri/gen/android/app/build/outputs/apk || true
exit 1
fi
cp "${SRC}" "android-release/endprotocol-android-${ARCH}-release.apk"
done
ls -l android-release
- name: Verify signed per-ABI release APKs
shell: bash
run: |
set -euo pipefail
for PAIR in arm64:arm64-v8a x86_64:x86_64; do
ARCH="${PAIR%%:*}"
ABI="${PAIR##*:}"
APK="android-release/endprotocol-android-${ARCH}-release.apk"
"${ANDROID_HOME}/build-tools/36.0.0/apksigner" verify --verbose "${APK}"
# Exactly the expected ABI and nothing else: a stray second
# `lib/<abi>` directory means the split silently regressed to a
# universal APK and the size win is gone.
mapfile -t PACKED_ABIS < <(unzip -Z1 "${APK}" | sed -n 's#^lib/\([^/]*\)/.*#\1#p' | sort -u)
if [[ "${#PACKED_ABIS[@]}" -ne 1 || "${PACKED_ABIS[0]}" != "${ABI}" ]]; then
echo "::error::${APK} must contain exactly lib/${ABI}/, found: ${PACKED_ABIS[*]:-<none>}."
exit 1
fi
# Guard the size win: the unstripped arm64 `.so` alone is ~100 MB,
# so anything past 40 MB means `CARGO_PROFILE_RELEASE_STRIP`
# stopped taking effect and the symbols are back in the APK.
SIZE=$(stat -c%s "${APK}")
LIMIT=$((40 * 1024 * 1024))
if (( SIZE > LIMIT )); then
echo "::error::${APK} is ${SIZE} bytes, over the 40 MB budget; the native library looks unstripped."
exit 1
fi
printf '%s: %s bytes, ABI %s\n' "${APK}" "${SIZE}" "${PACKED_ABIS[0]}"
done
# Assert the packaged build really is the release build type with
# optimization on — a debug build would be both larger and debuggable.
# `isMinifyEnabled = false` only exists in the scaffolded debug block, so a
# `classes.dex` R8 never touched (no `mapping.txt`) means the release
# build type lost its `optimization { enable = true }`.
- name: Verify release build type and size optimization
shell: bash
run: |
set -euo pipefail
APK="android-release/endprotocol-android-arm64-release.apk"
if [[ ! -f "src-tauri/gen/android/app/build/outputs/mapping/arm64Release/mapping.txt" ]]; then
echo "::error::No R8 mapping.txt for arm64Release; the release build type is not running with optimization enabled."
exit 1
fi
BADGING="$("${ANDROID_HOME}/build-tools/36.0.0/aapt2" dump badging "${APK}")"
if grep -q '^application-debuggable' <<< "${BADGING}"; then
echo "::error::${APK} is built from the debug build type (application-debuggable is set)."
exit 1
fi
echo "Release build type confirmed; R8 mapping present."
# `tauri android init` scaffolds `gen/android` with the CLI's placeholder
# launcher artwork, and for a long time the release kept it because nothing
# copied the project icons in. Assert the packaged icon is really ours: the
# adaptive-icon descriptor has to be the resolved application icon, and every
# density has to ship a foreground layer. `aapt2` obfuscates resource file
# names, so match on type/qualifier rather than on the generated file name.
# Resource packaging is ABI-independent, so checking the arm64 APK covers
# both.
- name: Verify launcher icon comes from the project assets
shell: bash
run: |
set -euo pipefail
APK="android-release/endprotocol-android-arm64-release.apk"
AAPT2="${ANDROID_HOME}/build-tools/36.0.0/aapt2"
# Every predicate below greps a here-string rather than piping
# `printf` into `grep -q`. With `pipefail`, `grep -q` exits as soon as
# it matches, `printf` then dies of SIGPIPE, and the pipeline reports
# that as a failure — a matching assertion would randomly fail.
BADGING="$("${AAPT2}" dump badging "${APK}")"
printf '%s\n' "${BADGING}"
# The resolved application icon must be the adaptive-icon XML. A template
# placeholder shows up here as a bare `res/xx.png`.
if ! grep -q "application-icon-640:'res/[^']*\.xml'" <<< "${BADGING}"; then
echo "::error::The APK launcher icon is not an adaptive icon (the tauri android init template placeholder is being packaged instead of src-tauri/icons/android)."
exit 1
fi
RESOURCES="$("${AAPT2}" dump resources "${APK}")"
if ! grep -q 'mipmap/ic_launcher[[:space:]]*$' <<< "${RESOURCES}"; then
echo "::error::mipmap/ic_launcher is missing from the APK resources."
exit 1
fi
if ! grep -q '(anydpi-v26).*type=XML' <<< "${RESOURCES}"; then
echo "::error::mipmap/ic_launcher has no anydpi-v26 adaptive-icon descriptor."
exit 1
fi
for DENSITY in mdpi hdpi xhdpi xxhdpi xxxhdpi; do
if ! grep -q "(${DENSITY}).*type=PNG" <<< "${RESOURCES}"; then
echo "::error::mipmap/ic_launcher_foreground has no ${DENSITY} layer."
exit 1
fi
done
- name: Upload Android APK artifacts
uses: actions/upload-artifact@v4
with:
name: android-apks
path: android-release/*.apk
if-no-files-found: error
retention-days: 1
release:
name: Build and Publish Release
runs-on: windows-latest
needs: build-android
steps:
# ==========================================================
# Checkout
# ==========================================================
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch all tags
run: git fetch --tags --force
# ==========================================================
# Setup pnpm
# ==========================================================
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10
# ==========================================================
# Setup Node.js
# ==========================================================
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24
cache: pnpm
# ==========================================================
# Install dependencies
# ==========================================================
- name: Install dependencies
run: pnpm install --frozen-lockfile
# ==========================================================
# Align NPM packages with the Rust crate versions in Cargo.lock
# (auto-fixes "Found version mismatched Tauri packages")
# ==========================================================
- name: Sync Tauri NPM packages with Rust crates
id: tauri_sync
shell: bash
run: |
set -euo pipefail
node <<'SYNC_EOF'
const fs = require('fs');
const { spawnSync } = require('child_process');
const TARGET = '--target x86_64-pc-windows-msvc';
const DRY_RUN = process.env.DRY_RUN === '1';
function setBuildArgs(extra) {
const args = [TARGET, extra].filter(Boolean).join(' ');
fs.appendFileSync(process.env.GITHUB_OUTPUT, `args=${args}\n`);
console.log(`Build args: ${args}`);
}
function readJson(p) {
return JSON.parse(fs.readFileSync(p, 'utf8'));
}
// Crate versions as resolved by cargo (workspace root Cargo.lock wins).
const crateVersions = {};
for (const lock of ['Cargo.lock', 'src-tauri/Cargo.lock']) {
if (!fs.existsSync(lock)) continue;
for (const block of fs.readFileSync(lock, 'utf8').split('[[package]]')) {
const name = block.match(/^\s*name = "([^"]+)"/m);
const version = block.match(/^\s*version = "([^"]+)"/m);
if (name && version && crateVersions[name[1]] === undefined) {
crateVersions[name[1]] = version[1];
}
}
}
function npmVersion(name) {
try {
return readJson(`node_modules/${name}/package.json`).version;
} catch {
return undefined;
}
}
function crateOf(npmName) {
if (npmName === '@tauri-apps/api') return 'tauri';
if (npmName.startsWith('@tauri-apps/plugin-')) {
return `tauri-plugin-${npmName.slice('@tauri-apps/plugin-'.length)}`;
}
return null;
}
// The Tauri CLI only requires matching major.minor releases.
const sameMinor = (a, b) => {
const [aMaj, aMin] = a.split('.');
const [bMaj, bMin] = b.split('.');
return aMaj === bMaj && aMin === bMin;
};
const pkg = readJson('package.json');
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
const mismatches = [];
for (const name of Object.keys(deps)) {
const crate = crateOf(name);
if (!crate) continue;
const crateVersion = crateVersions[crate];
const npmVer = npmVersion(name);
if (!crateVersion || !npmVer) continue;
if (!sameMinor(crateVersion, npmVer)) {
mismatches.push({ name, crate, crateVersion, npmVer });
}
}
if (mismatches.length === 0) {
console.log('Tauri NPM packages and Rust crates are already in sync.');
}
let unresolved = false;
for (const m of mismatches) {
console.log(`Mismatch: ${m.crate} (v${m.crateVersion}) : ${m.name} (v${m.npmVer})`);
if (DRY_RUN) {
console.log(`[dry-run] would run: pnpm add --save-exact ${m.name}@${m.crateVersion}`);
unresolved = true;
continue;
}
const [major, minor] = m.crateVersion.split('.');
let aligned = false;
for (const spec of [m.crateVersion, `${major}.${minor}`]) {
const res = spawnSync(`pnpm add --save-exact "${m.name}@${spec}"`, {
stdio: 'inherit',
shell: true,
});
const now = npmVersion(m.name);
if (res.status === 0 && now && sameMinor(m.crateVersion, now)) {
console.log(`Aligned ${m.name} -> ${now} (matches ${m.crate} v${m.crateVersion})`);
aligned = true;
break;
}
}
if (!aligned) {
unresolved = true;
console.log(
`::warning=title=Tauri version sync failed::Could not align ${m.name} with ${m.crate} v${m.crateVersion}`
);
}
}
setBuildArgs(unresolved ? '--ignore-version-mismatches' : '');
SYNC_EOF
# ==========================================================
# Sync version from Git Tag to package.json and tauri.conf.json
# ==========================================================
- name: Update version from tag
shell: bash
run: |
set -e
# 提取纯版本号 (去掉前缀 'v')
VERSION="${GITHUB_REF_NAME#v}"
echo "Updating files to version: ${VERSION}"
# 使用 Node.js 修改 package.json
node -e "
const fs = require('fs');
const pkgPath = 'package.json';
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
pkg.version = '${VERSION}';
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
"
# 使用 Node.js 修改 src-tauri/tauri.conf.json
node -e "
const fs = require('fs');
const confPath = 'src-tauri/tauri.conf.json';
const conf = JSON.parse(fs.readFileSync(confPath, 'utf8'));
conf.version = '${VERSION}';
fs.writeFileSync(confPath, JSON.stringify(conf, null, 2) + '\n');
"
echo "Version successfully updated in package.json and src-tauri/tauri.conf.json"
# ==========================================================
# Setup Rust
# ==========================================================
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-pc-windows-msvc
# ==========================================================
# Rust cache
# ==========================================================
- name: Rust cache
uses: swatinem/rust-cache@v2
with:
workspaces: |
src-tauri -> target
# ==========================================================
# Determine channel and find previous tag
# ==========================================================
- name: Determine channel and previous tag
id: channel
shell: bash
run: |
set -e
TAG="${GITHUB_REF_NAME}"
VERSION="${TAG#v}"
echo "Current tag: ${TAG}"
echo "Current version: ${VERSION}"
if echo "${VERSION}" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+-.+'; then
CHANNEL="preview"
else
CHANNEL="stable"
fi
echo "Channel: ${CHANNEL}"
echo "channel=${CHANNEL}" >> "${GITHUB_OUTPUT}"
PREVIOUS_TAG=""
if [ "${CHANNEL}" = "stable" ]; then
PREVIOUS_TAG=$(
git tag --sort=-version:refname \
| grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' \
| grep -v "^${TAG}$" \
| head -n 1 \
|| true
)
else
PREVIOUS_TAG=$(
git tag --sort=-version:refname \
| grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-.+$' \
| grep -v "^${TAG}$" \
| head -n 1 \
|| true
)
fi
echo "Previous tag: ${PREVIOUS_TAG:-<none>}"
echo "previous_tag=${PREVIOUS_TAG}" >> "${GITHUB_OUTPUT}"
# ==========================================================
# Generate changelog
# ==========================================================
- name: Generate changelog
shell: bash
run: |
set -e
TAG="${GITHUB_REF_NAME}"
PREVIOUS_TAG="${{ steps.channel.outputs.previous_tag }}"
echo "Current tag: ${TAG}"
echo "Previous tag: ${PREVIOUS_TAG:-<none>}"
if [ -n "${PREVIOUS_TAG}" ]; then
RANGE="${PREVIOUS_TAG}..${TAG}"
else
RANGE="${TAG}"
fi
echo "Commit range: ${RANGE}"
{
echo "# ${TAG}"
echo
echo "## ✨ Features"
echo
git log "${RANGE}" --pretty=format:'- %s (%h)' | grep -E '^- feat(\(.+\))?:' || true
echo
echo "## 🐛 Bug Fixes"
echo
git log "${RANGE}" --pretty=format:'- %s (%h)' | grep -E '^- fix(\(.+\))?:' || true
echo
echo "## 📚 Documentation"
echo
git log "${RANGE}" --pretty=format:'- %s (%h)' | grep -E '^- docs(\(.+\))?:' || true
echo
echo "## ♻️ Refactoring"
echo
git log "${RANGE}" --pretty=format:'- %s (%h)' | grep -E '^- refactor(\(.+\))?:' || true
echo
echo "## ⚡ Performance"
echo
git log "${RANGE}" --pretty=format:'- %s (%h)' | grep -E '^- perf(\(.+\))?:' || true
echo
echo "## 🧪 Tests"
echo
git log "${RANGE}" --pretty=format:'- %s (%h)' | grep -E '^- test(\(.+\))?:' || true
echo
echo "## 🔧 Chores"
echo
git log "${RANGE}" --pretty=format:'- %s (%h)' | grep -E '^- chore(\(.+\))?:' || true
echo
echo "## 📝 Other Changes"
echo
git log "${RANGE}" --pretty=format:'- %s (%h)' | grep -E '^- (feat|fix|docs|refactor|perf|test|chore)(\(.+\))?:' -v || true
echo
} > CHANGELOG.md
echo ""
echo "========================================"
echo "CHANGELOG"
echo "========================================"
cat CHANGELOG.md
# ==========================================================
# Determine prerelease
# ==========================================================
- name: Determine release type
id: release-type
shell: bash
run: |
CHANNEL="${{ steps.channel.outputs.channel }}"
if [ "${CHANNEL}" = "preview" ]; then
echo "prerelease=true" >> "${GITHUB_OUTPUT}"
echo "Release type: PREVIEW"
else
echo "prerelease=false" >> "${GITHUB_OUTPUT}"
echo "Release type: STABLE"
fi
# ==========================================================
# Build Tauri + create GitHub Release
# ==========================================================
- name: Build and publish Tauri
uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
with:
tagName: ${{ github.ref_name }}
releaseName: "Release ${{ github.ref_name }}"
releaseDraft: true
prerelease: ${{ steps.release-type.outputs.prerelease }}
uploadUpdaterJson: false
args: ${{ steps.tauri_sync.outputs.args || '--target x86_64-pc-windows-msvc' }} --bundles nsis
- name: Download Android APK artifact
uses: actions/download-artifact@v4
with:
name: android-apks
path: android-release
- name: Download platform bundles
uses: actions/download-artifact@v4
continue-on-error: true
with:
pattern: platform-bundles-*
path: platform-bundles
merge-multiple: false
- name: Check for the Linux bundles
shell: bash
run: |
if [ -d platform-bundles/platform-bundles-x86_64-unknown-linux-gnu ]; then
echo "Linux bundles found."
else
echo "::warning title=Linux bundles missing::The Linux AppImage is absent, so the updater manifest carries no linux-x86_64 entry. The Linux build job has to succeed for that entry to exist."
fi
- name: Create signed multi-platform updater manifest
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
node <<'MANIFEST_EOF'
const fs = require('node:fs');
const path = require('node:path');
const { spawnSync } = require('node:child_process');
const tag = process.env.GITHUB_REF_NAME;
const version = tag.replace(/^v/, '');
const repository = process.env.GITHUB_REPOSITORY;
const assetsDir = 'release-assets';
fs.mkdirSync(assetsDir, { recursive: true });
function listFiles(directory) {
if (!fs.existsSync(directory)) return [];
return fs.readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
const entryPath = path.join(directory, entry.name);
return entry.isDirectory() ? listFiles(entryPath) : [entryPath];
});
}
function copyPlatformAssets(target, sourceDir) {
const allowed = /\.(?:exe|msi|dmg|deb|rpm|appimage|nsis\.zip|msi\.zip|appimage\.tar\.gz|app\.tar\.gz)(?:\.sig)?$/i;
const files = listFiles(sourceDir).filter((file) => allowed.test(path.basename(file)));
if (files.length === 0) throw new Error(`No distributable bundles found for ${target}`);
for (const file of files) {
const name = `${target}-${path.basename(file)}`;
fs.copyFileSync(file, path.join(assetsDir, name));
}
}
function findUpdaterBundle(target, sourceDir, suffix) {
const bundle = listFiles(sourceDir).find((file) =>
path.basename(file).toLowerCase().endsWith(suffix.toLowerCase()),
);
if (!bundle) throw new Error(`No ${suffix} updater bundle found for ${target}`);
const signaturePath = `${bundle}.sig`;
if (!fs.existsSync(signaturePath)) {
throw new Error(`Updater signature is missing: ${signaturePath}`);
}
const filename = path.basename(bundle);
const assetName = target === 'windows-x86_64'
? filename
: `${target}-${filename}`;
return {
assetName,
signature: fs.readFileSync(signaturePath, 'utf8').trim(),
};
}
const platformBuilds = [
{
key: 'linux-x86_64',
target: 'x86_64-unknown-linux-gnu',
source: 'platform-bundles/platform-bundles-x86_64-unknown-linux-gnu',
suffix: '.AppImage',
},
];
const platforms = {};
for (const build of platformBuilds) {
copyPlatformAssets(build.target, build.source);
const updater = findUpdaterBundle(build.target, build.source, build.suffix);
platforms[build.key] = {
url: `https://github.com/${repository}/releases/download/${tag}/${encodeURIComponent(updater.assetName)}`,
signature: updater.signature,
};
}
const windowsBundleDir = 'target/x86_64-pc-windows-msvc/release/bundle';
const windowsUpdater = findUpdaterBundle('windows-x86_64', windowsBundleDir, '.exe');
platforms['windows-x86_64'] = {
url: `https://github.com/${repository}/releases/download/${tag}/${encodeURIComponent(windowsUpdater.assetName)}`,
signature: windowsUpdater.signature,
};
// Android: the APKs are not Tauri updater targets (no minisign .sig),
// so they must NOT go into `platforms` — every entry there is
// deserialized as { url, signature } and a signature-less android key
// would break desktop updater parsing. Expose them as a dedicated
// top-level `android` field instead: serde ignores unknown top-level
// fields, so desktop stays unaffected. The APKs never need
// re-signing; they are verified by their APK signature.
//
// Releases are split per ABI, so the manifest lists each split by ABI
// and keeps `url`/`assetName` pointing at the arm64 APK, which is what
// the vast majority of devices install. Older clients read only
// `url`, so keeping it populated preserves their update path.
const androidApks = {
'arm64-v8a': 'endprotocol-android-arm64-release.apk',
x86_64: 'endprotocol-android-x86_64-release.apk',
};
const androidAssets = {};
for (const [abi, assetName] of Object.entries(androidApks)) {
if (fs.existsSync(path.join('android-release', assetName))) {
androidAssets[abi] = {
url: `https://github.com/${repository}/releases/download/${tag}/${encodeURIComponent(assetName)}`,
assetName,
};
} else {
console.log(`::warning title=Android APK missing::android-release/${assetName} not found, so latest.json carries no ${abi} entry.`);
}
}
let manifestAndroid = null;
if (Object.keys(androidAssets).length > 0) {
const primary = androidAssets['arm64-v8a'] ?? Object.values(androidAssets)[0];
manifestAndroid = { ...primary, apks: androidAssets };
}
const manifest = {
version,
pub_date: new Date().toISOString(),
notes: fs.readFileSync('CHANGELOG.md', 'utf8'),
platforms,
};
if (manifestAndroid) manifest.android = manifestAndroid;
fs.writeFileSync(path.join(assetsDir, 'latest.json'), `${JSON.stringify(manifest, null, 2)}\n`);
const upload = spawnSync(
'gh',
['release', 'upload', tag, ...fs.readdirSync(assetsDir).map((name) => path.join(assetsDir, name)), '--clobber'],
{ stdio: 'inherit' },
);
if (upload.status !== 0) {
throw new Error(`Failed to upload platform bundles and updater manifest (gh exit ${upload.status})`);
}
MANIFEST_EOF
- name: Upload Android APKs to Release
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
shopt -s nullglob
APKS=(android-release/*.apk)
if [[ "${#APKS[@]}" -eq 0 ]]; then
echo "::error::No Android APK was downloaded from the build job."
exit 1
fi
gh release upload "${GITHUB_REF_NAME}" "${APKS[@]}" --clobber
# ==========================================================
# Upload CHANGELOG.md as release asset
# ==========================================================
- name: Upload CHANGELOG.md
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload "${GITHUB_REF_NAME}" \
CHANGELOG.md \
--clobber
# ==========================================================
# Replace Release notes with our changelog
# ==========================================================
- name: Update release notes
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release edit "${GITHUB_REF_NAME}" \
--notes-file CHANGELOG.md
# ==========================================================
# Publish Release
# ==========================================================
- name: Publish release
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [[ "${{ steps.release-type.outputs.prerelease }}" == "true" ]]; then
gh release edit "${GITHUB_REF_NAME}" \
--draft=false \
--prerelease=true
else
gh release edit "${GITHUB_REF_NAME}" \
--draft=false \
--prerelease=false
fi
# ==========================================================
# Show final release information
# ==========================================================
- name: Release summary
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "========================================"
echo "Release completed"
echo "========================================"
echo "Tag: ${GITHUB_REF_NAME}"