-
Notifications
You must be signed in to change notification settings - Fork 0
722 lines (625 loc) · 33.8 KB
/
Copy pathdeploy.yml
File metadata and controls
722 lines (625 loc) · 33.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
name: Build and Deploy
on:
push:
branches:
- release
- development
- testing
permissions:
contents: write
concurrency:
group: deploy-gh-pages
cancel-in-progress: false
env:
NODE_VERSION: 24
jobs:
prepare-env:
runs-on: ubuntu-latest
outputs:
build_env: ${{ steps.set-env.outputs.build_env }}
path: ${{ steps.set-env.outputs.path }}
page_root: ${{ steps.set-env.outputs.page_root }}
build_prefix: ${{ steps.set-env.outputs.build_prefix }}
steps:
- name: Set environment variables
id: set-env
run: |
if [ '${{ github.ref }}' = 'refs/heads/release' ]; then
echo "build_env=production" >> $GITHUB_OUTPUT
echo "path=app" >> $GITHUB_OUTPUT
echo "page_root=/CheemsBonkGame/app/" >> $GITHUB_OUTPUT
echo "build_prefix=prod" >> $GITHUB_OUTPUT
elif [ '${{ github.ref }}' = 'refs/heads/testing' ]; then
echo "build_env=development" >> $GITHUB_OUTPUT
echo "path=test" >> $GITHUB_OUTPUT
echo "page_root=/CheemsBonkGame/test/" >> $GITHUB_OUTPUT
echo "build_prefix=test" >> $GITHUB_OUTPUT
else
echo "build_env=development" >> $GITHUB_OUTPUT
echo "path=dev" >> $GITHUB_OUTPUT
echo "page_root=/CheemsBonkGame/dev/" >> $GITHUB_OUTPUT
echo "build_prefix=dev" >> $GITHUB_OUTPUT
fi
compile-web:
needs: prepare-env
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set App Version
run: node -e "const fs = require('fs'); const ver = fs.readFileSync('ver', 'utf8').trim(); const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); pkg.version = ver + '.${{ github.run_number }}'; fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2)); if(fs.existsSync('electron/package.json')){const epkg = JSON.parse(fs.readFileSync('electron/package.json', 'utf8')); epkg.version = pkg.version; fs.writeFileSync('electron/package.json', JSON.stringify(epkg, null, 2));} console.log('Version set to ' + pkg.version);"
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install Dependencies
env:
NODE_TLS_REJECT_UNAUTHORIZED: 0
run: |
# Try installing globals up to 3 times to handle random network drops
for i in 1 2 3; do
npm install -g @angular/cli @capacitor/cli @capacitor/assets png-to-ico && break || sleep 5
done
# Use 'npm ci' for reliable CI builds (falls back to 'npm install' if no lockfile exists)
npm ci || npm install
- name: Setup PWA
env:
build_prefix: ${{ needs.prepare-env.outputs.build_prefix }}
run: |
rm -rf public/img/icons/pwa
mkdir -p public/img/icons/pwa
cp .pwa/icons-$build_prefix/pwa/* public/img/icons/pwa
rm -f public/img/favicon.ico
cp .pwa/favicon-$build_prefix.ico public/img/favicon.ico
rm -f public/manifest.webmanifest
cp .pwa/manifest-$build_prefix.webmanifest public/manifest.webmanifest
- name: Build Web
env:
build_env: ${{ needs.prepare-env.outputs.build_env }}
run: npm run build -- --configuration="$build_env"
- name: Upload Web Artifact
uses: actions/upload-artifact@v4
with:
name: web-app-${{ needs.prepare-env.outputs.build_prefix }}
path: dist/
- name: Deploy to gh-pages
env:
GH_PAT: ${{ secrets.GH_PAT }}
path: ${{ needs.prepare-env.outputs.path }}
build_env: ${{ needs.prepare-env.outputs.build_env }}
page_root: ${{ needs.prepare-env.outputs.page_root }}
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
if [ -n "$GH_PAT" ]; then
REPO_URL="https://x-access-token:${GH_PAT}@github.com/${{ github.repository }}.git"
else
REPO_URL="https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
fi
if git clone --branch gh-pages --single-branch "$REPO_URL" deploy-folder 2>/dev/null; then
echo "Cloned existing gh-pages branch."
else
echo "gh-pages branch does not exist yet. Creating orphan branch."
mkdir deploy-folder
cd deploy-folder
git init
git remote add origin "$REPO_URL"
git checkout --orphan gh-pages
cd ..
fi
target_dir="deploy-folder/$path"
rm -rf "$target_dir"
mkdir -p "$target_dir"
cp -r dist/cheems-angular/browser/* "$target_dir/"
sed -i 's|<base href="/">|<base href="'"$page_root"'">|g' "$target_dir/index.html"
cp README.md .gitignore "$target_dir/" 2>/dev/null || true
mkdir -p "$target_dir/game"
cp "$target_dir/index.html" "$target_dir/game/index.html"
mkdir -p "$target_dir/minigames/block-breaker"
cp "$target_dir/index.html" "$target_dir/minigames/block-breaker/index.html"
cp "$target_dir/index.html" "$target_dir/404.html"
if [ "$build_env" = "production" ]; then
cp .pwa/index.html "deploy-folder/" 2>/dev/null || true
cp README.md .gitignore "deploy-folder/" 2>/dev/null || true
cp .pwa/index.html "deploy-folder/404.html" 2>/dev/null || true
fi
cd deploy-folder
git add .
if ! git diff --cached --quiet; then
git commit -m "Deploy #${{ github.run_number }} from ${{ github.ref }} branch - $build_env"
git push origin HEAD:gh-pages
fi
build-android-linux:
needs: [prepare-env, compile-web]
runs-on: ubuntu-latest
strategy:
matrix:
app_type: [bundled, pwa]
steps:
- uses: actions/checkout@v4
- name: Set App Version
run: node -e "const fs = require('fs'); const ver = fs.readFileSync('ver', 'utf8').trim(); const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); pkg.version = ver + '.${{ github.run_number }}'; fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2)); if(fs.existsSync('electron/package.json')){const epkg = JSON.parse(fs.readFileSync('electron/package.json', 'utf8')); epkg.version = pkg.version; fs.writeFileSync('electron/package.json', JSON.stringify(epkg, null, 2));} console.log('Version set to ' + pkg.version);"
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- uses: actions/setup-java@v5
with:
distribution: 'zulu'
java-version: '21'
- name: Install Dependencies
env:
NODE_TLS_REJECT_UNAUTHORIZED: 0
run: |
# Try installing globals up to 3 times to handle random network drops
for i in 1 2 3; do
npm install -g @angular/cli @capacitor/cli @capacitor/assets png-to-ico && break || sleep 5
done
# Use 'npm ci' for reliable CI builds (falls back to 'npm install' if no lockfile exists)
npm ci || npm install
- name: Apply Environment Configs
env:
build_prefix: ${{ needs.prepare-env.outputs.build_prefix }}
page_root: ${{ needs.prepare-env.outputs.page_root }}
app_type: ${{ matrix.app_type }}
run: |
node -e "
const fs = require('fs');
let cap = fs.readFileSync('capacitor.config.ts', 'utf8');
let elec = fs.readFileSync('electron/electron-builder.config.json', 'utf8');
const isPwa = process.env.app_type === 'pwa';
const prefix = process.env.build_prefix;
const repoOwner = '${{ github.repository_owner }}'.toLowerCase() || 'luna115-oncode';
const pageRoot = process.env.page_root;
// Parse the electron config as JSON first to validate
let elecObj = JSON.parse(elec);
// Update appId in the parsed object
if (elecObj.appId) {
elecObj.appId = isPwa ? 'com.cheems.pwa.' + prefix : 'com.cheems.app.' + prefix;
}
// Update name for PWA variants
if (isPwa && elecObj.productName) {
elecObj.productName = 'Cheems Bonk Game (PWA)';
}
if (isPwa && elecObj.executableName) {
elecObj.executableName = 'CheemsBonkGamePWA';
}
// Write back as valid JSON
elec = JSON.stringify(elecObj, null, 2);
// Update capacitor config
cap = cap.replace('com.cheems.app', isPwa ? 'com.cheems.pwa.' + prefix : 'com.cheems.app.' + prefix);
if (isPwa) {
cap = cap.replace('Cheems Bonk Game', 'Cheems Bonk Game (PWA)');
const url = 'https://' + repoOwner + '.github.io' + pageRoot;
cap = cap.replace('webDir: \\'dist/cheems-angular/browser\\'', 'webDir: \\'dist/cheems-angular/browser\\',\\n server: { url: \\'' + url + '\\' }');
}
fs.writeFileSync('capacitor.config.ts', cap);
fs.writeFileSync('electron/electron-builder.config.json', elec);
"
mkdir -p assets electron/assets
cp .pwa/icons-$build_prefix/pwa/icon-512x512.png assets/icon-only.png
cp .pwa/icons-$build_prefix/pwa/icon-512x512.png assets/icon-foreground.png
cp .pwa/icons-$build_prefix/pwa/icon-512x512.png assets/icon-background.png
cp .pwa/icons-$build_prefix/pwa/icon-512x512.png assets/splash.png
cp .pwa/icons-$build_prefix/pwa/icon-512x512.png electron/assets/icon.png
- name: Download Web Artifact
uses: actions/download-artifact@v4
with:
name: web-app-${{ needs.prepare-env.outputs.build_prefix }}
path: dist/
- name: Optimize PWA Size for Wrappers
if: matrix.app_type == 'pwa'
shell: bash
run: |
rm -rf dist/cheems-angular/browser/*
echo "<!DOCTYPE html><html><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><title>Cheems Bonk Game</title></head><body style=\"background: black; color: white; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; font-family: sans-serif;\"><h1>Loading PWA...</h1></body></html>" > dist/cheems-angular/browser/index.html
- name: Build Android
run: |
npx cap add android
npx @capacitor/assets generate --android
npx cap sync android
# Use our consistent debug keystore so the signature doesn't change on every run
mkdir -p ~/.android
cp android-debug.keystore ~/.android/debug.keystore
cd android
VERSION=$(cat ../ver | tr -d '\r\n').${{ github.run_number }}
sed -i "s/versionName \".*\"/versionName \"$VERSION\"/g" app/build.gradle
sed -i "s/versionCode .*/versionCode ${{ github.run_number }}/g" app/build.gradle
./gradlew assembleDebug
./gradlew bundleDebug
- name: Build Linux (Bundled Electron + Portable)
if: matrix.app_type == 'bundled'
env:
build_prefix: ${{ needs.prepare-env.outputs.build_prefix }}
run: |
npx cap copy @capacitor-community/electron
cd electron
npm install
npm run electron:make
- name: Build Linux (Native PWA .deb and .rpm)
if: matrix.app_type == 'pwa'
shell: bash
env:
page_root: ${{ needs.prepare-env.outputs.page_root }}
build_prefix: ${{ needs.prepare-env.outputs.build_prefix }}
run: |
OWNER="${{ github.repository_owner }}"
if [ -z "$OWNER" ]; then OWNER="luna115-oncode"; fi
MANIFEST_URL="https://${OWNER,,}.github.io${page_root}"
APP_NAME="cheems-bonk-pwa-${build_prefix}"
mkdir -p deb-package/DEBIAN
mkdir -p deb-package/usr/bin
mkdir -p deb-package/usr/share/applications
mkdir -p deb-package/usr/share/icons/hicolor/512x512/apps
VERSION=$(cat ver | tr -d '\r\n').${{ github.run_number }}
sed -e "s|\${AppName}|$APP_NAME|g" -e "s|Version: 1.0.0|Version: $VERSION|g" .pwa/linux-control > deb-package/DEBIAN/control
sed -e "s|\${ManifestUrl}|$MANIFEST_URL|g" .pwa/linux-launcher.sh > deb-package/usr/bin/$APP_NAME
chmod +x deb-package/usr/bin/$APP_NAME
sed -e "s|\${AppName}|$APP_NAME|g" .pwa/linux.desktop > deb-package/usr/share/applications/$APP_NAME.desktop
cp .pwa/icons-${build_prefix}/pwa/icon-512x512.png deb-package/usr/share/icons/hicolor/512x512/apps/$APP_NAME.png
dpkg-deb --build deb-package ${APP_NAME}.deb
sudo apt-get update && sudo apt-get install -y rpm
mkdir -p rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
sed -e "s|\${AppName}|$APP_NAME|g" -e "s|\${Workspace}|$GITHUB_WORKSPACE|g" -e "s|Version: 1.0.0|Version: $VERSION|g" .pwa/linux.spec > rpmbuild/SPECS/pwa.spec
rpmbuild -bb --define "_topdir $GITHUB_WORKSPACE/rpmbuild" rpmbuild/SPECS/pwa.spec
cp rpmbuild/RPMS/noarch/*.rpm .
- name: Upload Android Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.app_type == 'bundled' && 'android-app-' || 'android-pwa-' }}${{ needs.prepare-env.outputs.build_prefix }}
path: |
android/app/build/outputs/apk/debug/app-debug.apk
android/app/build/outputs/bundle/debug/app-debug.aab
- name: Upload Linux Bundled Artifacts
if: matrix.app_type == 'bundled'
uses: actions/upload-artifact@v4
with:
name: linux-app-${{ needs.prepare-env.outputs.build_prefix }}
path: |
electron/dist/*.deb
electron/dist/*.rpm
electron/dist/*.AppImage
- name: Upload Linux PWA Artifacts
if: matrix.app_type == 'pwa'
uses: actions/upload-artifact@v4
with:
name: linux-pwa-${{ needs.prepare-env.outputs.build_prefix }}
path: |
*.deb
*.rpm
build-windows-xbox:
needs: [prepare-env, compile-web]
runs-on: windows-latest
strategy:
matrix:
app_type: [bundled, pwa]
steps:
- uses: actions/checkout@v4
- name: Set App Version
run: node -e "const fs = require('fs'); const ver = fs.readFileSync('ver', 'utf8').trim(); const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); pkg.version = ver + '.${{ github.run_number }}'; fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2)); if(fs.existsSync('electron/package.json')){const epkg = JSON.parse(fs.readFileSync('electron/package.json', 'utf8')); epkg.version = pkg.version; fs.writeFileSync('electron/package.json', JSON.stringify(epkg, null, 2));} console.log('Version set to ' + pkg.version);"
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install Dependencies
env:
NODE_TLS_REJECT_UNAUTHORIZED: 0
run: |
foreach ($i in 1..3) {
npm install -g @angular/cli @capacitor/cli @capacitor/assets png-to-ico
if ($LASTEXITCODE -eq 0) { break }
Start-Sleep -Seconds 5
}
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
npm ci
if ($LASTEXITCODE -ne 0) { npm install }
- name: Apply Environment Configs
shell: bash
env:
build_prefix: ${{ needs.prepare-env.outputs.build_prefix }}
page_root: ${{ needs.prepare-env.outputs.page_root }}
app_type: ${{ matrix.app_type }}
run: |
# Create directories and copy the source PNG
mkdir -p electron/assets assets
cp .pwa/icons-$build_prefix/pwa/icon-512x512.png electron/assets/icon.png
# Install the converter locally so Node can require() it
npm install png-to-ico --no-save
node -e "
const fs = require('fs');
// Safely handle both ESM and CommonJS exports for the png-to-ico package
const imported = require('png-to-ico');
const pngToIco = imported.default || imported;
let cap = fs.readFileSync('capacitor.config.ts', 'utf8');
let elec = JSON.parse(fs.readFileSync('electron/electron-builder.config.json', 'utf8'));
const isPwa = process.env.app_type === 'pwa';
const prefix = process.env.build_prefix;
const repoOwner = '${{ github.repository_owner }}'.toLowerCase() || 'luna115-oncode';
const pageRoot = process.env.page_root;
const appId = isPwa ? 'com.cheems.pwa.' + prefix : 'com.cheems.app.' + prefix;
elec.appId = appId;
if (isPwa) {
elec.productName = 'Cheems Bonk Game (PWA)';
elec.executableName = 'CheemsBonkGamePWA';
if (elec.nsis) elec.nsis.shortcutName = 'Cheems Bonk Game (PWA)';
}
// Point Windows specifically to the .ico file
if (elec.win) elec.win.icon = 'assets/icon.ico';
cap = cap.replace('com.cheems.app', appId);
if (isPwa) {
cap = cap.replace('Cheems Bonk Game', 'Cheems Bonk Game (PWA)');
const url = 'https://' + repoOwner + '.github.io' + pageRoot;
cap = cap.replace('webDir: \'dist/cheems-angular/browser\'', 'webDir: \'dist/cheems-angular/browser\',\n server: { url: \'' + url + '\' }');
}
// Generate the ICO file using raw binary buffers (avoids shell redirection corruption)
pngToIco('electron/assets/icon.png').then(buf => {
fs.writeFileSync('electron/assets/icon.ico', buf);
fs.writeFileSync('capacitor.config.ts', cap);
fs.writeFileSync('electron/electron-builder.config.json', JSON.stringify(elec, null, 2));
}).catch(err => {
console.error('Failed to convert icon:', err);
process.exit(1);
});
"
- name: Download Web Artifact
uses: actions/download-artifact@v4
with:
name: web-app-${{ needs.prepare-env.outputs.build_prefix }}
path: dist/
- name: Optimize PWA Size for Wrappers
if: matrix.app_type == 'pwa'
shell: bash
run: |
rm -rf dist/cheems-angular/browser/*
echo "<!DOCTYPE html><html><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><title>Cheems Bonk Game</title></head><body style=\"background: black; color: white; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; font-family: sans-serif;\"><h1>Loading PWA...</h1></body></html>" > dist/cheems-angular/browser/index.html
- name: Build Windows Desktop (Electron Bundled + Portable)
if: matrix.app_type == 'bundled'
shell: bash
run: |
npx cap copy @capacitor-community/electron
cd electron
npm install
npm run electron:make
- name: Build Windows & Xbox (Native MSIX Bundled Offline)
if: matrix.app_type == 'bundled'
shell: pwsh
env:
build_prefix: ${{ needs.prepare-env.outputs.build_prefix }}
run: |
$Prefix = $env:build_prefix
$AppDir = "windows-bundled-src"
New-Item -ItemType Directory -Path "$AppDir\Assets" -Force
Copy-Item -Path "dist\cheems-angular\browser\*" -Destination $AppDir -Recurse
$IconSrc = ".pwa/icons-$Prefix/pwa/icon-512x512.png"
Copy-Item $IconSrc "$AppDir\Assets\StoreLogo.png"
Copy-Item $IconSrc "$AppDir\Assets\Square150x150Logo.png"
Copy-Item $IconSrc "$AppDir\Assets\Square44x44Logo.png"
Copy-Item $IconSrc "$AppDir\Assets\SplashScreen.png"
$Version = (Get-Content -Path "ver" -Raw).Trim() + "." + $env:GITHUB_RUN_NUMBER + ".0"
$ManifestContent = Get-Content -Path ".pwa/windows-bundled.appxmanifest.xml" -Raw
$ManifestContent = $ManifestContent -replace '\$\{Prefix\}', $Prefix -replace 'Version="1\.0\.0\.0"', "Version=`"$Version`""
Set-Content -Path "$AppDir\AppxManifest.xml" -Value $ManifestContent
$MakeAppx = (Get-ChildItem -Path "C:\Program Files (x86)\Windows Kits\10\bin\*\x64\makeappx.exe" -ErrorAction SilentlyContinue | Sort-Object FullName -Descending | Select-Object -First 1).FullName
$SignTool = (Get-ChildItem -Path "C:\Program Files (x86)\Windows Kits\10\bin\*\x64\signtool.exe" -ErrorAction SilentlyContinue | Sort-Object FullName -Descending | Select-Object -First 1).FullName
& $MakeAppx pack /d $AppDir /p cheems-bundled-$Prefix.msix
# Use our consistent certificate so the signature doesn't change on every run
Copy-Item windows-msix.pfx cheems.pfx
& $SignTool sign /fd SHA256 /a /f cheems.pfx /p password cheems-bundled-$Prefix.msix
mkdir -p windows-bundled
mv cheems-bundled-$Prefix.msix windows-bundled/
- name: Build Windows & Xbox (Native MSIX PWA)
if: matrix.app_type == 'pwa'
shell: pwsh
env:
page_root: ${{ needs.prepare-env.outputs.page_root }}
build_prefix: ${{ needs.prepare-env.outputs.build_prefix }}
run: |
$Owner = "${{ github.repository_owner }}"
if ([string]::IsNullOrWhiteSpace($Owner)) { $Owner = "luna115-oncode" }
$Owner = $Owner.ToLower()
$ManifestUrl = "https://$Owner.github.io${env:page_root}"
$Prefix = $env:build_prefix
$AppDir = "windows-pwa-src"
New-Item -ItemType Directory -Path "$AppDir\Assets" -Force
$IconSrc = ".pwa/icons-$Prefix/pwa/icon-512x512.png"
Copy-Item $IconSrc "$AppDir\Assets\StoreLogo.png"
Copy-Item $IconSrc "$AppDir\Assets\Square150x150Logo.png"
Copy-Item $IconSrc "$AppDir\Assets\Square44x44Logo.png"
Copy-Item $IconSrc "$AppDir\Assets\SplashScreen.png"
$Version = (Get-Content -Path "ver" -Raw).Trim() + "." + $env:GITHUB_RUN_NUMBER + ".0"
$ManifestContent = Get-Content -Path ".pwa/windows-pwa.appxmanifest.xml" -Raw
$ManifestContent = $ManifestContent -replace '\$\{Prefix\}', $Prefix -replace '\$\{ManifestUrl\}', $ManifestUrl -replace 'Version="1\.0\.0\.0"', "Version=`"$Version`""
Set-Content -Path "$AppDir\AppxManifest.xml" -Value $ManifestContent
$MakeAppx = (Get-ChildItem -Path "C:\Program Files (x86)\Windows Kits\10\bin\*\x64\makeappx.exe" -ErrorAction SilentlyContinue | Sort-Object FullName -Descending | Select-Object -First 1).FullName
$SignTool = (Get-ChildItem -Path "C:\Program Files (x86)\Windows Kits\10\bin\*\x64\signtool.exe" -ErrorAction SilentlyContinue | Sort-Object FullName -Descending | Select-Object -First 1).FullName
& $MakeAppx pack /d $AppDir /p cheems-pwa-$Prefix.msix
# Use our consistent certificate so the signature doesn't change on every run
Copy-Item windows-msix.pfx cheems.pfx
& $SignTool sign /fd SHA256 /a /f cheems.pfx /p password cheems-pwa-$Prefix.msix
mkdir -p windows-pwa
mv cheems-pwa-$Prefix.msix windows-pwa/
- name: Upload Windows Bundled Artifacts
if: matrix.app_type == 'bundled'
uses: actions/upload-artifact@v4
with:
name: windows-app-${{ needs.prepare-env.outputs.build_prefix }}
path: |
electron/dist/*.exe
electron/dist/*.msi
windows-bundled/*.msix
- name: Upload Windows PWA Artifacts
if: matrix.app_type == 'pwa'
uses: actions/upload-artifact@v4
with:
name: windows-pwa-${{ needs.prepare-env.outputs.build_prefix }}
path: windows-pwa/*.msix
build-macos-ios:
needs: [prepare-env, compile-web]
runs-on: macos-latest
strategy:
matrix:
app_type: [bundled, pwa]
steps:
- uses: actions/checkout@v4
- name: Set App Version
run: node -e "const fs = require('fs'); const ver = fs.readFileSync('ver', 'utf8').trim(); const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); pkg.version = ver + '.${{ github.run_number }}'; fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2)); if(fs.existsSync('electron/package.json')){const epkg = JSON.parse(fs.readFileSync('electron/package.json', 'utf8')); epkg.version = pkg.version; fs.writeFileSync('electron/package.json', JSON.stringify(epkg, null, 2));} console.log('Version set to ' + pkg.version);"
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install Dependencies
env:
NODE_TLS_REJECT_UNAUTHORIZED: 0
run: |
# Try installing globals up to 3 times to handle random network drops
for i in 1 2 3; do
npm install -g @angular/cli @capacitor/cli @capacitor/assets png-to-ico && break || sleep 5
done
# Use 'npm ci' for reliable CI builds (falls back to 'npm install' if no lockfile exists)
npm ci || npm install
- name: Apply Environment Configs
env:
build_prefix: ${{ needs.prepare-env.outputs.build_prefix }}
page_root: ${{ needs.prepare-env.outputs.page_root }}
app_type: ${{ matrix.app_type }}
run: |
node -e "
const fs = require('fs');
let cap = fs.readFileSync('capacitor.config.ts', 'utf8');
let elec = JSON.parse(fs.readFileSync('electron/electron-builder.config.json', 'utf8'));
const isPwa = process.env.app_type === 'pwa';
const prefix = process.env.build_prefix;
const repoOwner = '${{ github.repository_owner }}'.toLowerCase() || 'luna115-oncode';
const pageRoot = process.env.page_root;
const appId = isPwa ? 'com.cheems.pwa.' + prefix : 'com.cheems.app.' + prefix;
// Update electron config as JSON object
elec.appId = appId;
if (isPwa) {
elec.productName = 'Cheems Bonk Game (PWA)';
elec.executableName = 'CheemsBonkGamePWA';
}
// Update capacitor config
cap = cap.replace('com.cheems.app', appId);
if (isPwa) {
cap = cap.replace('Cheems Bonk Game', 'Cheems Bonk Game (PWA)');
const url = 'https://' + repoOwner + '.github.io' + pageRoot;
cap = cap.replace('webDir: \\'dist/cheems-angular/browser\\'', 'webDir: \\'dist/cheems-angular/browser\\',\\n server: { url: \\'' + url + '\\' }');
}
fs.writeFileSync('capacitor.config.ts', cap);
fs.writeFileSync('electron/electron-builder.config.json', JSON.stringify(elec, null, 2));
"
mkdir -p assets electron/assets
cp .pwa/icons-$build_prefix/pwa/icon-512x512.png assets/icon-only.png
cp .pwa/icons-$build_prefix/pwa/icon-512x512.png assets/icon-foreground.png
cp .pwa/icons-$build_prefix/pwa/icon-512x512.png assets/icon-background.png
cp .pwa/icons-$build_prefix/pwa/icon-512x512.png assets/splash.png
cp .pwa/icons-$build_prefix/pwa/icon-512x512.png electron/assets/icon.png
- name: Download Web Artifact
uses: actions/download-artifact@v4
with:
name: web-app-${{ needs.prepare-env.outputs.build_prefix }}
path: dist/
- name: Optimize PWA Size for Wrappers
if: matrix.app_type == 'pwa'
shell: bash
run: |
rm -rf dist/cheems-angular/browser/*
echo "<!DOCTYPE html><html><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><title>Cheems Bonk Game</title></head><body style=\"background: black; color: white; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; font-family: sans-serif;\"><h1>Loading PWA...</h1></body></html>" > dist/cheems-angular/browser/index.html
- name: Build Mac (Electron Intel & Apple Silicon)
if: matrix.app_type != 'pwa'
run: |
npx cap copy @capacitor-community/electron
cd electron
npm install
# Kill any processes that might be holding onto the disk
lsof | grep -i /dev/disk | awk '{print $2}' | xargs kill -9 2>/dev/null || true
# Give the system a moment to clean up
sleep 2
# Retry the build
npm run electron:make || {
# If it fails, force unmount any remaining disk images
diskutil list | grep -i APFS | awk '{print $NF}' | xargs -I {} diskutil unmountDisk force /dev/{} 2>/dev/null || true
exit 1
}
- name: Build iOS
run: |
npx cap add ios
npx @capacitor/assets generate --ios
npx cap sync ios
VERSION=$(cat ver | tr -d '\r\n').${{ github.run_number }}
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $VERSION" ios/App/App/Info.plist
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${{ github.run_number }}" ios/App/App/Info.plist
cd ios/App
xcodebuild -project App.xcodeproj -scheme App -configuration Debug -sdk iphonesimulator -derivedDataPath build
xcodebuild archive -project App.xcodeproj -scheme App -configuration Release -archivePath build/App.xcarchive CODE_SIGNING_ALLOWED=NO || true
xcodebuild -exportArchive -archivePath build/App.xcarchive -exportPath build/Export -exportOptionsPlist App/Info.plist CODE_SIGNING_ALLOWED=NO || true
- name: Upload Mac Artifacts
if: matrix.app_type != 'pwa'
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.app_type == 'bundled' && 'macos-app-' || 'macos-pwa-' }}${{ needs.prepare-env.outputs.build_prefix }}
path: |
electron/dist/*.dmg
electron/dist/*.zip
electron/dist/**/*.app
- name: Upload iOS Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.app_type == 'bundled' && 'ios-app-' || 'ios-pwa-' }}${{ needs.prepare-env.outputs.build_prefix }}
path: |
ios/App/build/Build/Products/Debug-iphonesimulator/*.app
ios/App/build/Export/*.ipa
build-extensions:
needs: [prepare-env, compile-web]
runs-on: ubuntu-latest
strategy:
matrix:
app_type: [bundled, pwa]
steps:
- uses: actions/checkout@v4
- name: Set App Version
run: node -e "const fs = require('fs'); const ver = fs.readFileSync('ver', 'utf8').trim(); const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); pkg.version = ver + '.${{ github.run_number }}'; fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2)); if(fs.existsSync('electron/package.json')){const epkg = JSON.parse(fs.readFileSync('electron/package.json', 'utf8')); epkg.version = pkg.version; fs.writeFileSync('electron/package.json', JSON.stringify(epkg, null, 2));} console.log('Version set to ' + pkg.version);"
- name: Download Web Artifact
uses: actions/download-artifact@v4
with:
name: web-app-${{ needs.prepare-env.outputs.build_prefix }}
path: dist/
- name: Build Chromium and Firefox Extensions
env:
app_type: ${{ matrix.app_type }}
build_prefix: ${{ needs.prepare-env.outputs.build_prefix }}
page_root: ${{ needs.prepare-env.outputs.page_root }}
run: |
mkdir -p ext-chromium ext-firefox
# Setup routing logic based on PWA or Bundled
OWNER="${{ github.repository_owner }}"
if [ -z "$OWNER" ]; then OWNER="luna115-oncode"; fi
MANIFEST_URL="https://${OWNER,,}.github.io${page_root}"
if [ "$app_type" = "bundled" ]; then
# Copy all game files into the extension for offline play
cp -r dist/cheems-angular/browser/* ext-chromium/
cp -r dist/cheems-angular/browser/* ext-firefox/
TARGET_URL="index.html"
APP_NAME="Cheems Bonk Game"
else
# Light PWA: Only opens the remote URL
TARGET_URL="$MANIFEST_URL"
APP_NAME="Cheems Bonk Game (PWA)"
fi
# Copy extension icons
cp .pwa/icons-$build_prefix/pwa/icon-512x512.png ext-chromium/icon.png
cp .pwa/icons-$build_prefix/pwa/icon-512x512.png ext-firefox/icon.png
# 1. Chromium Extension (Chrome, Edge, Brave, Opera, ChromeOS)
VERSION=$(cat ver | tr -d '\r\n').${{ github.run_number }}
sed -e "s|\${AppName}|$APP_NAME|g" -e "s|\"version\": \"1.0.0\"|\"version\": \"$VERSION\"|g" .pwa/chromium-manifest.json > ext-chromium/manifest.json
sed -e "s|\${TargetUrl}|$TARGET_URL|g" .pwa/extension-background.js > ext-chromium/background.js
# 2. Firefox Extension
sed -e "s|\${AppName}|$APP_NAME|g" -e "s|\${Prefix}|$build_prefix|g" -e "s|\"version\": \"1.0.0\"|\"version\": \"$VERSION\"|g" .pwa/firefox-manifest.json > ext-firefox/manifest.json
sed -e "s|\${TargetUrl}|$TARGET_URL|g" .pwa/extension-background.js > ext-firefox/background.js
# Zip the extensions (Ready for Chrome Web Store & Mozilla Add-ons)
cd ext-chromium
zip -r ../chromium-extension-$build_prefix.zip *
cd ../ext-firefox
zip -r ../firefox-extension-$build_prefix.zip *
cd ..
- name: Upload Extension Artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.app_type == 'bundled' && 'browser-extensions-bundled-' || 'browser-extensions-pwa-' }}${{ needs.prepare-env.outputs.build_prefix }}
path: |
*.zip