Files
tern-android/.gitea/workflows/release.yml
T
Mateusz PstruchaandClaude Opus 5 c83d1d5823
CI / build (push) Successful in 1m18s
Release / apk (push) Successful in 1m42s
Resolve the keystore path in-step rather than via runner.temp
If that context is unset on this runner the keystore would be written
somewhere unintended; resolve it with a fallback and export the result
so the build and cleanup steps agree on one path.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 22:13:41 +02:00

110 lines
4.3 KiB
YAML

name: Release
on:
push:
tags: ['v*']
jobs:
apk:
runs-on: rocky-10
steps:
- name: Check out source
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17'
# See ci.yml — installed explicitly so SDK package versions stay
# pinned to match the build config.
- name: Set up Android SDK
run: |
set -eu
SDK="$HOME/android-sdk"
if [ ! -d "$SDK/cmdline-tools/latest" ]; then
mkdir -p "$SDK/cmdline-tools"
curl -sSLo /tmp/cmdline-tools.zip \
https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip
unzip -q /tmp/cmdline-tools.zip -d "$SDK/cmdline-tools"
mv "$SDK/cmdline-tools/cmdline-tools" "$SDK/cmdline-tools/latest"
rm -f /tmp/cmdline-tools.zip
fi
yes | "$SDK/cmdline-tools/latest/bin/sdkmanager" --licenses >/dev/null 2>&1 || true
"$SDK/cmdline-tools/latest/bin/sdkmanager" \
"platform-tools" "platforms;android-35" "build-tools;35.0.0" >/dev/null
echo "ANDROID_HOME=$SDK" >> "$GITHUB_ENV"
echo "ANDROID_SDK_ROOT=$SDK" >> "$GITHUB_ENV"
- name: Cache Gradle
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: gradle-${{ hashFiles('**/*.gradle.kts', 'gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: gradle-
- 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
# Resolve the path here rather than via ${{ runner.temp }}: if that
# context is empty on this runner, the keystore would be written to
# an unintended location. Export it so later steps use the same one.
KS="${RUNNER_TEMP:-${GITHUB_WORKSPACE:-$PWD}}/tern-release.jks"
echo "$KEYSTORE_B64" | base64 -d > "$KS"
chmod 600 "$KS"
echo "TERN_KEYSTORE_PATH=$KS" >> "$GITHUB_ENV"
- name: Build signed APK
env:
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 "${TERN_KEYSTORE_PATH:-}"
- name: Create release
uses: akkuman/gitea-release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
server_url: ${{ gitea.server_url }}
tag_name: ${{ gitea.ref_name }}
name: ${{ gitea.ref_name }}
files: |-
tern-*.apk
tern-*.apk.sha256