-
Notifications
You must be signed in to change notification settings - Fork 8
73 lines (63 loc) · 3.13 KB
/
attach_apk_to_release.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
name: Attach APK To Release
on:
release:
types:
- published
jobs:
attach-apk:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Clone repository
uses: actions/checkout@v4
with:
ref: ${{ env.GITHUB_REF }}
- name: Generate keystore properties
run: |
if [ ! -z "${{ secrets.KEYSTORE }}" ]; then
echo storeFile='keystore.jks' > keystore.properties
echo storePassword='${{ secrets.STORE_PASSWORD }}' >> keystore.properties
echo keyAlias='${{ secrets.KEY_ALIAS }}' >> keystore.properties
echo keyPassword='${{ secrets.KEY_PASSWORD }}' >> keystore.properties
echo ${{ secrets.KEYSTORE }} | base64 --decode > keystore.jks # Generated with `base64 -w 0 keystore.jks > keystore.base64`
fi
- name: Build and attach APK to release
shell: bash {0}
run: |
exit_on_error() {
echo "$1"
echo "Deleting '$RELEASE_VERSION_NAME' release and '$GITHUB_REF' tag"
gh release delete --cleanup-tag --yes "$RELEASE_VERSION_NAME"
git push --delete origin "$GITHUB_REF"
exit 1
}
echo "Setting vars"
RELEASE_VERSION_NAME="${GITHUB_REF/refs\/tags\//}"
if ! printf "%s" "${RELEASE_VERSION_NAME/v/}" | grep -qP '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'; then
exit_on_error "The versionName '${RELEASE_VERSION_NAME/v/}' is not a valid version as per semantic version '2.0.0' spec in the format 'major.minor.patch(-prerelease)(+buildmetadata)'. https://semver.org/spec/v2.0.0.html."
fi
APK_DIR_PATH="./app/build/outputs/apk/release"
APK_VERSION_TAG="$RELEASE_VERSION_NAME+github-release"
APK_BASENAME_PREFIX="XLogcatManager_$APK_VERSION_TAG"
echo "Building APK for '$RELEASE_VERSION_NAME' release"
export XLOGCATMANAGER_APK_VERSION_TAG="$APK_VERSION_TAG" # Used by app/build.gradle
if ! ./gradlew assembleRelease; then
exit_on_error "Build failed for '$RELEASE_VERSION_NAME' release."
fi
echo "Validating APK"
if ! test -f "$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk"; then
files_found="$(ls "$APK_DIR_PATH")"
exit_on_error "Failed to find built APK at '$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk'. Files found: "$'\n'"$files_found"
fi
echo "Generating sha25sums file"
if ! (cd "$APK_DIR_PATH"; sha256sum "${APK_BASENAME_PREFIX}.apk" > sha256sums); then
exit_on_error "Generate sha25sums failed for '$RELEASE_VERSION_NAME' release."
fi
echo "Attaching APK to github release"
if ! gh release upload "$RELEASE_VERSION_NAME" \
"$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk" \
"$APK_DIR_PATH/sha256sums" \
; then
exit_on_error "Attach APK to release failed for '$RELEASE_VERSION_NAME' release."
fi