Repository navigation
426 lines (400 loc) · 15.8 KB
/
Copy pathdeploy_android.yml
File metadata and controls
426 lines (400 loc) · 15.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
name: Deploy Android
run-name: Deploy Android ${{ inputs.version_name }}
on:
workflow_dispatch:
inputs:
version_name:
description: 'App versionName (e.g. 1.1.0, 1.2.0-rc1)'
required: true
version_code:
description: 'versionCode (empty = from the version, 1.4.12 is 1041299, 1.4.12-rc2 is 1041202)'
required: false
default: ''
notes_en:
description: 'What''s new in English for Google Play, up to 500 characters, \n is a line break'
required: false
default: ''
notes_ru:
description: 'Что нового по-русски для Google Play (до 500 знаков) и RuStore, \n — перенос строки'
required: false
default: ''
publish_google_play:
description: 'Publish the AAB to Google Play'
type: boolean
default: false
play_track:
description: 'Google Play track'
type: choice
options: [internal, alpha, beta, production]
default: internal
play_status:
description: 'Google Play release status'
type: choice
options: [draft, inProgress, completed]
default: completed
play_send_for_review:
description: 'Send the Google Play changes to review (unchecked = they wait in Publishing overview)'
type: boolean
default: false
publish_rustore:
description: 'Upload the build to a RuStore draft version'
type: boolean
default: false
rustore_artifact:
description: 'File to upload to RuStore'
type: choice
options: [apk, aab]
default: apk
rustore_submit:
description: 'Send the RuStore draft to moderation'
type: boolean
default: false
rustore_auto_publish:
description: 'Publish on RuStore as soon as moderation passes'
type: boolean
default: false
workflow_call:
inputs:
version_name:
type: string
required: false
default: ''
version_code:
type: string
required: false
default: ''
notes_en:
type: string
required: false
default: ''
notes_ru:
type: string
required: false
default: ''
publish_google_play:
type: boolean
required: false
default: false
play_track:
type: string
required: false
default: internal
play_status:
type: string
required: false
default: completed
play_send_for_review:
type: boolean
required: false
default: false
publish_rustore:
type: boolean
required: false
default: false
rustore_artifact:
type: string
required: false
default: apk
rustore_submit:
type: boolean
required: false
default: false
rustore_auto_publish:
type: boolean
required: false
default: false
permissions:
contents: read
concurrency:
group: deploy-android-${{ github.ref }}
cancel-in-progress: false
env:
PACKAGE_NAME: com.vasmarfas.networkhelm
jobs:
build:
name: Build AAB and APK
runs-on: ubuntu-latest
outputs:
signed: ${{ steps.keystore.outputs.signed }}
steps:
- uses: actions/checkout@v7
- name: Set up JDK 21
uses: actions/setup-java@v6
with:
java-version: '21'
distribution: 'temurin'
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v6
- name: Resolve version
id: version
env:
INPUT_VERSION: ${{ inputs.version_name }}
INPUT_CODE: ${{ inputs.version_code }}
RUN_NUMBER: ${{ github.run_number }}
run: |
set -eu
name="$INPUT_VERSION"
if [ -z "$name" ]; then
case "$GITHUB_REF" in
refs/tags/v*) name="${GITHUB_REF#refs/tags/v}" ;;
*) echo "::error::the version is not given"; exit 1 ;;
esac
fi
derived=$(printf '%s' "$name" | awk '{
split($0, part, "-")
split(part[1], v, ".")
stage = 99
if (index($0, "-")) { stage = 0; if (match($0, /[0-9]+$/)) stage = substr($0, RSTART) }
print ((v[1] * 100 + v[2]) * 100 + v[3]) * 100 + stage
}')
code="${INPUT_CODE:-$derived}"
[ "$code" != 0 ] || code="$RUN_NUMBER"
{
echo "name=$name"
echo "code=$code"
} >> "$GITHUB_OUTPUT"
- name: Decode keystore
id: keystore
env:
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
run: |
set -eu
if [ -z "${KEYSTORE_BASE64:-}" ]; then
echo "signed=false" >> "$GITHUB_OUTPUT"
echo "::warning::KEYSTORE_BASE64 is not set, the release build will be unsigned and cannot be published"
else
umask 077
printf '%s' "$KEYSTORE_BASE64" | base64 -d > "$RUNNER_TEMP/release.keystore"
echo "KEYSTORE_PATH=$RUNNER_TEMP/release.keystore" >> "$GITHUB_ENV"
echo "signed=true" >> "$GITHUB_OUTPUT"
fi
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Build
env:
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
APP_VERSION_NAME: ${{ steps.version.outputs.name }}
APP_VERSION_CODE: ${{ steps.version.outputs.code }}
run: ./gradlew :app:androidApp:bundleRelease :app:androidApp:assembleRelease
- name: Collect artifacts
env:
VERSION: ${{ steps.version.outputs.name }}
run: |
set -eu
mkdir -p out mapping
outputs=app/androidApp/build/outputs
cp "$outputs"/bundle/release/*.aab "out/NetworkHelm-$VERSION.aab"
cp "$outputs"/apk/release/*.apk "out/NetworkHelm-$VERSION.apk"
if [ -f "$outputs/mapping/release/mapping.txt" ]; then
cp "$outputs/mapping/release/mapping.txt" mapping/mapping.txt
fi
- name: Upload release artifacts
uses: actions/upload-artifact@v7
with:
name: release-android
path: out/*
if-no-files-found: error
- name: Upload mapping
uses: actions/upload-artifact@v7
with:
name: android-mapping
path: mapping/*
if-no-files-found: ignore
google_play:
name: Google Play
needs: build
if: ${{ inputs.publish_google_play }}
runs-on: ubuntu-latest
steps:
- name: Check credentials
id: guard
env:
PLAY_SERVICE_ACCOUNT_JSON: ${{ secrets.PLAY_SERVICE_ACCOUNT_JSON }}
SIGNED: ${{ needs.build.outputs.signed }}
run: |
set -eu
if [ -z "${PLAY_SERVICE_ACCOUNT_JSON:-}" ]; then
echo "ready=false" >> "$GITHUB_OUTPUT"
echo "::notice::PLAY_SERVICE_ACCOUNT_JSON is not set, skipping Google Play"
echo 'Google Play: skipped, PLAY_SERVICE_ACCOUNT_JSON is not set.' >> "$GITHUB_STEP_SUMMARY"
elif [ "$SIGNED" != 'true' ]; then
echo "ready=false" >> "$GITHUB_OUTPUT"
echo "::notice::the build is unsigned, skipping Google Play"
echo 'Google Play: skipped, the build is unsigned.' >> "$GITHUB_STEP_SUMMARY"
else
echo "ready=true" >> "$GITHUB_OUTPUT"
fi
- name: Download bundle
if: steps.guard.outputs.ready == 'true'
uses: actions/download-artifact@v8
with:
name: release-android
path: out
- name: Download mapping
if: steps.guard.outputs.ready == 'true'
continue-on-error: true
uses: actions/download-artifact@v8
with:
name: android-mapping
path: mapping
- name: Prepare release notes
id: notes
if: steps.guard.outputs.ready == 'true'
env:
NOTES_EN: ${{ inputs.notes_en }}
NOTES_RU: ${{ inputs.notes_ru }}
run: |
set -eu
mkdir -p whatsnew
# dispatch inputs are single-line, \n in them stands for a line break
[ -z "$NOTES_EN" ] || printf '%b' "$NOTES_EN" > whatsnew/whatsnew-en-US
[ -z "$NOTES_RU" ] || printf '%b' "$NOTES_RU" > whatsnew/whatsnew-ru-RU
if [ -z "$(ls -A whatsnew)" ]; then
echo "::notice::no release notes given, publishing without them"
fi
if [ -f mapping/mapping.txt ]; then
echo "mapping=mapping/mapping.txt" >> "$GITHUB_OUTPUT"
else
echo "mapping=" >> "$GITHUB_OUTPUT"
fi
- name: Upload to Google Play
if: steps.guard.outputs.ready == 'true'
uses: r0adkll/upload-google-play@v1.1.5
with:
serviceAccountJsonPlainText: ${{ secrets.PLAY_SERVICE_ACCOUNT_JSON }}
packageName: ${{ env.PACKAGE_NAME }}
releaseFiles: out/*.aab
mappingFile: ${{ steps.notes.outputs.mapping }}
whatsNewDirectory: whatsnew
track: ${{ inputs.play_track }}
status: ${{ inputs.play_status }}
changesNotSentForReview: ${{ !inputs.play_send_for_review }}
rustore:
name: RuStore
needs: build
if: ${{ inputs.publish_rustore }}
runs-on: ubuntu-latest
steps:
- name: Check credentials
id: guard
env:
RUSTORE_KEY_ID: ${{ secrets.RUSTORE_KEY_ID }}
RUSTORE_PRIVATE_KEY: ${{ secrets.RUSTORE_PRIVATE_KEY }}
SIGNED: ${{ needs.build.outputs.signed }}
run: |
set -eu
if [ -z "${RUSTORE_KEY_ID:-}" ] || [ -z "${RUSTORE_PRIVATE_KEY:-}" ]; then
echo "ready=false" >> "$GITHUB_OUTPUT"
echo "::notice::RUSTORE_KEY_ID / RUSTORE_PRIVATE_KEY are not set, skipping RuStore"
echo 'RuStore: skipped, secrets are not set.' >> "$GITHUB_STEP_SUMMARY"
elif [ "$SIGNED" != 'true' ]; then
echo "ready=false" >> "$GITHUB_OUTPUT"
echo "::notice::the build is unsigned, skipping RuStore"
echo 'RuStore: skipped, the build is unsigned.' >> "$GITHUB_STEP_SUMMARY"
else
echo "ready=true" >> "$GITHUB_OUTPUT"
fi
- name: Download build
if: steps.guard.outputs.ready == 'true'
uses: actions/download-artifact@v8
with:
name: release-android
path: out
- name: Upload to RuStore
if: steps.guard.outputs.ready == 'true'
env:
RUSTORE_KEY_ID: ${{ secrets.RUSTORE_KEY_ID }}
RUSTORE_PRIVATE_KEY: ${{ secrets.RUSTORE_PRIVATE_KEY }}
ARTIFACT: ${{ inputs.rustore_artifact }}
SUBMIT: ${{ inputs.rustore_submit }}
PUBLISH_TYPE: ${{ inputs.rustore_auto_publish && 'INSTANTLY' || 'MANUAL' }}
NOTES: ${{ inputs.notes_ru || inputs.notes_en }}
run: |
set -euo pipefail
api="https://public-api.rustore.ru"
raw="$RUNNER_TEMP/rustore.raw"
der="$RUNNER_TEMP/rustore.der"
key="$RUNNER_TEMP/rustore.pem"
umask 077
# the secret may be base64 DER or a PEM file, either PKCS#8 or PKCS#1, and a PEM may arrive in one line
# or itself base64-encoded, so everything is brought to DER and openssl detects the structure
printf '%s' "$RUSTORE_PRIVATE_KEY" > "$raw"
if ! grep -q 'BEGIN' "$raw"; then
tr -d '\r\n ' < "$raw" | base64 -d > "$der"
if grep -qa 'BEGIN' "$der"; then cp "$der" "$raw"; fi
fi
if grep -q 'BEGIN' "$raw"; then
sed 's/-----[A-Z ]*-----//g' "$raw" | tr -d '\r\n ' | base64 -d > "$der"
fi
if ! openssl pkey -inform DER -in "$der" -out "$key"; then
echo "::error::RUSTORE_PRIVATE_KEY is not an RSA private key, put the key from the RuStore console there again"
exit 1
fi
rm -f "$raw" "$der"
timestamp=$(date +%Y-%m-%dT%H:%M:%S.%3N%:z)
signature=$(printf '%s' "$RUSTORE_KEY_ID$timestamp" | openssl dgst -sha512 -sign "$key" | openssl base64 -A)
auth=$(jq -n --arg id "$RUSTORE_KEY_ID" --arg ts "$timestamp" --arg sig "$signature" \
'{keyId: $id, timestamp: $ts, signature: $sig}')
session=$(curl -sS -X POST "$api/public/auth/" -H 'Content-Type: application/json' -d "$auth")
rm -f "$key"
token=$(jq -r '.body.jwe // ""' <<< "$session")
if [ -z "$token" ]; then
echo "::error::RuStore authorization failed: $(jq -c '{code, message}' <<< "$session")"
exit 1
fi
echo "::add-mask::$token"
base="$api/public/v1/application/$PACKAGE_NAME"
# dispatch inputs are single-line, \n in them stands for a line break
whats_new=$(printf '%b' "$NOTES")
draft=$(curl -sS -X POST "$base/version" -H "Public-Token: $token" -H 'Content-Type: application/json' \
-d "$(jq -n --arg type "$PUBLISH_TYPE" --arg notes "$whats_new" \
'{publishType: $type} + (if $notes == "" then {} else {whatsNew: $notes} end)')")
if [ "$(jq -r '.code' <<< "$draft")" = 'OK' ]; then
version_id=$(jq -r '.body' <<< "$draft")
else
version_id=$(jq -r '.message // ""' <<< "$draft" | grep -oE '[0-9]{3,}' | tail -n 1 || true)
if [ -z "$version_id" ]; then
echo "::error::RuStore draft was not created: $(jq -c '{code, message}' <<< "$draft")"
exit 1
fi
echo "::notice::reusing the existing RuStore draft $version_id, its release notes stay as they were"
# publishType is set when a draft is created, an older draft keeps its own unless the key may change it
settings=$(curl -sS -X POST "$base/version/$version_id/publish-settings" -H "Public-Token: $token" \
-H 'Content-Type: application/json' -d "$(jq -n --arg type "$PUBLISH_TYPE" '{publishType: $type}')")
if [ "$(jq -r '.code' <<< "$settings")" != 'OK' ]; then
echo "::warning::RuStore kept the draft's publish type: $(jq -c '{code, message}' <<< "$settings")"
fi
fi
set -- out/*."$ARTIFACT"
file=$1
if [ "$ARTIFACT" = 'aab' ]; then
upload_url="$base/version/$version_id/aab?servicesType=Unknown"
else
upload_url="$base/version/$version_id/apk?servicesType=Unknown&isMainApk=true"
fi
upload=$(curl -sS -X POST "$upload_url" -H "Public-Token: $token" -F "file=@$file")
if [ "$(jq -r '.code' <<< "$upload")" != 'OK' ]; then
# a rerun finds the file from the first attempt already in the draft
if jq -r '.message // ""' <<< "$upload" | grep -qi 'already uploaded'; then
echo "::notice::the build is already in RuStore draft $version_id"
else
echo "::error::RuStore upload failed: $(jq -c '{code, message}' <<< "$upload")"
exit 1
fi
fi
if [ "$SUBMIT" = 'true' ]; then
commit=$(curl -sS -X POST "$base/version/$version_id/commit?priorityUpdate=0" -H "Public-Token: $token")
if [ "$(jq -r '.code' <<< "$commit")" != 'OK' ]; then
echo "::error::RuStore moderation request failed: $(jq -c '{code, message}' <<< "$commit")"
exit 1
fi
if [ "$PUBLISH_TYPE" = 'INSTANTLY' ]; then
echo "RuStore: version $version_id sent to moderation, it goes live once approved." >> "$GITHUB_STEP_SUMMARY"
else
echo "RuStore: version $version_id sent to moderation, publish it in the console once approved." >> "$GITHUB_STEP_SUMMARY"
fi
else
echo "RuStore: version $version_id left as a draft." >> "$GITHUB_STEP_SUMMARY"
fi