From 4848e6bed62534f14514f17c8103ef4d17563167 Mon Sep 17 00:00:00 2001 From: Yuriy Panov Date: Sun, 25 Oct 2026 12:05:25 +0600 Subject: [PATCH] Add Gitea Actions CI and tag releases Co-Authored-By: Claude Opus 5.5 --- .gitea/workflows/ci.yml | 37 ++++++++ .gitea/workflows/release.yml | 158 +++++++++++++++++++++++++++++++++++ README.md | 25 ++++++ 3 files changed, 220 insertions(+) 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..10d3c08 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,37 @@ +# Unit tests, Android Lint and debug builds of both apps on every push to main and every PR. +name: CI + +on: + push: + branches: [main] + pull_request: + +jobs: + check: + runs-on: devserver_runner_org + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 21 + + # Accepts the SDK licenses, so AGP can fetch the build tools it wants on its own. + - uses: android-actions/setup-android@v3 + with: + packages: platform-tools platforms;android-37 + + - uses: gradle/actions/setup-gradle@v4 + + - run: ./gradlew testDebugUnitTest lint assembleDebug + + # Gitea's artifact backend speaks the v3 protocol only. + - if: failure() + uses: actions/upload-artifact@v3 + with: + name: reports + path: | + */build/reports/ + */build/test-results/ + if-no-files-found: ignore diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..4502e63 --- /dev/null +++ b/.gitea/workflows/release.yml @@ -0,0 +1,158 @@ +# Pushing a tag v-tv builds both apps signed with the release key and publishes them +# on the tag's release, creating it if it doesn't exist yet. Run by hand, it's a dry run: it +# builds and checks the signatures, then keeps the APKs as run artifacts instead of publishing. +name: Release + +on: + push: + tags: ['v*'] + workflow_dispatch: + +env: + # The start of the release key's SHA-256 certificate digest, as apksigner prints it. + RELEASE_CERT: df4c799f + +jobs: + release: + runs-on: devserver_runner_org + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + # The whole history and tags, for the changes since the last release. + fetch-depth: 0 + + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 21 + + - uses: android-actions/setup-android@v3 + with: + packages: platform-tools platforms;android-37 + + - uses: gradle/actions/setup-gradle@v4 + + - name: Read versions + id: versions + run: | + name() { sed -nE 's/^[[:space:]]*versionName = "(.*)"/\1/p' "$1/build.gradle.kts"; } + code() { sed -nE 's/^[[:space:]]*versionCode = ([0-9]+)/\1/p' "$1/build.gradle.kts"; } + { + echo "tv_name=$(name tv)" + echo "tv_code=$(code tv)" + echo "phone_name=$(name mobile)" + echo "phone_code=$(code mobile)" + echo "tag=v$(name mobile)-tv$(name tv)" + } >> "$GITHUB_OUTPUT" + + - name: Check the tag matches the versions + if: gitea.event_name == 'push' + env: + TAG: ${{ gitea.ref_name }} + EXPECTED: ${{ steps.versions.outputs.tag }} + run: | + if [ "$TAG" != "$EXPECTED" ]; then + echo "::error::Tag $TAG doesn't match the app versions, which want $EXPECTED" + exit 1 + fi + + - name: Write keystore.properties + env: + KEYSTORE_BASE64: ${{ secrets.RELEASE_KEYSTORE_BASE64 }} + STORE_PASSWORD: ${{ secrets.RELEASE_STORE_PASSWORD }} + KEY_ALIAS: ${{ secrets.RELEASE_KEY_ALIAS }} + KEY_PASSWORD: ${{ secrets.RELEASE_KEY_PASSWORD }} + run: | + # Without these the build would quietly sign with a debug key. + for secret in KEYSTORE_BASE64 STORE_PASSWORD KEY_ALIAS KEY_PASSWORD; do + if [ -z "${!secret}" ]; then + echo "::error::The RELEASE_$secret secret isn't set" + exit 1 + fi + done + umask 077 + echo "$KEYSTORE_BASE64" | base64 -d > "$RUNNER_TEMP/musyx.keystore" + # Properties files treat a backslash as an escape. + escape() { printf '%s' "${1//\\/\\\\}"; } + { + echo "storeFile=$(escape "$RUNNER_TEMP/musyx.keystore")" + echo "storePassword=$(escape "$STORE_PASSWORD")" + echo "keyAlias=$(escape "$KEY_ALIAS")" + echo "keyPassword=$(escape "$KEY_PASSWORD")" + } > keystore.properties + + - run: ./gradlew :tv:assembleRelease :mobile:assembleRelease + + - name: Check the signatures + run: | + apksigner="$(ls -d "$ANDROID_HOME"/build-tools/* | sort -V | tail -1)/apksigner" + for apk in tv/build/outputs/apk/release/tv-release.apk mobile/build/outputs/apk/release/mobile-release.apk; do + if ! "$apksigner" verify --print-certs "$apk" | grep -q "SHA-256 digest: $RELEASE_CERT"; then + echo "::error::$apk isn't signed with the release key" + exit 1 + fi + done + + - name: Keep the APKs + if: gitea.event_name == 'workflow_dispatch' + uses: actions/upload-artifact@v3 + with: + name: apks + path: | + tv/build/outputs/apk/release/tv-release.apk + mobile/build/outputs/apk/release/mobile-release.apk + + - name: Publish the release + if: gitea.event_name == 'push' + env: + TOKEN: ${{ secrets.GITEA_TOKEN }} + API: ${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }} + TAG: ${{ gitea.ref_name }} + TV_NAME: ${{ steps.versions.outputs.tv_name }} + TV_CODE: ${{ steps.versions.outputs.tv_code }} + PHONE_NAME: ${{ steps.versions.outputs.phone_name }} + PHONE_CODE: ${{ steps.versions.outputs.phone_code }} + run: | + api() { curl -sSf -H "Authorization: token $TOKEN" "$@"; } + json() { python3 -c "import json, sys; d = json.load(sys.stdin); $1"; } + + # A release made by hand for the tag keeps its notes; otherwise write them. + if release=$(api "$API/releases/tags/$TAG" 2>/dev/null); then + id=$(echo "$release" | json 'print(d["id"])') + else + previous=$(git describe --tags --abbrev=0 --match 'v*' "$TAG^" 2>/dev/null || true) + changes=$(git log --no-merges --format='- %s' "${previous:+$previous..}$TAG" | grep -v '^- Bump ' || true) + cat > "$RUNNER_TEMP/notes.md" < /dev/null + done + echo "Published $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/$TAG" + + - name: Remove the key + if: always() + run: rm -f keystore.properties "$RUNNER_TEMP/musyx.keystore" diff --git a/README.md b/README.md index 6e00ef4..1ebbe91 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,31 @@ changing the sources: - `python3 tool/make_icon.py assets/icon/musyx.png` redraws the icon itself. - The fonts are copied by hand from `assets/fonts` to `res/font` (lower-case names). +### CI and releases + +Gitea Actions runs `.gitea/workflows/ci.yml` on every push to `main` and every pull request: +the unit tests, Lint and debug builds of both apps. A failed run keeps the reports as an +artifact. + +To release, bump `versionName` and `versionCode` in `tv/build.gradle.kts` and/or +`mobile/build.gradle.kts`, commit, and push a tag named `v-tv`: + +```bash +git tag v0.1.3-tv0.1.8 && git push origin v0.1.3-tv0.1.8 +``` + +`.gitea/workflows/release.yml` then checks that the tag matches the versions, builds both +apps signed with the release key, and attaches `tv-release.apk` and `mobile-release.apk` to +the tag's release. It creates the release if there isn't one yet, with the commit subjects +since the previous tag as its notes; a release written by hand beforehand keeps its notes. +Running the workflow by hand from the Actions tab is a dry run that keeps the signed APKs as +an artifact instead of publishing. + +The key comes from four repository secrets (Settings, Actions, Secrets): +`RELEASE_KEYSTORE_BASE64` (the keystore, from `base64 -i musyx-key.keystore`), +`RELEASE_STORE_PASSWORD`, `RELEASE_KEY_ALIAS` and `RELEASE_KEY_PASSWORD`, the same values +`keystore.properties` holds locally. + ## Layout - `core/`: what the apps share (`it.panov.musyx`), under `core/src/main/java/it/panov/musyx`: