From ecc41cdbd51ffd0da386e41f84a9a93719d545af Mon Sep 17 00:00:00 2001 From: Leonhard Breuer Date: Sat, 7 Nov 2026 16:27:31 +0100 Subject: [PATCH] ci: publish signed release APKs from version tags A vMAJOR.MINOR.PATCH tag builds a release APK with FCM, signed with the key from repository secrets, and attaches it to a GitHub release. Release builds without CRUMBLE_KEYSTORE_PATH stay unsigned. --- .github/workflows/release.yml | 56 +++++++++++++++++++++++++++++++++++ CHANGELOG.md | 1 + README.md | 12 ++++++++ app/build.gradle.kts | 18 +++++++++-- 4 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b3e19b6 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,56 @@ +name: Android release + +on: + push: + tags: ['v*'] + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0 + with: + distribution: temurin + java-version: '17' + - uses: android-actions/setup-android@be39fa834029ff78f1a44aa3bb0819b8fc2bd8fd # v4.0.4 + with: + packages: 'platform-tools platforms;android-36 build-tools;36.0.0' + - name: Read the version from the tag + id: version + run: | + version="${GITHUB_REF_NAME#v}" + if [[ ! "$version" =~ ^([0-9]+)\.([0-9]{1,2})\.([0-9]{1,2})$ ]]; then + echo "::error::Tag $GITHUB_REF_NAME must be vMAJOR.MINOR.PATCH with MINOR and PATCH below 100" + exit 1 + fi + echo "name=$version" >> "$GITHUB_OUTPUT" + echo "code=$((BASH_REMATCH[1] * 10000 + 10#${BASH_REMATCH[2]} * 100 + 10#${BASH_REMATCH[3]}))" >> "$GITHUB_OUTPUT" + - name: Restore the signing key and Firebase config + env: + KEYSTORE: ${{ secrets.ANDROID_KEYSTORE_BASE64 }} + GOOGLE_SERVICES: ${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }} + run: | + echo "$KEYSTORE" | base64 --decode > "$RUNNER_TEMP/release.jks" + echo "$GOOGLE_SERVICES" | base64 --decode > app/google-services.json + - name: Build the signed APK + env: + CRUMBLE_KEYSTORE_PATH: ${{ runner.temp }}/release.jks + CRUMBLE_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }} + run: >- + ./gradlew assembleRelease + -Pcrumble.versionName=${{ steps.version.outputs.name }} + -Pcrumble.versionCode=${{ steps.version.outputs.code }} + - name: Publish the GitHub release + env: + GH_TOKEN: ${{ github.token }} + VERSION: ${{ steps.version.outputs.name }} + run: | + apk="crumble-$VERSION.apk" + cp app/build/outputs/apk/release/app-release.apk "$apk" + gh release create "$GITHUB_REF_NAME" "$apk" --repo "$GITHUB_REPOSITORY" --title "Crumble $VERSION" --generate-notes diff --git a/CHANGELOG.md b/CHANGELOG.md index 77479a8..da77f2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- Publish signed release APKs: a `vX.Y.Z` tag builds one with FCM and attaches it to a GitHub release. Release builds are signed when `CRUMBLE_KEYSTORE_PATH` and `CRUMBLE_KEYSTORE_PASSWORD` are set, and take their version from `crumble.versionName` and `crumble.versionCode`. - The bot form shows the portrait with a pencil, and the avatar editor opens in a dialog instead of filling the form, as on the web. - Pin the bot's `6.0.0` contract as a local export and bump the generator to `1.1.0`, adding closed objects with declared properties, nullable named schemas and `allOf` parts, and `*/*` binary responses. - Sign in with account email and password. The server token is gone; the app stores the returned session. diff --git a/README.md b/README.md index 10a4d81..e0f9f7e 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,18 @@ python3 scripts/contract.py update --release contract-vX.Y.Z # Update to a publi python3 scripts/contract.py update --local EXPORT_DIR # Update from a local bot bundle ``` +## Release + +Pushing a `vMAJOR.MINOR.PATCH` tag runs `.github/workflows/release.yml`, which builds a signed release APK with FCM and attaches it to a GitHub release. The version code is `MAJOR * 10000 + MINOR * 100 + PATCH`, so minor and patch stay below 100. + +The workflow reads three repository secrets: `ANDROID_KEYSTORE_BASE64` (the base64 of the release keystore), `ANDROID_KEYSTORE_PASSWORD`, and `GOOGLE_SERVICES_JSON_BASE64`. Every update must be signed with the same keystore, alias `crumble`, so keep a backup of it. + +To sign a release build locally: + +```bash +CRUMBLE_KEYSTORE_PATH=~/crumble-release.jks CRUMBLE_KEYSTORE_PASSWORD=... ./gradlew assembleRelease +``` + ## Push notifications (optional) Without `app/google-services.json`, the app builds cleanly and posts local notifications while connected to `/v1/events`. To enable background delivery via Firebase Cloud Messaging (FCM), place `google-services.json` registering `ng.crumbli.android` and `ng.crumbli.android.dev` in `app/` and set `CRUMBLE_FCM_SERVICE_ACCOUNT_PATH` on the server (see `bot/docs/native-push.md`). diff --git a/app/build.gradle.kts b/app/build.gradle.kts index a2ef9a3..25c2323 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -17,8 +17,21 @@ android { applicationId = "ng.crumbli.android" minSdk = 26 targetSdk = 36 - versionCode = 1 - versionName = "1.0" + versionCode = providers.gradleProperty("crumble.versionCode").orNull?.toInt() ?: 1 + versionName = providers.gradleProperty("crumble.versionName").orNull ?: "1.0" + } + + // Release signing needs the key, which only CI and the maintainer have; without it, release builds stay unsigned. + val releaseKeystore = providers.environmentVariable("CRUMBLE_KEYSTORE_PATH").orNull + signingConfigs { + if (releaseKeystore != null) { + create("release") { + storeFile = file(releaseKeystore) + storePassword = providers.environmentVariable("CRUMBLE_KEYSTORE_PASSWORD").get() + keyAlias = "crumble" + keyPassword = storePassword + } + } } buildTypes { @@ -27,6 +40,7 @@ android { applicationIdSuffix = ".dev" } release { + signingConfig = signingConfigs.findByName("release") isMinifyEnabled = false proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") }