Files
BikeControl/scripts/ci-android-version-code.sh
dtourolleandClaude Opus 5 db974dcac1
🚴 Build and Test BikeControl / Workspace tests (push) Successful in 13m33s
🚴 Build and Test BikeControl / Android compile check (push) Successful in 3m29s
Pin the versionCode in the config, not in a file the build overwrites
The Android job died on `tauri.properties not found`. It is not found
because `cargo tauri android init` does not write it: in a clean clone
init leaves gen/android/app/ holding build.gradle.kts, proguard-rules.pro
and src/, nothing else. The generated app/.gitignore names the pattern —
tauri.properties sits with tauri.build.gradle.kts and proguard-tauri.pro,
the tauri.* files that `android build` stamps out on every run.

So the step was wrong twice and the crash was the lucky half. Had the
file existed, the build would have rewritten it from tauri.conf.json and
discarded the sed — a green build shipping the default versionCode, which
is the failure that reaches a rider's phone rather than the log.

Tauri exposes the actual input, so use it:

- tauri.conf.json gains bundle.android.versionCode, committed rather than
  conjured by CI, so the key is greppable and the sed has a fixed target.
- ci-android-version-code.sh edits the config. Formula and the 1000 floor
  are unchanged; the header comment is rewritten, since its premise (init
  writes the file, the default collides) does not hold — Tauri's default
  is major*1000000 + minor*1000 + patch, monotonic, and it puts 0.1.0 at
  exactly 1000, which is where the floor comes from. Missing key or failed
  substitution now exits 1 instead of degrading to a silent no-op.
- The step moves ahead of `android init`, next to ci-set-version.sh, since
  both edit the same config.

Verified against a clean clone: 0.1.0 -> 1100, v0.2.3 -> 1203,
v1.0.0 -> 11000, config still parses at each step. Then a real
`cargo tauri android build`, which wrote versionCode=1100 into
tauri.properties — the value reaches the APK.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-21 17:39:06 +02:00

62 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env sh
# Pin an explicit, monotonic Android versionCode.
#
# Tauri derives one from the semver as
#
# major * 1000000 + minor * 1000 + patch
#
# which is monotonic but leaves the pre-1.0 series crowded down at the bottom of
# the range: 0.1.0 is versionCode 1000. Android refuses to install an APK whose
# versionCode is not greater than the installed one, and a rider who cannot
# update is a rider who stops updating, so this pins the number rather than
# leaving it to a default that a Tauri upgrade could change under us:
#
# code = 1000 + major * 10000 + minor * 100 + patch
#
# so 0.1.0 -> 1100, 0.1.3 -> 1103, 0.2.0 -> 1200, 1.0.0 -> 11000. Monotonic in
# semver order for any minor/patch below 100, which is well past where this
# project will ever get.
#
# The 1000 floor is not decoration: Tauri's default gives 0.1.0 versionCode
# 1000, so anyone carrying an APK from before this script already has that
# number installed. A bare major/minor/patch code would be 100 — a *downgrade*,
# which Android refuses outright.
#
# This writes bundle.android.versionCode in tauri.conf.json, NOT
# gen/android/app/tauri.properties. tauri.properties is generated by
# `cargo tauri android build`, not by `android init` — it does not exist at init
# time, and the build overwrites it from the config on every run, so an edit
# there is either a crash or a no-op. The config is the only durable input.
#
# POSIX sh: the runner's /bin/sh is dash. No here-strings, no \s in sed.
set -e
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
CONF="$ROOT/src-tauri/tauri.conf.json"
VERSION=$(grep '"version"' "$CONF" | head -1 | sed -E 's/.*"version"[[:space:]]*:[[:space:]]*"([^"]+)".*/\1/')
MAJ=$(echo "$VERSION" | cut -d. -f1)
MIN=$(echo "$VERSION" | cut -d. -f2)
PAT=$(echo "$VERSION" | cut -d. -f3)
# Guard a malformed or short version so we can never emit code 0, which Android
# treats as "older than everything".
: "${MAJ:=0}" "${MIN:=0}" "${PAT:=0}"
CODE=$(( 1000 + MAJ * 10000 + MIN * 100 + PAT ))
echo "version=$VERSION -> versionCode=$CODE"
# The key is committed to tauri.conf.json, so a missing one means the config was
# restructured and this sed would otherwise silently do nothing — shipping an
# APK with a stale versionCode that no device would accept as an update.
grep -q '"versionCode"' "$CONF" || {
echo "❌ no \"versionCode\" key in $CONF — add bundle.android.versionCode back" >&2
exit 1
}
sed -i "s/\"versionCode\"[[:space:]]*:[[:space:]]*[0-9]*/\"versionCode\": $CODE/" "$CONF"
grep -q "\"versionCode\": $CODE" "$CONF" || {
echo "❌ failed to set versionCode to $CODE in $CONF" >&2
exit 1
}
grep -A2 '"android"' "$CONF"