neiam
/recourse
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
Log in to mark this repository.
Android CI: container build, tests, F-Droid publish
3b701d6 · gmorell · 2026-12-03 01:33
Message
{commit_body(@commit)}
Files changed
modified
.dockerignore
+3
−0
@@ -5,3 +5,6 @@ assets/f/js/app.js
| 5 | 5 | assets/f/webfonts/ |
| 6 | 6 | .git/ |
| 7 | 7 | .idea/ |
| 8 | +# The Android app is built by Gradle, not by the Rust image (android/Dockerfile | |
| 9 | +# has its own context) — keeping it out saves copying the wrapper and caches. | |
| 10 | +android/ |
added
.forgejo/workflows/android.yml
+202
−0
@@ -0,0 +1,202 @@
| 1 | +# The Android client (android/): its unit tests on every push that touches | |
| 2 | +# it, and on master a signed release APK published to the forge's own | |
| 3 | +# F-Droid repository, the way the other neiam apps publish theirs. | |
| 4 | +# | |
| 5 | +# Everything runs in android/Dockerfile, so the runner needs docker and | |
| 6 | +# nothing else, and `docker buildx build --target android-test …` on a | |
| 7 | +# laptop reproduces the test job exactly (the commands are in the | |
| 8 | +# Dockerfile's header). | |
| 9 | +# | |
| 10 | +# Publishing needs two secrets, and skips cleanly without them rather | |
| 11 | +# than failing a build for a package that isn't set up yet: | |
| 12 | +# | |
| 13 | +# ANDROID_KEYSTORE base64 of the release keystore (.jks) | |
| 14 | +# ANDROID_KEYSTORE_PASS its password | |
| 15 | +# | |
| 16 | +# Generate one once, and keep it: the signing certificate is what | |
| 17 | +# Android checks on every update, so losing it means every install has | |
| 18 | +# to be uninstalled and redone by hand. See android/README.md. | |
| 19 | +# | |
| 20 | +# This is the APK signing key. It is NOT the F-Droid index key — that | |
| 21 | +# one is per-owner, lives in the forge's OpenBao, and never comes near | |
| 22 | +# CI. | |
| 23 | +# | |
| 24 | +# The `paths:` filters are GitHub's semantics; this forge doesn't apply | |
| 25 | +# them yet and runs the workflow on every push, which costs a test run | |
| 26 | +# and a re-publish but breaks nothing. | |
| 27 | +name: android | |
| 28 | +on: | |
| 29 | + push: | |
| 30 | + paths: | |
| 31 | + - "android/**" | |
| 32 | + - ".forgejo/workflows/android.yml" | |
| 33 | + pull_request: | |
| 34 | + paths: | |
| 35 | + - "android/**" | |
| 36 | + - ".forgejo/workflows/android.yml" | |
| 37 | + | |
| 38 | +# A newer push supersedes this run: on a branch or PR the run in | |
| 39 | +# progress is cancelled; on master it finishes, and only a run still | |
| 40 | +# waiting is replaced. | |
| 41 | +concurrency: | |
| 42 | + group: ${{ github.workflow }}-${{ github.ref }} | |
| 43 | + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} | |
| 44 | + | |
| 45 | +jobs: | |
| 46 | + test: | |
| 47 | + runs-on: self-hosted | |
| 48 | + steps: | |
| 49 | + - uses: actions/checkout@v4 | |
| 50 | + | |
| 51 | + - uses: docker/setup-buildx-action@v3 | |
| 52 | + | |
| 53 | + - name: Unit tests | |
| 54 | + run: | | |
| 55 | + docker buildx build \ | |
| 56 | + --target android-test \ | |
| 57 | + --progress=plain \ | |
| 58 | + --file android/Dockerfile android | |
| 59 | + | |
| 60 | + publish: | |
| 61 | + needs: test | |
| 62 | + # Only `github.ref`: this forge's runner context carries `event`, not | |
| 63 | + # `event_name`, so `github.event_name == 'push'` reads as empty and | |
| 64 | + # skipped this job on every push. A pull request's ref is never | |
| 65 | + # master's, so the ref alone keeps publishing to pushes to master. | |
| 66 | + if: github.ref == 'refs/heads/master' | |
| 67 | + runs-on: self-hosted | |
| 68 | + steps: | |
| 69 | + - uses: actions/checkout@v4 | |
| 70 | + | |
| 71 | + - uses: docker/setup-buildx-action@v3 | |
| 72 | + | |
| 73 | + # `vars.CI_FORGE_URL` is a forge built-in, but an older forge | |
| 74 | + # build won't inject it. Fall back to what the runner already | |
| 75 | + # knows, and say so plainly if neither resolves rather than | |
| 76 | + # handing curl an empty URL. | |
| 77 | + - name: Resolve the forge URL | |
| 78 | + env: | |
| 79 | + CI_FORGE_URL: ${{ vars.CI_FORGE_URL }} | |
| 80 | + run: | | |
| 81 | + set -euo pipefail | |
| 82 | + forge_url=${CI_FORGE_URL:-${GITHUB_SERVER_URL:-}} | |
| 83 | + | |
| 84 | + if [ -z "$forge_url" ]; then | |
| 85 | + echo "No forge URL available." >&2 | |
| 86 | + echo "Set a CI_FORGE_URL variable on this repository or its org," >&2 | |
| 87 | + echo "or upgrade the forge to a build that injects it." >&2 | |
| 88 | + exit 1 | |
| 89 | + fi | |
| 90 | + | |
| 91 | + echo "using forge URL: $forge_url" | |
| 92 | + echo "FORGE_URL=$forge_url" >> "$GITHUB_ENV" | |
| 93 | + | |
| 94 | + # A secret can't be read in a job-level `if`, so the gate is a | |
| 95 | + # step output that everything after checks. | |
| 96 | + - name: Unpack the signing keystore | |
| 97 | + id: keystore | |
| 98 | + env: | |
| 99 | + KEYSTORE: ${{ secrets.ANDROID_KEYSTORE }} | |
| 100 | + KEYSTORE_PASS: ${{ secrets.ANDROID_KEYSTORE_PASS }} | |
| 101 | + run: | | |
| 102 | + set -euo pipefail | |
| 103 | + | |
| 104 | + if [ -z "${KEYSTORE:-}" ] || [ -z "${KEYSTORE_PASS:-}" ]; then | |
| 105 | + echo "No ANDROID_KEYSTORE / ANDROID_KEYSTORE_PASS set — skipping." | |
| 106 | + echo "An unsigned or debug-signed APK is worse than none: the" | |
| 107 | + echo "debug key is shared by every developer, so publishing one" | |
| 108 | + echo "would let anyone ship an 'update' to it." | |
| 109 | + echo "skip=true" >> "$GITHUB_OUTPUT" | |
| 110 | + exit 0 | |
| 111 | + fi | |
| 112 | + | |
| 113 | + umask 077 | |
| 114 | + printf '%s' "$KEYSTORE" | base64 -d > release.jks | |
| 115 | + printf '%s' "$KEYSTORE_PASS" > keystore.pass | |
| 116 | + echo "skip=false" >> "$GITHUB_OUTPUT" | |
| 117 | + | |
| 118 | + - name: Build and sign the APK | |
| 119 | + if: steps.keystore.outputs.skip != 'true' | |
| 120 | + env: | |
| 121 | + RUN_NUMBER: ${{ github.run_number }} | |
| 122 | + run: | | |
| 123 | + set -euo pipefail | |
| 124 | + | |
| 125 | + # One stamp for the whole run, computed here rather than | |
| 126 | + # inside Gradle, so every artifact a run produces agrees on | |
| 127 | + # its version even if the build is retried a step at a time. | |
| 128 | + stamp=$(date -u +%s) | |
| 129 | + echo "version: 0.1.0-dev-$stamp (versionCode $RUN_NUMBER)" | |
| 130 | + | |
| 131 | + docker buildx build \ | |
| 132 | + --target android-export \ | |
| 133 | + --build-arg GITHUB_RUN_NUMBER="$RUN_NUMBER" \ | |
| 134 | + --build-arg SOURCE_DATE_EPOCH="$stamp" \ | |
| 135 | + --secret id=keystore,src=./release.jks \ | |
| 136 | + --secret id=keystore_password,src=./keystore.pass \ | |
| 137 | + --output type=local,dest=./apk \ | |
| 138 | + --progress=plain \ | |
| 139 | + --file android/Dockerfile android | |
| 140 | + | |
| 141 | + # The keystore is gone before anything else runs, so a later step | |
| 142 | + # or a failure mid-job can't leave it on a persistent runner. | |
| 143 | + - name: Shred the keystore | |
| 144 | + if: always() | |
| 145 | + run: shred -u release.jks keystore.pass 2>/dev/null || rm -f release.jks keystore.pass | |
| 146 | + | |
| 147 | + # `${{ github.token }}` is minted for this job and authorized to | |
| 148 | + # publish to THIS repository's packages and nowhere else, so there | |
| 149 | + # is no secret to create first. | |
| 150 | + - name: Publish to the F-Droid repository | |
| 151 | + if: steps.keystore.outputs.skip != 'true' | |
| 152 | + env: | |
| 153 | + REPOSITORY: ${{ github.repository }} | |
| 154 | + TOKEN: ${{ github.token }} | |
| 155 | + run: | | |
| 156 | + set -euo pipefail | |
| 157 | + | |
| 158 | + # What F-Droid shows under the name and on the app's page. | |
| 159 | + # android/DESCRIPTION.md: the summary on its first line, then | |
| 160 | + # a blank line, then the description. The description header | |
| 161 | + # is percent-encoded because a header can't carry newlines — | |
| 162 | + # done in bash so the runner needs nothing it doesn't have. | |
| 163 | + urlencode() { | |
| 164 | + local LC_ALL=C s="$1" out="" c i | |
| 165 | + for ((i = 0; i < ${#s}; i++)); do | |
| 166 | + c=${s:i:1} | |
| 167 | + case $c in | |
| 168 | + [a-zA-Z0-9.~_-]) out+=$c ;; | |
| 169 | + *) printf -v c '%%%02X' "'$c"; out+=$c ;; | |
| 170 | + esac | |
| 171 | + done | |
| 172 | + printf '%s' "$out" | |
| 173 | + } | |
| 174 | + summary=$(head -n 1 android/DESCRIPTION.md) | |
| 175 | + description=$(tail -n +3 android/DESCRIPTION.md) | |
| 176 | + | |
| 177 | + curl --fail-with-body -sS \ | |
| 178 | + -u "ci:$TOKEN" \ | |
| 179 | + -H "Content-Type: application/vnd.android.package-archive" \ | |
| 180 | + -H "X-Package-Summary: $summary" \ | |
| 181 | + -H "X-Package-Description: $(urlencode "$description")" \ | |
| 182 | + --data-binary "@apk/app-release.apk" \ | |
| 183 | + "$FORGE_URL/pkg/fdroid/$REPOSITORY/upload" | |
| 184 | + echo | |
| 185 | + | |
| 186 | + - name: How to install it | |
| 187 | + if: steps.keystore.outputs.skip != 'true' | |
| 188 | + env: | |
| 189 | + OWNER: ${{ github.repository_owner }} | |
| 190 | + run: | | |
| 191 | + set -euo pipefail | |
| 192 | + fingerprint=$(curl -fsSL "$FORGE_URL/pkg/_keys/fdroid/$OWNER") | |
| 193 | + | |
| 194 | + cat <<EOF | |
| 195 | + Add this repository in F-Droid (Settings -> Repositories -> +): | |
| 196 | + | |
| 197 | + $FORGE_URL/pkg/fdroid/$OWNER/_all?fingerprint=$fingerprint | |
| 198 | + | |
| 199 | + One entry covers every Android app $OWNER publishes. The | |
| 200 | + fingerprint pins the index signing certificate; F-Droid | |
| 201 | + refuses an index signed by anything else. | |
| 202 | + EOF |
added
android/DESCRIPTION.md
+5
−0
@@ -0,0 +1,5 @@
| 1 | +Your recourse forum on your phone: read, reply, react and keep up. | |
| 2 | + | |
| 3 | +The phone app for a recourse forum. Browse categories as a list or as tiles you swipe through, read topics, reply and start new ones, react, bookmark posts, watch categories, follow tags, search, and see your notifications. Layout, sort and the rest of your profile are shared with the web. | |
| 4 | + | |
| 5 | +Pair it by scanning the code from Devices on the web. |
added
android/Dockerfile
+158
−0
@@ -0,0 +1,158 @@
| 1 | +# Tests, builds and signs the Android app. Copied from ../../party-slut/android | |
| 2 | +# (the family Dockerfile, ../../pin_flip/android, with its test stage). | |
| 3 | +# | |
| 4 | +# In a container rather than on the runner, so the runner needs docker | |
| 5 | +# and nothing else, and a developer can reproduce exactly what CI did | |
| 6 | +# without installing an SDK. | |
| 7 | +# | |
| 8 | +# The JVM unit tests (the pairing link, and the contract tests that decode | |
| 9 | +# real API responses): | |
| 10 | +# | |
| 11 | +# docker buildx build --target android-test --progress=plain \ | |
| 12 | +# --file android/Dockerfile android | |
| 13 | +# | |
| 14 | +# The signed release APK: | |
| 15 | +# | |
| 16 | +# docker buildx build \ | |
| 17 | +# --target android-export \ | |
| 18 | +# --secret id=keystore,src=./release.jks \ | |
| 19 | +# --secret id=keystore_password,src=./keystore.pass \ | |
| 20 | +# --output type=local,dest=./apk \ | |
| 21 | +# --progress=plain \ | |
| 22 | +# --file android/Dockerfile android | |
| 23 | +# | |
| 24 | +# Run from the repository root. The build context is `android`, not the | |
| 25 | +# repository: the app needs nothing from outside it, and the root | |
| 26 | +# .dockerignore in several of these repos excludes `android/` so the | |
| 27 | +# service image doesn't drag the Gradle wrapper and SDK caches along. | |
| 28 | +# With a repo-root context BuildKit is handed a tree with the app | |
| 29 | +# filtered out of it, and the COPY below fails as a bare glob error | |
| 30 | +# with no step log to explain itself. | |
| 31 | + | |
| 32 | +ARG JDK_IMAGE=eclipse-temurin:17-jdk | |
| 33 | + | |
| 34 | +FROM ${JDK_IMAGE} AS sdk | |
| 35 | + | |
| 36 | +# Pinned. `…_latest.zip` is a moving target under a cache that has no | |
| 37 | +# way to notice it moved. | |
| 38 | +ARG CMDLINE_TOOLS=commandlinetools-linux-11076708_latest.zip | |
| 39 | +ARG ANDROID_PLATFORM=34 | |
| 40 | +ARG BUILD_TOOLS=34.0.0 | |
| 41 | + | |
| 42 | +ENV ANDROID_HOME=/opt/android-sdk \ | |
| 43 | + DEBIAN_FRONTEND=noninteractive | |
| 44 | + | |
| 45 | +RUN apt-get update \ | |
| 46 | + && apt-get install -y --no-install-recommends unzip curl ca-certificates \ | |
| 47 | + && rm -rf /var/lib/apt/lists/* | |
| 48 | + | |
| 49 | +RUN mkdir -p "${ANDROID_HOME}/cmdline-tools" \ | |
| 50 | + && curl -fsSL "https://dl.google.com/android/repository/${CMDLINE_TOOLS}" -o /tmp/tools.zip \ | |
| 51 | + && unzip -q /tmp/tools.zip -d "${ANDROID_HOME}/cmdline-tools" \ | |
| 52 | + && mv "${ANDROID_HOME}/cmdline-tools/cmdline-tools" "${ANDROID_HOME}/cmdline-tools/latest" \ | |
| 53 | + && rm /tmp/tools.zip | |
| 54 | + | |
| 55 | +ENV PATH="${ANDROID_HOME}/cmdline-tools/latest/bin:${ANDROID_HOME}/platform-tools:${PATH}" | |
| 56 | + | |
| 57 | +# `yes |` because sdkmanager prompts per licence and there is no | |
| 58 | +# non-interactive flag that covers all of them. | |
| 59 | +RUN yes | sdkmanager --licenses > /dev/null \ | |
| 60 | + && sdkmanager --install \ | |
| 61 | + "platforms;android-${ANDROID_PLATFORM}" \ | |
| 62 | + "build-tools;${BUILD_TOOLS}" \ | |
| 63 | + "platform-tools" > /dev/null | |
| 64 | + | |
| 65 | +# ── dependencies ───────────────────────────────────────────────────── | |
| 66 | +# | |
| 67 | +# Build files only, so the ~200 MB of Gradle and Maven downloads cache | |
| 68 | +# as one layer that survives every change to the Kotlin sources. | |
| 69 | + | |
| 70 | +FROM sdk AS deps | |
| 71 | + | |
| 72 | +WORKDIR /src | |
| 73 | +COPY gradle ./gradle | |
| 74 | +COPY gradlew settings.gradle.kts build.gradle.kts gradle.properties ./ | |
| 75 | +COPY app/build.gradle.kts ./app/ | |
| 76 | + | |
| 77 | +RUN echo "sdk.dir=${ANDROID_HOME}" > local.properties | |
| 78 | + | |
| 79 | +# A task that resolves the whole dependency graph without needing the | |
| 80 | +# sources. `--no-daemon` because a daemon outliving the RUN is just a | |
| 81 | +# process the image has to reap. | |
| 82 | +RUN ./gradlew --no-daemon :app:dependencies --configuration releaseRuntimeClasspath > /dev/null \ | |
| 83 | + || echo "dependency warm-up failed; the build below will fetch them" | |
| 84 | + | |
| 85 | +# ── test ───────────────────────────────────────────────────────────── | |
| 86 | +# | |
| 87 | +# Its own stage off `deps`, so testing never waits on (or touches) the | |
| 88 | +# release build, and the release build never needs the keystore to have | |
| 89 | +# been tested first. Nothing is exported; a failing test fails the build. | |
| 90 | + | |
| 91 | +FROM deps AS android-test | |
| 92 | + | |
| 93 | +COPY app ./app | |
| 94 | + | |
| 95 | +RUN ./gradlew --no-daemon :app:testDebugUnitTest | |
| 96 | + | |
| 97 | +# ── build ──────────────────────────────────────────────────────────── | |
| 98 | + | |
| 99 | +FROM deps AS build | |
| 100 | + | |
| 101 | +ARG BUILD_TOOLS=34.0.0 | |
| 102 | + | |
| 103 | +# A container build inherits nothing from the runner's environment, so | |
| 104 | +# the version has to be handed in explicitly. Without these, Gradle's | |
| 105 | +# getenv lookups come back empty inside here and every run builds | |
| 106 | +# versionCode 1 — the same filename with different bytes, which the | |
| 107 | +# registry refuses with a 409. | |
| 108 | +# | |
| 109 | +# Declared in this stage rather than at the top so they don't invalidate | |
| 110 | +# the SDK and dependency layers, which is most of the build time. | |
| 111 | +ARG GITHUB_RUN_NUMBER | |
| 112 | +ARG SOURCE_DATE_EPOCH | |
| 113 | +ARG RELEASE_VERSION | |
| 114 | +ENV GITHUB_RUN_NUMBER=${GITHUB_RUN_NUMBER} \ | |
| 115 | + SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} \ | |
| 116 | + RELEASE_VERSION=${RELEASE_VERSION} | |
| 117 | + | |
| 118 | +COPY app ./app | |
| 119 | + | |
| 120 | +RUN echo "building versionCode=${GITHUB_RUN_NUMBER:-1}" \ | |
| 121 | + && ./gradlew --no-daemon :app:assembleRelease | |
| 122 | + | |
| 123 | +# Sign as a separate step from Gradle so the keystore never reaches a | |
| 124 | +# build script, a Gradle cache, or an image layer. BuildKit secrets are | |
| 125 | +# mounted for the life of one RUN and are not committed. | |
| 126 | +# | |
| 127 | +# zipalign before apksigner, not after: aligning rewrites offsets, and | |
| 128 | +# doing it to an already-signed APK invalidates the v2 signature that | |
| 129 | +# covers them. | |
| 130 | +# | |
| 131 | +# No --key-pass. apksigner reads each `file:` password as a *sequential* | |
| 132 | +# read from that file, so passing the same one-line file to both | |
| 133 | +# --ks-pass and --key-pass makes the second read hit EOF: | |
| 134 | +# | |
| 135 | +# Failed to read Key "…" password: end of file reached | |
| 136 | +# | |
| 137 | +# Omitted, the key password defaults to the store password, which is | |
| 138 | +# what PKCS12 keystores use anyway. | |
| 139 | +RUN --mount=type=secret,id=keystore,target=/tmp/release.jks \ | |
| 140 | + --mount=type=secret,id=keystore_password,target=/tmp/keystore.pass \ | |
| 141 | + set -eu; \ | |
| 142 | + tools="${ANDROID_HOME}/build-tools/${BUILD_TOOLS}"; \ | |
| 143 | + unsigned=app/build/outputs/apk/release/app-release-unsigned.apk; \ | |
| 144 | + mkdir -p /out; \ | |
| 145 | + "${tools}/zipalign" -p -f 4 "$unsigned" /tmp/aligned.apk; \ | |
| 146 | + "${tools}/apksigner" sign \ | |
| 147 | + --ks /tmp/release.jks \ | |
| 148 | + --ks-pass "file:/tmp/keystore.pass" \ | |
| 149 | + --out /out/app-release.apk \ | |
| 150 | + /tmp/aligned.apk; \ | |
| 151 | + "${tools}/apksigner" verify --print-certs /out/app-release.apk | |
| 152 | + | |
| 153 | +# ── export ─────────────────────────────────────────────────────────── | |
| 154 | +# | |
| 155 | +# FROM scratch, so `--output type=local` lands the APK and nothing else. | |
| 156 | + | |
| 157 | +FROM scratch AS android-export | |
| 158 | +COPY --from=build /out/app-release.apk / |
Parents: 4d8ef0a