Repository navigation
103 lines (90 loc) · 4.39 KB
/
Copy pathrelease.yml
File metadata and controls
103 lines (90 loc) · 4.39 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
name: Release
# Builds a signed AAB for Play and an APK for sideloading on every merge to main, and
# publishes both on the GitHub release for the current versionName (v1.4.0 …), replacing
# the files of the previous build of that version.
#
# The very first AAB has to be uploaded manually through the Play Console — the
# Publishing API cannot create a new app, only push to one that already exists.
# After that, the last step uploads every main build to the internal track once the
# PLAY_SERVICE_ACCOUNT_JSON secret is set.
on:
push:
branches: [main]
tags: ["v*"]
workflow_dispatch:
# The default GITHUB_TOKEN is read-only here, so the tag build could compile and
# sign an APK and then 403 on the one step that publishes it. Releases need
# contents: write.
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
timeout-minutes: 40
env:
# A step's `if` cannot read secrets; expose only whether the Play key exists.
PLAY_UPLOAD_CONFIGURED: ${{ secrets.PLAY_SERVICE_ACCOUNT_JSON != '' }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: "17"
distribution: temurin
- uses: gradle/actions/setup-gradle@v4
# Never ship a red build.
- name: Run unit tests
run: ./gradlew testDebugUnitTest
# Every build of main gets a fresh, increasing versionCode so Play accepts it.
- name: Set version
run: |
echo "VERSION_CODE=$((100 + GITHUB_RUN_NUMBER))" >> "$GITHUB_ENV"
echo "VERSION_NAME=$(sed -n 's/.*versionName = "\(.*\)".*/\1/p' app/build.gradle.kts | head -1)" >> "$GITHUB_ENV"
- name: Decode keystore
env:
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
run: echo "$KEYSTORE_BASE64" | base64 --decode > scanrift-release.jks
- name: Build release bundle and APK
env:
RELEASE_STORE_PASSWORD: ${{ secrets.RELEASE_STORE_PASSWORD }}
RELEASE_KEY_PASSWORD: ${{ secrets.RELEASE_KEY_PASSWORD }}
run: ./gradlew bundleRelease assembleRelease
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: scanrift-release
path: |
app/build/outputs/bundle/release/app-release.aab
app/build/outputs/apk/release/app-release.apk
- name: Publish on the GitHub release
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
env:
GH_TOKEN: ${{ github.token }}
run: |
tag="v${VERSION_NAME}"
dir=dist && mkdir -p "$dir"
cp app/build/outputs/bundle/release/app-release.aab "$dir/scanrift-${VERSION_NAME}-${VERSION_CODE}.aab"
cp app/build/outputs/apk/release/app-release.apk "$dir/scanrift-${VERSION_NAME}-${VERSION_CODE}.apk"
if ! gh release view "$tag" >/dev/null 2>&1; then
gh release create "$tag" --target "$GITHUB_SHA" --title "ScanRift ${VERSION_NAME}" --generate-notes
fi
# Keep only this build's files on the release: drop the previous build's.
gh release view "$tag" --json assets -q '.assets[].name' | grep -E '^scanrift-.*\.(aab|apk)$' | while read -r old; do
gh release delete-asset "$tag" "$old" --yes
done
gh release upload "$tag" "$dir"/* --clobber
echo "Published ${VERSION_NAME} (${VERSION_CODE}) on $tag" >> "$GITHUB_STEP_SUMMARY"
# Sends every main build to a Play testing track (repository variable PLAY_TRACK:
# internal, alpha = closed testing, beta = open testing; default internal). Skipped until the
# PLAY_SERVICE_ACCOUNT_JSON secret exists. Play accepts only *draft* releases until
# the app has passed its first review: set the repository variable
# PLAY_RELEASE_STATUS to `completed` after that, so builds reach testers directly.
- name: Upload to Play internal track
if: github.ref == 'refs/heads/main' && env.PLAY_UPLOAD_CONFIGURED == 'true'
uses: r0adkll/upload-google-play@v1
with:
serviceAccountJsonPlainText: ${{ secrets.PLAY_SERVICE_ACCOUNT_JSON }}
packageName: com.scanrift.android
releaseFiles: app/build/outputs/bundle/release/app-release.aab
releaseName: ${{ env.VERSION_NAME }} (${{ env.VERSION_CODE }})
track: ${{ vars.PLAY_TRACK || 'internal' }}
status: ${{ vars.PLAY_RELEASE_STATUS || 'draft' }}