Build APK & Create Release #14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# written in such a way that this exact same file can be created in .github/workflows in | |
# obbimi/Squore | |
# obbimi/TennisPadel | |
# obbimi/Tabletennis | |
# obbimi/Badminton etc to create obbimi/xxx/Release.### | |
# | |
# please note that all 4 secrets (GSM_API_KEY, KEYSTORE_BASE64, KEYSTORE_PASSWORD, GH_ACCESS_TOKEN) need to be present in EACH repo | |
# | |
name: Build APK & Create Release | |
on: | |
workflow_dispatch: # run manually | |
inputs: | |
release_in_draft: | |
description: Leave the release in draft | |
type: boolean | |
default: true | |
required: true | |
generateReleaseNotes: | |
description: Generate release notes for the release | |
type: boolean | |
default: false | |
required: true | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup Java JDK | |
uses: | |
actions/[email protected] | |
with: | |
java-version: 11 | |
distribution: 'adopt' | |
- name: Checkout the code | |
uses: actions/[email protected] | |
with: | |
repository: obbimi/Squore # overwrite the default ${{ github.repository }}. Our java code/resources is always in the Squore repo | |
#ref: main | |
- name: Prepare for build | |
id: prepare_for_build | |
env: | |
GSM_API_KEY: ${{ secrets.GSM_API_KEY }} | |
run: | | |
set -x | |
# make support files executable | |
chmod +x ./gradlew ./build.gradle.adapt.for.github.workflow.sh ./change.R.package.sh | |
./build.gradle.adapt.for.github.workflow.sh ${GSM_API_KEY} | |
# adapt sources and res files to build different brand | |
brand=$(echo "${{ github.repository }}" | cut -d '/' -f 2) | |
./change.R.package.sh ${brand} | |
# Extract the version from build.gradle | |
VERSION=$(grep 'def\s*versionCodeXXX' build.gradle | cut -d '=' -f 2 | tr -d ' ') | |
echo "version=$VERSION" >> $GITHUB_OUTPUT | |
- name: Build unsigned release .apk files | |
run: | | |
./gradlew build | |
- name: Sign .apk files | |
env: | |
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }} | |
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }} | |
run: | | |
set -x | |
brand=$(echo "${{ github.repository }}" | cut -d '/' -f 2) | |
#baseBrand=Squore | |
baseBrand=$brand | |
echo "${KEYSTORE_BASE64}" | base64 -d > apksign.keystore | |
androidhome="${ANDROID_HOME:-${ANDROID_SDK}}" | |
find . -name *.apk | |
for unsignedFn in build/outputs/apk/*/release/*.apk; do | |
unbrandedSignedFn=${unsignedFn/release-unsigned/release-signed} | |
signedFn=${unbrandedSignedFn/${baseBrand}/${brand}.${{ steps.prepare_for_build.outputs.version }}} | |
${androidhome}/build-tools/$(ls ${androidhome}/build-tools/ | tail -1)/apksigner sign --ks apksign.keystore --ks-pass pass:"${KEYSTORE_PASSWORD}" --out "${signedFn}" "${unsignedFn}" | |
done | |
rm -v apksign.keystore | |
find . -name *.apk | |
- name: Upload .apk to /releases | |
uses: ncipollo/release-action@v1 | |
with: | |
draft: ${{ inputs.release_in_draft }} # Sets the release as a draft instead of publishing it, allowing you to make any edits needed before publishing | |
token: ${{ secrets.GH_ACCESS_TOKEN }} | |
tag: "${{ steps.prepare_for_build.outputs.version }}" | |
artifacts: ./build/outputs/apk/*/release/*-*-release-signed.apk | |
generateReleaseNotes: ${{ inputs.generateReleaseNotes }} | |
#make_latest: true |