Repository navigation
451 lines (415 loc) · 19.5 KB
/
Copy pathrelease.yml
File metadata and controls
451 lines (415 loc) · 19.5 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
name: Release
# Makes a tester build of the phone and TV apps: tags the commit
# vX.Y.Z-beta.B, uploads both App Bundles to the Google Play beta track, and
# publishes the APKs on a GitHub prerelease with notes on what changed since
# the last build. promote.yml turns a tester build into a store release.
# See docs/releasing.md.
on:
workflow_dispatch:
inputs:
bump:
description: "build = another build of the unreleased version. minor or patch = start the next version once the current one is promoted."
required: true
type: choice
default: build
options:
- build
- minor
- patch
version:
description: "Optional: use this version (for example 1.2.0) instead of bump."
required: false
type: string
# One release at a time: each run takes the next build number and opens a Play
# edit, and overlapping Play edits conflict.
concurrency:
group: release
cancel-in-progress: false
permissions:
contents: read
defaults:
run:
shell: bash
jobs:
prepare:
name: Choose version and build
runs-on: ubuntu-latest
permissions:
contents: write # create the tag
actions: read # check CI on the commit
outputs:
version: ${{ steps.version.outputs.version }}
build: ${{ steps.version.outputs.build }}
tag: ${{ steps.version.outputs.tag }}
previous_tag: ${{ steps.version.outputs.previous_tag }}
version_code: ${{ steps.version.outputs.version_code }}
play_notes: ${{ steps.notes.outputs.play_notes }}
steps:
- name: Require main
if: github.ref != 'refs/heads/main'
run: |
echo "::error::Releases are made from main."
exit 1
- name: Check out sources
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
fetch-depth: 0 # all tags
persist-credentials: false
- name: Require CI to have passed on this commit
env:
GH_TOKEN: ${{ github.token }}
run: |
conclusion="$(gh run list --repo "${GITHUB_REPOSITORY}" --workflow android-build.yml \
--commit "${GITHUB_SHA}" --event push --limit 1 --json conclusion --jq '.[0].conclusion // ""')"
if [[ "${conclusion}" != "success" ]]; then
echo "::error::Android Builds has not passed on ${GITHUB_SHA::9} (${conclusion:-still running or missing}). Release once it is green."
exit 1
fi
# A promoted version waiting for Play review (a draft vX.Y.Z release)
# counts as released. Listing drafts needs contents: write.
- name: Choose version and build
id: version
env:
GH_TOKEN: ${{ github.token }}
BUMP: ${{ inputs.bump }}
VERSION: ${{ inputs.version }}
run: |
# Read every page: a draft can be older than the newest 100 releases.
draft_tags="$(gh api "repos/${GITHUB_REPOSITORY}/releases" --paginate \
--jq '.[] | select(.draft) | .tag_name')"
drafts=()
for draft in ${draft_tags}; do
drafts+=(--draft "${draft}")
done
python3 scripts/release-version.py next --bump "${BUMP}" --version "${VERSION}" "${drafts[@]}" |
tee -a "${GITHUB_OUTPUT}"
# A tag without a release comes from a run that failed before publishing.
# Starting this build's notes there would leave out changes no tester got.
- name: Require the previous build to have shipped
env:
GH_TOKEN: ${{ github.token }}
PREVIOUS_TAG: ${{ steps.version.outputs.previous_tag }}
run: |
if [[ -n "${PREVIOUS_TAG}" ]] && ! gh release view "${PREVIOUS_TAG}" --repo "${GITHUB_REPOSITORY}" > /dev/null; then
echo "::error::${PREVIOUS_TAG} has no release, so its run failed. Re-run that run's failed jobs. Delete the tag only if that run never uploaded to Play."
exit 1
fi
# Play's "What's new" (500 characters at most): Claude's summary of the
# pull request titles since the last build, or the plain list of Features
# and Fixes when that fails or ANTHROPIC_API_KEY isn't set. Written here
# because generating notes needs contents: write. The key exists only in
# this step, on a GitHub-hosted runner, and the workflow only runs by
# manual dispatch.
- name: Write Play release notes
id: notes
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ steps.version.outputs.tag }}
PREVIOUS_TAG: ${{ steps.version.outputs.previous_tag }}
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
gh api "repos/${GITHUB_REPOSITORY}/releases/generate-notes" \
-f tag_name="${TAG}" -f target_commitish="${GITHUB_SHA}" \
${PREVIOUS_TAG:+-f previous_tag_name="${PREVIOUS_TAG}"} --jq .body > "${RUNNER_TEMP}/notes.md"
play_notes="${RUNNER_TEMP}/play-notes.txt"
if scripts/summarize-release-notes.sh "${RUNNER_TEMP}/notes.md" 500 > "${play_notes}"; then
source="Claude's summary of the merged pull requests"
else
echo "::warning::What's new uses the plain list because the summary failed (see above)."
python3 scripts/release-version.py store-notes 500 < "${RUNNER_TEMP}/notes.md" > "${play_notes}"
source="the plain list of Features and Fixes"
fi
{
echo "### Play \"What's new\""
echo
echo "From ${source}:"
echo
# Indented, so the text shows as a code block whatever it contains.
sed 's/^/ /' "${play_notes}"
} >> "${GITHUB_STEP_SUMMARY}"
delimiter="play_notes_$(python3 -c 'import uuid; print(uuid.uuid4().hex)')"
{
echo "play_notes<<${delimiter}"
cat "${play_notes}"
echo "${delimiter}"
} >> "${GITHUB_OUTPUT}"
# Tagging last in this job reserves the build number once everything
# above succeeded. A later failure keeps the tag: re-run the run's failed
# jobs (see docs/releasing.md).
- name: Tag the commit
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ steps.version.outputs.tag }}
run: gh api "repos/${GITHUB_REPOSITORY}/git/refs" -f ref="refs/tags/${TAG}" -f sha="${GITHUB_SHA}" --silent
play:
name: Upload to Google Play beta
needs: prepare
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.prepare.outputs.version }}
BUILD: ${{ needs.prepare.outputs.build }}
steps:
- name: Check out sources
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
persist-credentials: false
- name: Set up JDK 21
uses: actions/setup-java@03ad4de0992f5dab5e18fcb136590ce7c4a0ac95 # v5
with:
distribution: temurin
java-version: "21"
- name: Set up Gradle
uses: gradle/actions/setup-gradle@3f131e8634966bd73d06cc69884922b02e6faf92 # v6
- name: Set up Ruby
uses: ruby/setup-ruby@14594264cd68ce8a2345dd349bc3d138a4ef85c8 # v1
with:
bundler-cache: true
- name: Decode signing key and Firebase config
run: scripts/decode-release-secrets.sh
env:
SILO_RELEASE_KEYSTORE_B64: ${{ secrets.SILO_RELEASE_KEYSTORE_B64 }}
SILO_RELEASE_KEYSTORE_PASSWORD: ${{ secrets.SILO_RELEASE_KEYSTORE_PASSWORD }}
SILO_RELEASE_KEY_ALIAS: ${{ secrets.SILO_RELEASE_KEY_ALIAS }}
SILO_GOOGLE_SERVICES_JSON_B64: ${{ secrets.SILO_GOOGLE_SERVICES_JSON_B64 }}
# All unit tests, debug and release variants, on this exact commit before
# anything reaches Play. CI's run on main can skip them (a docs-only
# change after a cancelled run) and only covers the debug variant.
- name: Cache Robolectric Android runtimes
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
with:
path: ~/.m2/repository/org/robolectric
key: robolectric-${{ runner.os }}-${{ hashFiles('gradle/libs.versions.toml', '**/build.gradle.kts') }}
restore-keys: |
robolectric-${{ runner.os }}-
- name: Run unit tests
run: |
./gradlew \
-Dorg.gradle.jvmargs="-Xmx4g -Dfile.encoding=UTF-8" \
test \
--max-workers=2
- name: Upload test reports
if: failure()
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5
with:
name: unit-test-reports
path: "**/build/reports/tests/**"
if-no-files-found: ignore
- name: Build App Bundles
env:
VERSION_CODE: ${{ needs.prepare.outputs.version_code }}
SILO_RELEASE_KEYSTORE_PASSWORD: ${{ secrets.SILO_RELEASE_KEYSTORE_PASSWORD }}
SILO_RELEASE_KEY_PASSWORD: ${{ secrets.SILO_RELEASE_KEY_PASSWORD }}
SILO_RELEASE_KEY_ALIAS: ${{ secrets.SILO_RELEASE_KEY_ALIAS }}
run: |
./gradlew \
-Dorg.gradle.jvmargs="-Xmx4g -Dfile.encoding=UTF-8" \
:androidApp:bundleRelease :androidTvApp:bundleRelease \
"-PsiloVersionName=${VERSION}" \
"-PsiloBuildNumber=${BUILD}" \
"-PsiloVersionCode=${VERSION_CODE}" \
-PsiloReleaseChannel=release \
--max-workers=2
- name: Write Play release notes
env:
PLAY_NOTES: ${{ needs.prepare.outputs.play_notes }}
run: |
notes_dir=fastlane/metadata/android/en-US/changelogs
mkdir -p "${notes_dir}"
printf '%s\n' "${PLAY_NOTES}" > "${notes_dir}/default.txt"
cat "${notes_dir}/default.txt"
- name: Upload to the beta track
run: bundle exec fastlane android upload
env:
PLAY_TRACK: beta
PLAY_RELEASE_NAME: ${{ env.VERSION }} (${{ env.BUILD }})
PLAY_SERVICE_ACCOUNT_JSON: ${{ secrets.PLAY_SERVICE_ACCOUNT_JSON }}
apks:
name: Build APKs
needs: prepare
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.prepare.outputs.version }}
BUILD: ${{ needs.prepare.outputs.build }}
steps:
- name: Check out sources
uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
persist-credentials: false
- name: Set up JDK 21
uses: actions/setup-java@03ad4de0992f5dab5e18fcb136590ce7c4a0ac95 # v5
with:
distribution: temurin
java-version: "21"
- name: Set up Gradle
uses: gradle/actions/setup-gradle@3f131e8634966bd73d06cc69884922b02e6faf92 # v6
- name: Decode signing key and Firebase config
run: scripts/decode-release-secrets.sh
env:
SILO_RELEASE_KEYSTORE_B64: ${{ secrets.SILO_RELEASE_KEYSTORE_B64 }}
SILO_RELEASE_KEYSTORE_PASSWORD: ${{ secrets.SILO_RELEASE_KEYSTORE_PASSWORD }}
SILO_RELEASE_KEY_ALIAS: ${{ secrets.SILO_RELEASE_KEY_ALIAS }}
SILO_GOOGLE_SERVICES_JSON_B64: ${{ secrets.SILO_GOOGLE_SERVICES_JSON_B64 }}
# A separate Gradle run from the bundles: the APKs carry the sideload
# channel, and APK splits are switched off whenever a bundle task runs.
- name: Build APKs
env:
VERSION_CODE: ${{ needs.prepare.outputs.version_code }}
SILO_RELEASE_KEYSTORE_PASSWORD: ${{ secrets.SILO_RELEASE_KEYSTORE_PASSWORD }}
SILO_RELEASE_KEY_PASSWORD: ${{ secrets.SILO_RELEASE_KEY_PASSWORD }}
SILO_RELEASE_KEY_ALIAS: ${{ secrets.SILO_RELEASE_KEY_ALIAS }}
run: |
./gradlew \
-Dorg.gradle.jvmargs="-Xmx4g -Dfile.encoding=UTF-8" \
:androidApp:assembleRelease :androidTvApp:assembleRelease \
"-PsiloVersionName=${VERSION}" \
"-PsiloBuildNumber=${BUILD}" \
"-PsiloVersionCode=${VERSION_CODE}" \
-PsiloReleaseChannel=sideload \
--max-workers=2
# One universal APK per app: silo-android-1.0.0-22.apk for phones and
# tablets, silo-android-tv-1.0.0-22.apk for TV. Play serves per-ABI
# splits from the App Bundles; the per-ABI APKs Gradle also builds stay
# local.
- name: Name the APKs
run: |
mkdir apks
cp androidApp/build/outputs/apk/release/androidApp-universal-release.apk "apks/silo-android-${VERSION}-${BUILD}.apk"
cp androidTvApp/build/outputs/apk/release/androidTvApp-universal-release.apk "apks/silo-android-tv-${VERSION}-${BUILD}.apk"
ls -l apks
- name: Upload APKs
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5
with:
name: apks
path: apks/*.apk
if-no-files-found: error
publish:
name: Publish the GitHub prerelease
needs: [prepare, play, apks]
runs-on: ubuntu-latest
permissions:
contents: write
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
VERSION: ${{ needs.prepare.outputs.version }}
BUILD: ${{ needs.prepare.outputs.build }}
TAG: ${{ needs.prepare.outputs.tag }}
PREVIOUS_TAG: ${{ needs.prepare.outputs.previous_tag }}
BETA_LATEST: beta-latest
steps:
- name: Download APKs
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5
with:
name: apks
path: apks
- name: Publish the prerelease
run: |
# "Re-run failed jobs" re-runs this whole job. When this run already
# created the prerelease, upload only the APKs it lacks (--clobber
# would delete a good copy first), then publish it: gh release create
# leaves a draft when an upload fails.
if gh release view "${TAG}" > /dev/null 2>&1; then
uploaded="$(gh release view "${TAG}" --json assets --jq '.assets[] | select(.state == "uploaded") | .name')"
for apk in apks/*.apk; do
if ! grep -qxF "$(basename "${apk}")" <<< "${uploaded}"; then
# A failed upload can leave a broken asset under this name.
gh release upload "${TAG}" --clobber "${apk}"
fi
done
gh release edit "${TAG}" --draft=false --prerelease
echo "${TAG} is published with both APKs."
exit 0
fi
{
echo "Tester build ${VERSION} (${BUILD}), also on the Google Play beta track."
echo
gh api "repos/${GH_REPO}/releases/generate-notes" \
-f tag_name="${TAG}" ${PREVIOUS_TAG:+-f previous_tag_name="${PREVIOUS_TAG}"} --jq .body
echo
echo "### Install"
echo
echo "Phones and tablets: \`silo-android-${VERSION}-${BUILD}.apk\`."
echo "Android TV: \`silo-android-tv-${VERSION}-${BUILD}.apk\`."
echo
echo "To install with Downloader by AFTVnews, use code 2988950 for phones and tablets or 6033910 for Android TV. Both install the newest tester build from the [latest tester build](https://github.com/${GH_REPO}/releases/tag/${BETA_LATEST}) release."
} > notes.md
# A prerelease never becomes Latest, so the store Downloader codes and
# the releases/latest links keep pointing at the store release.
gh release create "${TAG}" --verify-tag --prerelease \
--title "Silo Android ${VERSION} (${BUILD})" --notes-file notes.md apks/*.apk
# One prerelease, tag beta-latest, always holds the newest tester build
# under fixed names, so the beta Downloader codes can point at
# releases/download/beta-latest/silo-android-latest-beta.apk and
# silo-android-tv-latest-beta.apk. GitHub's releases/latest links skip
# prereleases, so they can't do this. Version tags start with v, so the
# version script and Promote never see this one.
- name: Update the latest tester build
run: |
# A re-run of an older build must not replace a newer one.
newest="$(gh release list --limit 100 --json tagName,isPrerelease \
--jq '[.[] | select(.isPrerelease and (.tagName | test("-beta[.][0-9]+$")))][0].tagName')"
if [[ "${newest}" != "${TAG}" ]]; then
echo "${newest} is newer than ${TAG}; leaving ${BETA_LATEST} alone."
exit 0
fi
# The first run creates the tag and the release.
if ! gh api "repos/${GH_REPO}/git/refs/tags/${BETA_LATEST}" > /dev/null 2>&1; then
gh api "repos/${GH_REPO}/git/refs" -f ref="refs/tags/${BETA_LATEST}" -f sha="${GITHUB_SHA}" --silent
fi
if ! gh release view "${BETA_LATEST}" > /dev/null 2>&1; then
gh release create "${BETA_LATEST}" --verify-tag --prerelease --title "Latest tester build" --notes "Being updated."
fi
# Upload each APK under a staging name, then swap it in, so a failed
# upload never leaves the Downloader links without a file. The old
# file steps aside as previous-<name> and comes back if the swap
# fails. Every step is safe to repeat on a re-run.
release_id="$(gh release view "${BETA_LATEST}" --json databaseId --jq .databaseId)"
asset_id() {
gh api "repos/${GH_REPO}/releases/${release_id}/assets" --paginate \
--jq ".[] | select(.name == \"$1\") | .id"
}
rename_asset() {
gh api -X PATCH "repos/${GH_REPO}/releases/assets/$1" -f name="$2" --silent
}
delete_asset() {
gh api -X DELETE "repos/${GH_REPO}/releases/assets/$1" --silent
}
# Upload both staged files before swapping either, so a failed upload
# leaves the phone and TV links on the same build.
for app in silo-android silo-android-tv; do
cp "apks/${app}-${VERSION}-${BUILD}.apk" "apks/next-${app}-latest-beta.apk"
gh release upload "${BETA_LATEST}" --clobber "apks/next-${app}-latest-beta.apk"
done
for app in silo-android silo-android-tv; do
name="${app}-latest-beta.apk"
staged="next-${name}"
previous="previous-${name}"
staged_id="$(asset_id "${staged}")"
current_id="$(asset_id "${name}")"
if [[ -n "${current_id}" ]]; then
# The live file is safe, so a copy left by an interrupted run can go.
stale_id="$(asset_id "${previous}")"
if [[ -n "${stale_id}" ]]; then
delete_asset "${stale_id}"
fi
rename_asset "${current_id}" "${previous}"
fi
if ! rename_asset "${staged_id}" "${name}"; then
# Put the old file back, whether this run or an interrupted one
# moved it aside.
restore_id="$(asset_id "${previous}")"
if [[ -n "${restore_id}" ]]; then
rename_asset "${restore_id}" "${name}"
fi
echo "::error::Couldn't swap in ${name}; the previous file is still served. Re-run failed jobs."
exit 1
fi
for old_id in $(asset_id "${previous}"); do
delete_asset "${old_id}"
done
done
# Point the tag and title at this build only once its files are live.
gh api -X PATCH "repos/${GH_REPO}/git/refs/tags/${BETA_LATEST}" -f sha="${GITHUB_SHA}" -F force=true --silent
gh release edit "${BETA_LATEST}" --prerelease \
--title "Latest tester build: ${VERSION} (${BUILD})" \
--notes "The newest tester build, ${TAG}, under fixed file names for the beta Downloader codes. Release notes and versioned APKs are on [${TAG}](https://github.com/${GH_REPO}/releases/tag/${TAG})."