With the NDKs baked in the CI image was 14 G in grg-runner's 48 G RAM-backed image store: it filled the store (run 54264, Gradle "No space left on device") and the runner cleanup evicts such images under pressure, so it would have been rebuilt most runs. The image is now Flutter + node + cache paths only (seconds to build); the SDK packages Gradle installs (NDKs, CMake, build-tools, platform) are their own actions/cache entry, stored on the runner's disk, keyed by the Gradle build files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
284 lines
11 KiB
YAML
284 lines
11 KiB
YAML
---
|
|
# Merge upstream zjs81/meshcore-open dev into tth every night, run the tests,
|
|
# build a signed arm64 APK without the on-device ML (see stubs/README.md),
|
|
# push the merge and publish a release that Obtainium picks up.
|
|
#
|
|
# A release is made only when HEAD has none yet (its body carries
|
|
# "commit: <sha>"); workflow_dispatch always builds.
|
|
#
|
|
# Signing: secrets ANDROID_KEYSTORE_B64 + ANDROID_KEYSTORE_PASSWORD, set by
|
|
# .gitea/setup-signing.sh. Without them the job fails rather than publish a
|
|
# debug-signed APK - Android refuses an update signed by a different key.
|
|
#
|
|
# On failure: issue "upstream-sync failed"; closed by the next good run.
|
|
name: build
|
|
|
|
"on":
|
|
schedule:
|
|
- cron: "50 4 * * *"
|
|
push:
|
|
branches: [tth]
|
|
workflow_dispatch:
|
|
inputs:
|
|
skip_trivy:
|
|
description: "skip the Trivy gate (EMERGENCY, logged)"
|
|
type: boolean
|
|
default: false
|
|
|
|
concurrency:
|
|
group: build
|
|
cancel-in-progress: false
|
|
|
|
env:
|
|
BRANCH: tth
|
|
UPSTREAM_URL: https://github.com/zjs81/meshcore-open.git
|
|
UPSTREAM_REFS: dev
|
|
GITEA: https://git.rfa.cz
|
|
KEEP_RELEASES: 5
|
|
|
|
defaults:
|
|
run:
|
|
shell: bash
|
|
|
|
jobs:
|
|
# CI image (.gitea/ci/Dockerfile: Flutter + node for actions/cache, cache
|
|
# paths) tagged by a hash of its Dockerfile. Built straight into the Docker of the `big` runner
|
|
# (grg-runner, the only one with that label) and never pushed: the job
|
|
# container below then starts from the local image. If the image is gone
|
|
# (prune), this job just builds it again.
|
|
ci-image:
|
|
runs-on: big
|
|
outputs:
|
|
image: ${{ steps.img.outputs.image }}
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
- name: Build the CI image if its Dockerfile changed
|
|
id: img
|
|
run: |
|
|
set -euo pipefail
|
|
hash=$(sha256sum .gitea/ci/Dockerfile | cut -c1-12)
|
|
tag="meshcore-open-ci:$hash"
|
|
if docker image inspect "$tag" >/dev/null 2>&1; then
|
|
echo "$tag already built"
|
|
else
|
|
docker build -t "$tag" .gitea/ci
|
|
docker images meshcore-open-ci --format '{{.Tag}}' | grep -vx "$hash" |
|
|
xargs -r -I{} docker rmi "meshcore-open-ci:{}" || true
|
|
fi
|
|
echo "image=$tag" >>"$GITHUB_OUTPUT"
|
|
|
|
build:
|
|
needs: ci-image
|
|
runs-on: big
|
|
permissions:
|
|
contents: write
|
|
issues: write
|
|
container:
|
|
image: ${{ needs.ci-image.outputs.image }}
|
|
steps:
|
|
# Plain git instead of actions/checkout: it also leaves the push
|
|
# credentials for the merge commit in place.
|
|
- name: Checkout
|
|
env:
|
|
TOKEN: ${{ secrets.GITEA_TOKEN || github.token }}
|
|
run: |
|
|
set -euo pipefail
|
|
git config --global --add safe.directory '*'
|
|
git init -q .
|
|
git remote add origin "$GITEA/$GITHUB_REPOSITORY.git"
|
|
# Also authenticates the push at the end; the container is thrown away.
|
|
git config "http.$GITEA/.extraheader" "Authorization: token $TOKEN"
|
|
git fetch -q origin "+refs/heads/$BRANCH:refs/remotes/origin/$BRANCH"
|
|
git checkout -q -B "$BRANCH" "origin/$BRANCH"
|
|
|
|
- name: Merge upstream
|
|
id: merge
|
|
run: bash .gitea/upstream-sync.sh merge
|
|
|
|
# Secrets in the commits of this push (gitleaks, first-parent only,
|
|
# redacted output) and misconfigurations in Dockerfiles/compose
|
|
# (trivy config, report only).
|
|
- name: gitleaks
|
|
uses: https://git.rfa.cz/tth-pub/ci-actions/gitleaks@v3
|
|
with:
|
|
mode: block
|
|
|
|
- name: Trivy config
|
|
uses: https://git.rfa.cz/tth-pub/ci-actions/trivy-gate@v3
|
|
with:
|
|
scan-type: fs
|
|
scanners: misconfig
|
|
mode: warn
|
|
|
|
- name: Release needed?
|
|
id: rel
|
|
env:
|
|
TOKEN: ${{ secrets.GITEA_TOKEN || github.token }}
|
|
SHA: ${{ steps.merge.outputs.sha }}
|
|
run: |
|
|
set -euo pipefail
|
|
last=$(curl -sSf --config - "$GITEA/api/v1/repos/$GITHUB_REPOSITORY/releases?limit=1" \
|
|
<<<"header = \"Authorization: token $TOKEN\"" |
|
|
jq -r '.[0].body // ""' | sed -n 's/^commit: *//p' | head -n1)
|
|
echo "HEAD $SHA, last release commit ${last:-none}"
|
|
if [ "$last" = "$SHA" ] && [ "$GITHUB_EVENT_NAME" != workflow_dispatch ]; then
|
|
echo "needed=false" >>"$GITHUB_OUTPUT"
|
|
else
|
|
echo "needed=true" >>"$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
# Android SDK packages Gradle installs on demand (two NDKs, CMake,
|
|
# build-tools, platform: ~4 min of downloads per build). Own cache entry:
|
|
# ~5 G that changes only with the NDK pin, not with every pubspec.lock.
|
|
# A new package (upstream moved on) is installed by Gradle and saved
|
|
# under the new key; the build step warns about it.
|
|
- name: Android SDK packages cache
|
|
if: steps.rel.outputs.needed == 'true'
|
|
uses: actions/cache@v6
|
|
with:
|
|
path: |
|
|
/opt/android-sdk-linux/ndk
|
|
/opt/android-sdk-linux/cmake
|
|
/opt/android-sdk-linux/build-tools
|
|
/opt/android-sdk-linux/platforms
|
|
key: android-sdk-${{ hashFiles('android/app/build.gradle.kts', 'android/build.gradle.kts', 'android/settings.gradle.kts') }}
|
|
restore-keys: android-sdk-
|
|
|
|
# Gradle (deps, wrapper, build cache) and pub caches; the paths are set
|
|
# in .gitea/ci/Dockerfile. Without it Gradle spent ~17 min per build.
|
|
- name: Gradle and pub cache
|
|
if: steps.rel.outputs.needed == 'true'
|
|
uses: actions/cache@v6
|
|
with:
|
|
path: |
|
|
/ci-cache/gradle/caches
|
|
/ci-cache/gradle/wrapper
|
|
/ci-cache/pub
|
|
key: gradle-pub-${{ hashFiles('pubspec.lock', 'android/**/*.gradle.kts', 'android/gradle/wrapper/gradle-wrapper.properties') }}
|
|
restore-keys: gradle-pub-
|
|
|
|
- name: Tests
|
|
if: steps.rel.outputs.needed == 'true'
|
|
run: |
|
|
set -euo pipefail
|
|
flutter pub get
|
|
flutter test --no-pub -r failures-only
|
|
|
|
# Trivy gate (tth-pub/ci-actions): a fixable HIGH/CRITICAL in the
|
|
# dependencies (pubspec.lock from the pub get above, Podfile/SwiftPM
|
|
# locks) or a secret in the tree = no APK, no release. Accepted risks
|
|
# with a reason and expiry in .trivyignore.yaml. No Docker in this
|
|
# container, so the action runs its checksum-verified Trivy binary.
|
|
# mode: block since 2026-10-25 (phase 2).
|
|
- name: Trivy gate
|
|
id: trivy
|
|
if: steps.rel.outputs.needed == 'true'
|
|
uses: https://git.rfa.cz/tth-pub/ci-actions/trivy-gate@v3
|
|
with:
|
|
scan-type: fs
|
|
mode: block
|
|
skip: ${{ inputs.skip_trivy && 'true' || 'false' }}
|
|
|
|
- name: Build signed APK
|
|
if: steps.rel.outputs.needed == 'true'
|
|
id: apk
|
|
env:
|
|
KEYSTORE_B64: ${{ secrets.ANDROID_KEYSTORE_B64 }}
|
|
KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
|
|
run: |
|
|
set -euo pipefail
|
|
[ -n "$KEYSTORE_B64" ] && [ -n "$KEYSTORE_PASSWORD" ] || {
|
|
echo "::error::signing secrets missing, run .gitea/setup-signing.sh"
|
|
exit 1
|
|
}
|
|
ks="$RUNNER_TEMP/release.jks"
|
|
base64 -d <<<"$KEYSTORE_B64" >"$ks"
|
|
# PKCS12: key password = store password.
|
|
umask 077
|
|
printf 'storeFile=%s\nstorePassword=%s\nkeyAlias=meshcore-open\nkeyPassword=%s\n' \
|
|
"$ks" "$KEYSTORE_PASSWORD" "$KEYSTORE_PASSWORD" >android/key.properties
|
|
base=$(sed -n 's/^version: *\([^+ ]*\).*/\1/p' pubspec.yaml)
|
|
name="$base-tth.$(date -u +%Y%m%d%H%M)"
|
|
# Minutes since 2026-01-01: monotonic, and far above upstream's codes.
|
|
code=$((($(date -u +%s) - 1767225600) / 60))
|
|
flutter build apk --release --no-pub --target-platform android-arm64 \
|
|
--build-name "$name" --build-number "$code" 2>&1 | tee "$RUNNER_TEMP/build.log"
|
|
# With a warm SDK cache Gradle installs nothing; an install means the
|
|
# cache was cold or upstream moved on (new NDK, ...) - the next run
|
|
# restores it from the cache saved by this one.
|
|
if grep '^Installing ' "$RUNNER_TEMP/build.log"; then
|
|
echo "::warning::Gradle installed Android SDK packages (cold cache or a new pin, see above)"
|
|
fi
|
|
rm -f android/key.properties "$ks"
|
|
apk="$RUNNER_TEMP/meshcore-open-$name-arm64.apk"
|
|
cp build/app/outputs/flutter-apk/app-release.apk "$apk"
|
|
signer=$(ls -d "$ANDROID_HOME"/build-tools/* | sort -V | tail -n1)/apksigner
|
|
certs=$("$signer" verify --print-certs "$apk")
|
|
if grep -q 'CN=Android Debug' <<<"$certs"; then
|
|
echo "::error::APK is debug-signed"
|
|
exit 1
|
|
fi
|
|
grep 'certificate SHA-256' <<<"$certs"
|
|
ls -lh "$apk"
|
|
echo "name=$name" >>"$GITHUB_OUTPUT"
|
|
echo "apk=$apk" >>"$GITHUB_OUTPUT"
|
|
|
|
- name: Push
|
|
if: steps.merge.outputs.changed == 'true'
|
|
run: git push origin "HEAD:$BRANCH"
|
|
|
|
- name: Release
|
|
if: steps.rel.outputs.needed == 'true'
|
|
env:
|
|
TOKEN: ${{ secrets.GITEA_TOKEN || github.token }}
|
|
SHA: ${{ steps.merge.outputs.sha }}
|
|
NAME: ${{ steps.apk.outputs.name }}
|
|
APK: ${{ steps.apk.outputs.apk }}
|
|
run: |
|
|
set -euo pipefail
|
|
api="$GITEA/api/v1/repos/$GITHUB_REPOSITORY"
|
|
auth="header = \"Authorization: token $TOKEN\""
|
|
upstream=$(git log -1 --format='%h %s' "upstream/${UPSTREAM_REFS%% *}" 2>/dev/null || true)
|
|
body=$(printf 'commit: %s\n\nupstream %s: %s\n\narm64 only, without on-device ML (translation, neural image codec).\n' \
|
|
"$SHA" "${UPSTREAM_REFS%% *}" "$upstream")
|
|
jq -n --arg t "v$NAME" --arg c "$SHA" --arg b "$body" \
|
|
'{tag_name: $t, target_commitish: $c, name: $t, body: $b}' >"$RUNNER_TEMP/rel.json"
|
|
id=$(curl -sSf --config - -X POST -H 'Content-Type: application/json' \
|
|
--data-binary "@$RUNNER_TEMP/rel.json" "$api/releases" <<<"$auth" | jq -r .id)
|
|
curl -sSf --config - -X POST -F "attachment=@$APK" \
|
|
"$api/releases/$id/assets?name=$(basename "$APK")" <<<"$auth" >/dev/null
|
|
echo "released v$NAME (id $id)"
|
|
# Keep the newest KEEP_RELEASES releases and their tags.
|
|
curl -sSf --config - "$api/releases?limit=50" <<<"$auth" |
|
|
jq -r --argjson k "$KEEP_RELEASES" '.[$k:][] | "\(.id) \(.tag_name)"' |
|
|
while read -r old tag; do
|
|
curl -sSf --config - -X DELETE "$api/releases/$old" <<<"$auth"
|
|
curl -sSf --config - -X DELETE "$api/tags/$(jq -rn --arg t "$tag" '$t|@uri')" <<<"$auth" || true
|
|
echo "removed $tag"
|
|
done
|
|
|
|
# SBOM of the released dependencies to Dependency-Track from the same
|
|
# scan; a DT outage (or a missing key) does not fail the release.
|
|
- name: SBOM to Dependency-Track
|
|
if: steps.rel.outputs.needed == 'true'
|
|
uses: https://git.rfa.cz/tth-pub/ci-actions/dtrack-sbom@v3
|
|
with:
|
|
report: ${{ steps.trivy.outputs.report }}
|
|
url: https://dtrack.grg
|
|
api-key: ${{ secrets.DTRACK_API_KEY }}
|
|
ca-pem: ${{ vars.RFA_CA_PEM }}
|
|
project: meshcore-open
|
|
version: tth
|
|
|
|
- name: Close failure issue
|
|
if: success()
|
|
env:
|
|
TOKEN: ${{ secrets.GITEA_TOKEN || github.token }}
|
|
run: bash .gitea/upstream-sync.sh resolve
|
|
|
|
- name: Report failure
|
|
if: failure()
|
|
env:
|
|
TOKEN: ${{ secrets.GITEA_TOKEN || github.token }}
|
|
run: bash .gitea/upstream-sync.sh report
|