-
-
Notifications
You must be signed in to change notification settings - Fork 0
467 lines (400 loc) · 21.1 KB
/
build-android.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
name: Build For Android
on:
push:
branches: ["main"]
workflow_dispatch:
inputs:
publish:
description: 'Publish engine'
required: true
default: 'no'
type: choice
options:
- 'no'
- 'yes'
runanyway:
description: 'Override --norun Flag'
required: true
default: 'no'
type: choice
options:
- 'no'
- 'yes'
jobs:
build:
if: (!endsWith(github.event.head_commit.message, '--norun') || inputs.runanyway == 'yes')
runs-on: ubuntu-latest
environment: android
env:
ANDROID_HOME: /usr/local/lib/android/sdk
CARGO_TERM_COLOR: always
steps:
# Setup Build Environment
- name: 🎉 The job was automatically triggered by a ${{ github.event_name }} event.
run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- name: 🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!
run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- name: 🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}.
run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v4
with:
lfs: true
submodules: recursive
- name: 💡 The ${{ github.repository }} repository has been cloned to the runner.
run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
# Setup Java
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'graalvm'
java-version: '23'
# Setup Gradle Build Action (For Caching Builds) - ./app/.cxx|./app/build|./.gradle
- name: Setup Gradle Build Action (For Caching Builds)
uses: gradle/actions/setup-gradle@v3
# Install Dependencies
- name: Install and Cache APT Packages
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: unzip
version: 1.0
execute_install_scripts: true
# Install Rust
- name: Make Tools Directory
run: mkdir -p ${{ github.workspace }}/tools
- name: Download Rust Installer
run: curl --proto '=https' --tlsv1.2 --silent --show-error --fail --location https://sh.rustup.rs > ${{ github.workspace }}/tools/rust.sh
- name: Make Rust Installer Executable
run: chmod +x ${{ github.workspace }}/tools/rust.sh
- name: Install Rust
run: ${{ github.workspace }}/tools/rust.sh -y
- name: Load Cargo Environment
run: source "$HOME/.cargo/env"
# Install Rust Stable Toolchains
- name: Set Rust To The Stable Toolchains
run: $HOME/.cargo/bin/rustup default stable
# Setup Rust Build Caching
- uses: Swatinem/rust-cache@v2
with:
shared-key: "android-rust"
# Add Build Targets
- name: Add armv7 Android Build Target
run: $HOME/.cargo/bin/rustup target add armv7-linux-androideabi
- name: Add aarch64 Android Build Target
run: $HOME/.cargo/bin/rustup target add aarch64-linux-android
- name: Add i686 Android Build Target
run: $HOME/.cargo/bin/rustup target add i686-linux-android
- name: Add x86_64 Android Build Target
run: $HOME/.cargo/bin/rustup target add x86_64-linux-android
# Install Git Pre-Commit Hooks to Enforce Hooks
- name: Install Git Pre-Commit Hooks to Enforce Hooks
run: pip install pre-commit
# Check Pre-Commit Version
- name: Check Pre-Commit Version
run: pre-commit --version
# Install Pre-Commit Hooks
- name: Install Pre-Commit Hooks
run: pre-commit install
# Check Files with Pre-Commit Hooks
- name: Check Files with Pre-Commit Hooks
run: pre-commit run --all-files
# Install Cargo-NDK
- name: Install Cargo-NDK
run: cargo install cargo-ndk
# Workaround Cargo Gradle Plugin Bug
- name: Workaround Cargo Gradle Plugin Bug
run: touch ${{ github.workspace }}/android/local.properties
# Ignore Modifying android/app/build.gradle
- name: Ignore Modifying ${{ github.workspace }}/android/app/build.gradle
run: |
cd ${{ github.workspace }}
git update-index --skip-worktree ${{ github.workspace }}/android/app/build.gradle
# Extract Keystore
- name: Extract Keystore
run: echo "${{ secrets.ANDROID_RELEASE_KEY }}" | base64 -d > /home/runner/work/release.keystore
# Build Engine As APK
- name: Build Engine APK (FAT)
working-directory: ${{ github.workspace }}/android
env:
ANDROID_RELEASE_KEY_PATH: /home/runner/work/release.keystore
ANDROID_RELEASE_STORE_PASSWORD: ${{ secrets.ANDROID_RELEASE_STORE_PASSWORD }}
ANDROID_RELEASE_KEY_PASSWORD: ${{ secrets.ANDROID_RELEASE_KEY_PASSWORD }}
run: |
# Sets the build timestamp to the current commit to make builds reproducible
export SOURCE_DATE_EPOCH="`git --no-pager log -1 --format="%at"`"
${{ github.workspace }}/android/gradlew assembleRelease
mkdir -p ${{ github.workspace }}/upload/android
cp -a ${{ github.workspace }}/android/app/build/outputs/apk/release/app-release.apk ${{ github.workspace }}/upload/android/catgirl-engine-fat.apk
#cp -a ${{ github.workspace }}/android/app/build/outputs/bundle/release/app-release.aab ${{ github.workspace }}/upload/android
# Build Engine As APK
- name: Build Engine APK (arm64)
working-directory: ${{ github.workspace }}/android
env:
ANDROID_RELEASE_KEY_PATH: /home/runner/work/release.keystore
ANDROID_RELEASE_STORE_PASSWORD: ${{ secrets.ANDROID_RELEASE_STORE_PASSWORD }}
ANDROID_RELEASE_KEY_PASSWORD: ${{ secrets.ANDROID_RELEASE_KEY_PASSWORD }}
run: |
# Sets the build timestamp to the current commit to make builds reproducible
export SOURCE_DATE_EPOCH="`git --no-pager log -1 --format="%at"`"
# export CARGO_NDK_ANDROID_TARGET="arm64-v8a"
sed -i "s/targets = [\"[a-z_0-9, ]*\"]/targets = [\"arm64\"]/" ${{ github.workspace }}/android/app/build.gradle
rm -rf ${{ github.workspace }}/android/app/src/main/jniLibs
${{ github.workspace }}/android/gradlew clean
${{ github.workspace }}/android/gradlew assembleRelease
mkdir -p ${{ github.workspace }}/upload/android
cp -a ${{ github.workspace }}/android/app/build/outputs/apk/release/app-release.apk ${{ github.workspace }}/upload/android/catgirl-engine-arm64.apk
# Build Engine As APK
- name: Build Engine APK (armeabi-v7a)
working-directory: ${{ github.workspace }}/android
env:
ANDROID_RELEASE_KEY_PATH: /home/runner/work/release.keystore
ANDROID_RELEASE_STORE_PASSWORD: ${{ secrets.ANDROID_RELEASE_STORE_PASSWORD }}
ANDROID_RELEASE_KEY_PASSWORD: ${{ secrets.ANDROID_RELEASE_KEY_PASSWORD }}
run: |
# Sets the build timestamp to the current commit to make builds reproducible
export SOURCE_DATE_EPOCH="`git --no-pager log -1 --format="%at"`"
# export CARGO_NDK_ANDROID_TARGET="armeabi-v7a"
sed -i "s/targets = [\"[a-z_0-9, ]*\"]/targets = [\"arm\"]/" ${{ github.workspace }}/android/app/build.gradle
rm -rf ${{ github.workspace }}/android/app/src/main/jniLibs
${{ github.workspace }}/android/gradlew clean
${{ github.workspace }}/android/gradlew assembleRelease
mkdir -p ${{ github.workspace }}/upload/android
cp -a ${{ github.workspace }}/android/app/build/outputs/apk/release/app-release.apk ${{ github.workspace }}/upload/android/catgirl-engine-armeabi-v7a.apk
# Build Engine As APK
- name: Build Engine APK (x86)
working-directory: ${{ github.workspace }}/android
env:
ANDROID_RELEASE_KEY_PATH: /home/runner/work/release.keystore
ANDROID_RELEASE_STORE_PASSWORD: ${{ secrets.ANDROID_RELEASE_STORE_PASSWORD }}
ANDROID_RELEASE_KEY_PASSWORD: ${{ secrets.ANDROID_RELEASE_KEY_PASSWORD }}
run: |
# Sets the build timestamp to the current commit to make builds reproducible
export SOURCE_DATE_EPOCH="`git --no-pager log -1 --format="%at"`"
# export CARGO_NDK_ANDROID_TARGET="x86"
sed -i "s/targets = [\"[a-z_0-9, ]*\"]/targets = [\"x86\"]/" ${{ github.workspace }}/android/app/build.gradle
rm -rf ${{ github.workspace }}/android/app/src/main/jniLibs
${{ github.workspace }}/android/gradlew clean
${{ github.workspace }}/android/gradlew assembleRelease
mkdir -p ${{ github.workspace }}/upload/android
cp -a ${{ github.workspace }}/android/app/build/outputs/apk/release/app-release.apk ${{ github.workspace }}/upload/android/catgirl-engine-x86.apk
# Build Engine As APK
- name: Build Engine APK (x86_64)
working-directory: ${{ github.workspace }}/android
env:
ANDROID_RELEASE_KEY_PATH: /home/runner/work/release.keystore
ANDROID_RELEASE_STORE_PASSWORD: ${{ secrets.ANDROID_RELEASE_STORE_PASSWORD }}
ANDROID_RELEASE_KEY_PASSWORD: ${{ secrets.ANDROID_RELEASE_KEY_PASSWORD }}
run: |
# Sets the build timestamp to the current commit to make builds reproducible
export SOURCE_DATE_EPOCH="`git --no-pager log -1 --format="%at"`"
# export CARGO_NDK_ANDROID_TARGET="x86_64"
sed -i "s/targets = [\"[a-z_0-9, ]*\"]/targets = [\"x86_64\"]/" ${{ github.workspace }}/android/app/build.gradle
rm -rf ${{ github.workspace }}/android/app/src/main/jniLibs
${{ github.workspace }}/android/gradlew clean
${{ github.workspace }}/android/gradlew assembleRelease
mkdir -p ${{ github.workspace }}/upload/android
cp -a ${{ github.workspace }}/android/app/build/outputs/apk/release/app-release.apk ${{ github.workspace }}/upload/android/catgirl-engine-x86_64.apk
# Remove Keystore
- name: Remove Keystore
run: rm -rf /home/runner/work/release.keystore
# Display Export Directory
- name: Display Git Staging
run: |
cd ${{ github.workspace }}
git status -v -s -b
# Display APK Directory
- name: Display APK Directory (Release)
run: ls -liallh ${{ github.workspace }}/android/app/build/outputs/apk/release
# Prepare Artifact Uploads
- name: Prepare Artifact Uploads (Client/Server)
run: |
mkdir -p ${{ github.workspace }}/upload/android
cp -a ${{ github.workspace }}/target/binding ${{ github.workspace }}/upload/android
# Extract/Import GPG Signing Key
- name: Extract GPG Signing Key
run: |
echo "${{ secrets.GPG_SIGNING_KEY }}" > $HOME/signing.gpg
gpg --import $HOME/signing.gpg
rm -rf $HOME/signing.gpg
# Sign Files
- name: Sign Files (Client/Server)
run: |
cd ${{ github.workspace }}/upload/android
find . -type f -not -name "checksums.sha512" -exec shasum -a 512 {} \; > checksums.sha512
gpg --sign checksums.sha512
# Remove GPG Signing Key
- name: Remove GPG Signing Key
run: rm -rf $HOME/.gnupg
# Compress Files
- name: Compress Files (Client/Server)
run: |
export XZ_OPT=-e9
cd ${{ github.workspace }}/upload/android
tar cvJf ${{ github.workspace }}/upload/CatgirlEngine-Android.tar.xz .
# Upload Engine
- name: Upload Engine (Release)
uses: actions/upload-artifact@v4
with:
name: CatgirlEngine-Android
path: ${{ github.workspace }}/upload/CatgirlEngine-Android.tar.xz
# List Environment
- name: List Environment
run: env
- name: List All Installed Packages
run: |
apt list --installed | wc -l
apt list --installed
- name: List All Files
run: find ${{ github.workspace }}
# Display Build Status
- name: 🍏 This job's status is ${{ job.status }}.
run: echo "🍏 This job's status is ${{ job.status }}."
deploy:
if: ${{ success() && (endsWith(github.event.head_commit.message, '--publish') || inputs.publish == 'yes') }}
needs: [Build]
runs-on: ubuntu-latest
permissions:
# See https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
# See https://docs.github.com/en/rest/overview/permissions-required-for-fine-grained-personal-access-tokens
contents: write
environment: itch.io
steps:
# Setup Build Environment
- name: 🎉 The job was automatically triggered by a ${{ github.event_name }} event.
run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- name: 🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!
run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- name: 🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}.
run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v4
with:
lfs: true
submodules: recursive
- name: 💡 The ${{ github.repository }} repository has been cloned to the runner.
run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
# Download APK
- name: Download APK (Release)
uses: actions/download-artifact@v4
with:
name: CatgirlEngine-Android
path: ${{ github.workspace }}/artifacts
# Compress Files
- name: Extract Files (Client/Server)
run: |
mkdir -p ${{ github.workspace }}/artifacts/android
cd ${{ github.workspace }}/artifacts
tar xvf ${{ github.workspace }}/artifacts/CatgirlEngine-Android.tar.xz -C android
# Create Tag and Github Release
- name: 👩💻 Create Tag and Github Release
env:
GH_TOKEN: ${{ github.token }}
run: |
# TODO: Consider checking for -alpha and -beta to filter onto other packages
export VERSION=`cat ${{ github.workspace }}/Cargo.toml | grep '^version' | head -n1 | cut -d'"' -f2 | tr -d '\n'`
export VERSION_STRING="Catgirl Engine v$VERSION"
export BODY="Autogenerated Release From Github Actions..."
export DRAFT="false"
export PRERELEASE="false"
export LATEST="true"
export GENERATE_RELEASE_NOTES="true"
export BRANCH=`git branch --show-current --format="%s" | tr -d '\n'`
# export COMMIT=`git log -1 --oneline | cut -d' ' -f1 | tr -d '\n'`
gh api --method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/releases \
-f tag_name="v$VERSION" \
-f target_commitish="$BRANCH" \
-f name="$VERSION_STRING" \
-f body="$BODY" \
-f make_latest="$LATEST" \
-F draft="$DRAFT" \
-F prerelease="$PRERELEASE" \
-F generate_release_notes="$GENERATE_RELEASE_NOTES" || echo "Already Exists"
# Publish to Github Release
- name: 👩💻 Publish to Github Release (Tar)
env:
GH_TOKEN: ${{ github.token }}
run: |
export VERSION=`cat ${{ github.workspace }}/Cargo.toml | grep '^version' | head -n1 | cut -d'"' -f2 | tr -d '\n'`
export ARTIFACT_PATH="${{ github.workspace }}/artifacts/CatgirlEngine-Android.tar.xz"
export DISPLAY_LABEL="Android (Tar)"
gh release upload v$VERSION "$ARTIFACT_PATH"#"$DISPLAY_LABEL" -R ${{ github.repository }}
# Publish to Github Release
- name: 👩💻 Publish to Github Release (FAT)
env:
GH_TOKEN: ${{ github.token }}
run: |
export VERSION=`cat ${{ github.workspace }}/Cargo.toml | grep '^version' | head -n1 | cut -d'"' -f2 | tr -d '\n'`
export ARTIFACT_PATH="${{ github.workspace }}/artifacts/android/catgirl-engine-fat.apk"
export DISPLAY_LABEL="Android (FAT)"
gh release upload v$VERSION "$ARTIFACT_PATH"#"$DISPLAY_LABEL" -R ${{ github.repository }}
# Publish to Github Release
- name: 👩💻 Publish to Github Release (arm64)
env:
GH_TOKEN: ${{ github.token }}
run: |
export VERSION=`cat ${{ github.workspace }}/Cargo.toml | grep '^version' | head -n1 | cut -d'"' -f2 | tr -d '\n'`
export ARTIFACT_PATH="${{ github.workspace }}/artifacts/android/catgirl-engine-arm64.apk"
export DISPLAY_LABEL="Android (arm64)"
gh release upload v$VERSION "$ARTIFACT_PATH"#"$DISPLAY_LABEL" -R ${{ github.repository }}
# Publish to Github Release
- name: 👩💻 Publish to Github Release (armeabi-v7a)
env:
GH_TOKEN: ${{ github.token }}
run: |
export VERSION=`cat ${{ github.workspace }}/Cargo.toml | grep '^version' | head -n1 | cut -d'"' -f2 | tr -d '\n'`
export ARTIFACT_PATH="${{ github.workspace }}/artifacts/android/catgirl-engine-armeabi-v7a.apk"
export DISPLAY_LABEL="Android (armeabi-v7a)"
gh release upload v$VERSION "$ARTIFACT_PATH"#"$DISPLAY_LABEL" -R ${{ github.repository }}
# Publish to Github Release
- name: 👩💻 Publish to Github Release (x86)
env:
GH_TOKEN: ${{ github.token }}
run: |
export VERSION=`cat ${{ github.workspace }}/Cargo.toml | grep '^version' | head -n1 | cut -d'"' -f2 | tr -d '\n'`
export ARTIFACT_PATH="${{ github.workspace }}/artifacts/android/catgirl-engine-x86.apk"
export DISPLAY_LABEL="Android (x86)"
gh release upload v$VERSION "$ARTIFACT_PATH"#"$DISPLAY_LABEL" -R ${{ github.repository }}
# Publish to Github Release
- name: 👩💻 Publish to Github Release (x86_64)
env:
GH_TOKEN: ${{ github.token }}
run: |
export VERSION=`cat ${{ github.workspace }}/Cargo.toml | grep '^version' | head -n1 | cut -d'"' -f2 | tr -d '\n'`
export ARTIFACT_PATH="${{ github.workspace }}/artifacts/android/catgirl-engine-x86_64.apk"
export DISPLAY_LABEL="Android (x86_64)"
gh release upload v$VERSION "$ARTIFACT_PATH"#"$DISPLAY_LABEL" -R ${{ github.repository }}
# Install Butler (For Uploading to Itch.io)
- name: Install Butler (Upload to Itch.io)
id: download-butler
continue-on-error: true
run: |
# https://itch.io/docs/butler/pushing.html#channel-names
# Setup For Installation
mkdir -p ${{ github.workspace }}/tools/butler
# Install Butler
curl --proto '=https' --tlsv1.2 --silent --show-error --fail --location https://broth.itch.zone/butler/linux-amd64/LATEST/archive/default > ${{ github.workspace }}/tools/butler-linux-amd64.zip
unzip -o ${{ github.workspace }}/tools/butler-linux-amd64.zip -d ${{ github.workspace }}/tools/butler
# Fallback to deal with DDOS attack on Itch.io at the time of writing
- name: Install Butler (Fallback)
if: steps.download-butler.outcome == 'failure'
run: |
# Setup For Installation
mkdir -p ${{ github.workspace }}/tools/butler
# Install Butler
curl --proto '=https' --tlsv1.2 --silent --show-error --fail --location https://github.com/lexi-the-cute/butler/releases/download/v15.23.0/butler-linux-amd64.zip > ${{ github.workspace }}/tools/butler-linux-amd64.zip
unzip -o ${{ github.workspace }}/tools/butler-linux-amd64.zip -d ${{ github.workspace }}/tools/butler
# Publish to Itch.io
- name: 🎮 Publish to Itch.io
env:
BUTLER_API_KEY: ${{ secrets.ITCH_IO_API_KEY }}
run: |
export VERSION=`cat ${{ github.workspace }}/Cargo.toml | grep '^version' | head -n1 | cut -d'"' -f2 | tr -d '\n'`
# Upload App
${{ github.workspace }}/tools/butler/butler push ${{ github.workspace }}/artifacts/android/catgirl-engine-fat.apk foxgirl-labs/catgirl-engine:android --userversion $VERSION
# ${{ github.workspace }}/tools/butler/butler push ${{ github.workspace }}/artifacts/android/catgirl-engine-arm64.apk foxgirl-labs/catgirl-engine:android-arm64 --userversion $VERSION
# ${{ github.workspace }}/tools/butler/butler push ${{ github.workspace }}/artifacts/android/catgirl-engine-armeabi-v7a.apk foxgirl-labs/catgirl-engine:android-armeabi-v7a --userversion $VERSION
# ${{ github.workspace }}/tools/butler/butler push ${{ github.workspace }}/artifacts/android/catgirl-engine-x86.apk foxgirl-labs/catgirl-engine:android-x86 --userversion $VERSION
# ${{ github.workspace }}/tools/butler/butler push ${{ github.workspace }}/artifacts/android/catgirl-engine-x86_64.apk foxgirl-labs/catgirl-engine:android-x86_64 --userversion $VERSION