From 87d9afd55b675f66a4033d144c49b282d140c710 Mon Sep 17 00:00:00 2001 From: kalarina Date: Sun, 25 Oct 2026 12:00:26 +0200 Subject: [PATCH] Add CI that builds and unit-tests every pushed commit --- .github/workflows/ci.yml | 52 ++++++++++++++++++++++++++++++++++++++++ scripts/ci-check.sh | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100755 scripts/ci-check.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..1eb112c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,52 @@ +name: CI + +on: + push: + pull_request: + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ci-${{ github.ref }} + +jobs: + build: + # The Gitea instance has no Android SDK on its runners; this only runs on the GitHub mirror + if: github.server_url == 'https://github.com' + runs-on: ubuntu-latest + timeout-minutes: 90 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 21 + + - uses: gradle/actions/setup-gradle@v4 + + - name: Build and unit-test every pushed commit + run: bash scripts/ci-check.sh "${{ github.event.before }}" "${{ github.sha }}" + + - name: Release build (R8) + run: ./gradlew :app:assembleRelease --stacktrace + + - name: APK size and key dependencies + run: | + apk=$(ls app/build/outputs/apk/release/*.apk | head -n 1) + echo "::notice title=Release APK::$(stat -c %s "$apk") bytes ($(basename "$apk"))" + deps=$(./gradlew -q :app:dependencies --configuration releaseRuntimeClasspath \ + | grep -oE '(androidx\.lifecycle:lifecycle-runtime-compose|androidx\.profileinstaller:profileinstaller|com\.squareup\.okhttp3:okhttp):[^ ]+( -> [^ ]+)?' \ + | sort -u | paste -sd ';' -) + echo "::notice title=Dependencies::$deps" + + - uses: actions/upload-artifact@v4 + if: always() + with: + name: apk + path: app/build/outputs/apk/**/*.apk + if-no-files-found: ignore diff --git a/scripts/ci-check.sh b/scripts/ci-check.sh new file mode 100755 index 0000000..37b2e07 --- /dev/null +++ b/scripts/ci-check.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +# Builds and unit-tests every commit of a push, so each step of the history stays green. +# Usage: scripts/ci-check.sh +set -uo pipefail + +before="${1:-}" +head="$(git rev-parse "${2:-HEAD}")" +tasks=(:app:assembleDebug :app:testDebugUnitTest) + +commits=() +if [[ -n "$before" && ! "$before" =~ ^0+$ ]] \ + && git cat-file -e "$before^{commit}" 2>/dev/null \ + && git merge-base --is-ancestor "$before" "$head"; then + mapfile -t commits < <(git rev-list --reverse --max-count=30 "$before..$head") +fi +[[ ${#commits[@]} -eq 0 ]] && commits=("$head") + +# Turns the interesting part of a Gradle log into one annotation readable from the run page +report() { + local title="$1" log="$2" msg + msg="$(grep -E -A4 "^e: |FAILED|What went wrong|Exception|error:|AssertionError" "$log" | head -n 120)" + [[ -z "$msg" ]] && msg="$(tail -n 60 "$log")" + msg="${msg//'%'/'%25'}" + msg="${msg//$'\r'/}" + msg="${msg//$'\n'/'%0A'}" + echo "::error title=$title::$msg" +} + +status=0 +for c in "${commits[@]}"; do + subject="$(git log -1 --format='%h %s' "$c")" + echo "::group::$subject" + git checkout -q "$c" + if ! ./gradlew "${tasks[@]}" 2>&1 | tee build.log; then + report "Failed at ${c:0:7}" build.log + status=1 + fi + echo "::endgroup::" + [[ $status -ne 0 ]] && break +done + +git checkout -q "$head" +exit $status