From da83af5bc674c0cec0089d772c377927d7fed534 Mon Sep 17 00:00:00 2001 From: Mateusz Pstrucha Date: Tue, 22 Sep 2026 19:55:18 +0200 Subject: [PATCH] Add CI, release workflow, and release signing Signing config and version metadata come from the environment, so no keystore or credentials live in the repo. signingConfig resolves to null when unset rather than falling back to the debug key, so a local release build comes out unsigned instead of undistributable-but-looking-fine. versionCode is derived from the git tag to keep it monotonic and aligned with the version users see. CI asserts Play Services and Firebase stay out of the dependency tree, which the spec requires but nothing else enforces. Co-Authored-By: Claude Opus 5 --- .gitea/workflows/ci.yml | 39 +++++++++++++++++++ .gitea/workflows/release.yml | 74 ++++++++++++++++++++++++++++++++++++ .gitignore | 1 + app/build.gradle.kts | 27 ++++++++++++- 4 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 .gitea/workflows/ci.yml create mode 100644 .gitea/workflows/release.yml diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..d289736 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,39 @@ +name: CI + +on: + push: + branches: [master] + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '17' + + - uses: android-actions/setup-android@v3 + + - uses: actions/cache@v4 + with: + path: ~/.gradle/caches + key: gradle-${{ hashFiles('**/*.gradle.kts', 'gradle/wrapper/gradle-wrapper.properties') }} + restore-keys: gradle- + + - run: ./gradlew assembleDebug --no-daemon + + # Hard constraint from android-client-spec.md ยง7: nothing Google- + # dependent, including transitive pulls. Cheap to assert here, and far + # easier than noticing a library dragged it in three months from now. + - name: Assert no Play Services or Firebase + run: | + if ./gradlew :app:dependencies --configuration releaseRuntimeClasspath --no-daemon \ + | grep -iE 'play-services|firebase|com\.google\.android\.gms'; then + echo "::error::Play Services/Firebase found in the dependency tree" + exit 1 + fi + echo "Dependency tree is clean." diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..49c31c2 --- /dev/null +++ b/.gitea/workflows/release.yml @@ -0,0 +1,74 @@ +name: Release + +on: + push: + tags: ['v*'] + +jobs: + apk: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '17' + + - uses: android-actions/setup-android@v3 + + - name: Derive version + id: version + run: | + VERSION="${GITHUB_REF_NAME#v}" + MAJOR="${VERSION%%.*}"; REST="${VERSION#*.}" + MINOR="${REST%%.*}"; PATCH="${REST#*.}" + PATCH="${PATCH%%-*}" # drop any -rc1 suffix + # Monotonic and human-readable: 0.3.1 -> 301, 1.12.0 -> 11200. + # Android requires versionCode to only ever increase; deriving it + # from the tag means it can't drift from what users see. + echo "name=$VERSION" >> "$GITHUB_OUTPUT" + echo "code=$((MAJOR * 10000 + MINOR * 100 + PATCH))" >> "$GITHUB_OUTPUT" + + - name: Decode keystore + env: + KEYSTORE_B64: ${{ secrets.ANDROID_KEYSTORE_B64 }} + run: | + if [ -z "$KEYSTORE_B64" ]; then + echo "::error::ANDROID_KEYSTORE_B64 is not set โ€” refusing to publish an unsigned release." + exit 1 + fi + echo "$KEYSTORE_B64" | base64 -d > "$RUNNER_TEMP/tern-release.jks" + + - name: Build signed APK + env: + TERN_KEYSTORE_PATH: ${{ runner.temp }}/tern-release.jks + TERN_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }} + TERN_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }} + TERN_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }} + TERN_VERSION_NAME: ${{ steps.version.outputs.name }} + TERN_VERSION_CODE: ${{ steps.version.outputs.code }} + run: ./gradlew assembleRelease --no-daemon + + - name: Verify signature and stage artifact + run: | + APK=app/build/outputs/apk/release/app-release.apk + APKSIGNER="$(find "$ANDROID_HOME/build-tools" -name apksigner | sort -V | tail -1)" + # Fails loudly if the APK came out unsigned โ€” otherwise an + # unsigned build would sail through to a published release. + "$APKSIGNER" verify --print-certs "$APK" + cp "$APK" "tern-${{ steps.version.outputs.name }}.apk" + sha256sum "tern-${{ steps.version.outputs.name }}.apk" \ + > "tern-${{ steps.version.outputs.name }}.apk.sha256" + + - name: Clean up keystore + if: always() + run: rm -f "$RUNNER_TEMP/tern-release.jks" + + - name: Publish release + uses: akkuman/gitea-release-action@v1 + with: + token: ${{ secrets.RELEASE_TOKEN }} + files: |- + tern-*.apk + tern-*.apk.sha256 diff --git a/.gitignore b/.gitignore index 1573a77..9fd487e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ .externalNativeBuild .cxx local.properties +.kotlin diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 50c6cf4..4c17001 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -4,6 +4,14 @@ plugins { id("org.jetbrains.kotlin.plugin.compose") } +// Release signing and versioning come from the environment so CI can supply +// them without a keystore or credentials ever living in the repo. All absent +// locally, which is fine: debug builds use the standard debug keystore, and +// an unsigned release build still produces an APK to inspect. +val keystorePath: String? = System.getenv("TERN_KEYSTORE_PATH") +val buildVersionName: String = System.getenv("TERN_VERSION_NAME") ?: "0.1.0" +val buildVersionCode: Int = System.getenv("TERN_VERSION_CODE")?.toInt() ?: 1 + android { namespace = "pl.mtps.tern" compileSdk = 35 @@ -14,14 +22,29 @@ android { // no need to support old platform versions for a from-scratch app. minSdk = 29 targetSdk = 35 - versionCode = 1 - versionName = "0.1.0" + versionCode = buildVersionCode + versionName = buildVersionName testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } + signingConfigs { + if (keystorePath != null) { + create("release") { + storeFile = file(keystorePath) + storePassword = System.getenv("TERN_KEYSTORE_PASSWORD") + keyAlias = System.getenv("TERN_KEY_ALIAS") + keyPassword = System.getenv("TERN_KEY_PASSWORD") + } + } + } + buildTypes { release { + // Null when no keystore is configured โ€” AGP then leaves the APK + // unsigned rather than falling back to the debug key, which would + // quietly produce an undistributable "release" build. + signingConfig = signingConfigs.findByName("release") isMinifyEnabled = true proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") }