Add CI that builds and unit-tests every pushed commit

This commit is contained in:
2026-10-25 12:00:26 +02:00
parent 7a2c7eccb3
commit 87d9afd55b
2 changed files with 95 additions and 0 deletions
+52
View File
@@ -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
+43
View File
@@ -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 <sha before the push> <head sha>
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