--- # 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: "); 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: build: runs-on: big permissions: contents: write issues: write container: image: ghcr.io/cirruslabs/flutter:stable steps: # Plain git instead of actions/checkout: that is a JS action and the # image (Ubuntu 24.04) only offers node 18. - 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@v1.2 with: mode: warn - name: Trivy config uses: https://git.rfa.cz/tth-pub/ci-actions/trivy-gate@v1.2.2 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 - 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: warn = phase 1 (report only), block = phase 2. - name: Trivy gate id: trivy if: steps.rel.outputs.needed == 'true' uses: https://git.rfa.cz/tth-pub/ci-actions/trivy-gate@v1.2 with: scan-type: fs mode: warn 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" 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@v1.2 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