Skip to content

feat: Update version code to 22 and version name to 1.6.0 #18

feat: Update version code to 22 and version name to 1.6.0

feat: Update version code to 22 and version name to 1.6.0 #18

Workflow file for this run

name: Release
on:
push:
branches:
- main
paths:
- app/build.gradle.kts
workflow_dispatch:
concurrency:
group: "${{ github.workflow }}-global"
cancel-in-progress: true
jobs:
build_and_release:
name: Build APKs and create release
runs-on: ubuntu-latest
permissions:
contents: write
timeout-minutes: 60
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect version update
id: version
shell: bash
run: |
set -euo pipefail
extract_version_code() {
grep -E 'versionCode\s*=\s*[0-9]+' "$1" | head -n1 | sed -E 's/.*=\s*([0-9]+).*/\1/'
}
extract_version_name() {
grep -E 'versionName\s*=\s*"[^"]+"' "$1" | head -n1 | sed -E 's/.*=\s*"([^"]+)".*/\1/'
}
extract_application_id() {
grep -E 'applicationId\s*=\s*"[^"]+"' "$1" | head -n1 | sed -E 's/.*=\s*"([^"]+)".*/\1/'
}
current_file="app/build.gradle.kts"
current_version_code="$(extract_version_code "$current_file")"
current_version_name="$(extract_version_name "$current_file")"
current_application_id="$(extract_application_id "$current_file")"
if [[ -z "$current_version_code" || -z "$current_version_name" ]]; then
echo "Failed to extract versionCode/versionName from $current_file."
echo "current_version_code='$current_version_code' current_version_name='$current_version_name'"
exit 1
fi
if [[ -z "$current_application_id" ]]; then
echo "Failed to extract applicationId from $current_file."
exit 1
fi
previous_version_code=""
previous_version_name=""
if [[ "${{ github.event_name }}" == "push" && -n "${{ github.event.before }}" ]]; then
previous_file="$(mktemp)"
if git show "${{ github.event.before }}:$current_file" > "$previous_file" 2>/dev/null; then
previous_version_code="$(extract_version_code "$previous_file" || true)"
previous_version_name="$(extract_version_name "$previous_file" || true)"
else
echo "Could not read previous version from commit ${{ github.event.before }}."
fi
else
echo "No previous commit SHA available for event '${{ github.event_name }}'."
fi
should_release="true"
if [[ "$current_version_code" == "$previous_version_code" && "$current_version_name" == "$previous_version_name" ]]; then
should_release="false"
fi
tag_name="v$current_version_name"
if git ls-remote --tags origin "refs/tags/$tag_name" | grep -q "$tag_name"; then
should_release="false"
echo "Tag $tag_name already exists. Skipping release."
fi
echo "should_release=$should_release" >> "$GITHUB_OUTPUT"
echo "version_code=$current_version_code" >> "$GITHUB_OUTPUT"
echo "version_name=$current_version_name" >> "$GITHUB_OUTPUT"
echo "application_id=$current_application_id" >> "$GITHUB_OUTPUT"
echo "tag_name=$tag_name" >> "$GITHUB_OUTPUT"
- name: Copy CI gradle.properties
if: steps.version.outputs.should_release == 'true'
run: mkdir -p ~/.gradle ; cp .github/gradle-ci.properties ~/.gradle/gradle.properties
- name: Set up JDK 21
if: steps.version.outputs.should_release == 'true'
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 21
- name: Setup Gradle
if: steps.version.outputs.should_release == 'true'
uses: gradle/actions/setup-gradle@v4
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
build-scan-publish: true
build-scan-terms-of-use-url: "https://gradle.com/terms-of-service"
build-scan-terms-of-use-agree: "yes"
- name: Validate release secrets
if: steps.version.outputs.should_release == 'true'
shell: bash
env:
ANDROID_RELEASE_KEYSTORE_B64: ${{ secrets.ANDROID_RELEASE_KEYSTORE_B64 }}
ANDROID_RELEASE_STORE_PASSWORD: ${{ secrets.ANDROID_RELEASE_STORE_PASSWORD }}
ANDROID_RELEASE_KEY_ALIAS: ${{ secrets.ANDROID_RELEASE_KEY_ALIAS }}
ANDROID_RELEASE_KEY_PASSWORD: ${{ secrets.ANDROID_RELEASE_KEY_PASSWORD }}
PLAY_SERVICE_ACCOUNT_JSON: ${{ secrets.PLAY_SERVICE_ACCOUNT_JSON }}
run: |
set -euo pipefail
if [ -z "$ANDROID_RELEASE_KEYSTORE_B64" ]; then
echo "ANDROID_RELEASE_KEYSTORE_B64 is required for releases."
exit 1
fi
if [ -z "$ANDROID_RELEASE_STORE_PASSWORD" ]; then
echo "ANDROID_RELEASE_STORE_PASSWORD is required for releases."
exit 1
fi
if [ -z "$ANDROID_RELEASE_KEY_ALIAS" ]; then
echo "ANDROID_RELEASE_KEY_ALIAS is required for releases."
exit 1
fi
if [ -z "$ANDROID_RELEASE_KEY_PASSWORD" ]; then
echo "ANDROID_RELEASE_KEY_PASSWORD is required for releases."
exit 1
fi
if [ -z "$PLAY_SERVICE_ACCOUNT_JSON" ]; then
echo "PLAY_SERVICE_ACCOUNT_JSON is required for releases."
exit 1
fi
- name: Prepare release keystore
if: steps.version.outputs.should_release == 'true'
shell: bash
env:
ANDROID_RELEASE_KEYSTORE_B64: ${{ secrets.ANDROID_RELEASE_KEYSTORE_B64 }}
run: |
set -euo pipefail
keystore_path="$RUNNER_TEMP/release-signing.jks"
if ! printf '%s' "$ANDROID_RELEASE_KEYSTORE_B64" | base64 --decode > "$keystore_path" 2>/dev/null; then
echo "Failed to decode ANDROID_RELEASE_KEYSTORE_B64. Ensure it is valid base64 keystore data."
exit 1
fi
chmod 600 "$keystore_path"
echo "ANDROID_RELEASE_KEYSTORE_PATH=$keystore_path" >> "$GITHUB_ENV"
- name: Build Play and OSS release artifacts
if: steps.version.outputs.should_release == 'true'
env:
ANDROID_RELEASE_STORE_PASSWORD: ${{ secrets.ANDROID_RELEASE_STORE_PASSWORD }}
ANDROID_RELEASE_KEY_ALIAS: ${{ secrets.ANDROID_RELEASE_KEY_ALIAS }}
ANDROID_RELEASE_KEY_PASSWORD: ${{ secrets.ANDROID_RELEASE_KEY_PASSWORD }}
run: ./gradlew :app:assemblePlayRelease :app:bundlePlayRelease :app:assembleOssRelease
- name: Validate release outputs
if: steps.version.outputs.should_release == 'true'
shell: bash
run: |
set -euo pipefail
shopt -s nullglob
play_apks=(app/build/outputs/apk/play/release/*.apk)
if [ "${#play_apks[@]}" -eq 0 ]; then
echo "No Play release APK files found."
exit 1
fi
oss_apks=(app/build/outputs/apk/oss/release/*.apk)
if [ "${#oss_apks[@]}" -eq 0 ]; then
echo "No OSS release APK files found."
exit 1
fi
aabs=(app/build/outputs/bundle/playRelease/*.aab)
shopt -u nullglob
if [ "${#aabs[@]}" -eq 0 ]; then
echo "No Play release AAB files found."
exit 1
fi
if ls app/build/outputs/apk/play/release/*-unsigned.apk >/dev/null 2>&1; then
echo "Found unsigned Play release APK. Configure release signing before publishing."
exit 1
fi
if ls app/build/outputs/apk/oss/release/*-unsigned.apk >/dev/null 2>&1; then
echo "Found unsigned OSS release APK. Configure release signing before publishing."
exit 1
fi
- name: Upload to Play Store (Internal Track)
if: steps.version.outputs.should_release == 'true'
uses: r0adkll/upload-google-play@v1
with:
serviceAccountJsonPlainText: ${{ secrets.PLAY_SERVICE_ACCOUNT_JSON }}
packageName: ${{ steps.version.outputs.application_id }}
releaseFiles: app/build/outputs/bundle/playRelease/*.aab
track: internal
status: completed
- name: Create GitHub Release and upload APKs
if: steps.version.outputs.should_release == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag_name }}
target_commitish: ${{ github.sha }}
name: ${{ steps.version.outputs.tag_name }}
generate_release_notes: true
files: |
app/build/outputs/apk/play/release/*.apk
app/build/outputs/apk/oss/release/*.apk