From 01e07562d6e58f9d865b3696ed2d0a20db47541c Mon Sep 17 00:00:00 2001 From: diffwireauto <330573775+diffwireauto@users.noreply.github.com> Date: Mon, 30 Nov 2026 23:00:00 -0500 Subject: [PATCH] ci(#1347): re-run a build that failed only in its native-assets downloads Package build hooks (sqlite3, llamadart) download prebuilt libraries during flutter build. A bad download fails the build with "Building native assets failed" although the code is fine. It hit Windows, macOS and Android four times on 2026-11-30, each needing a manual re-run, once on a release-promotion PR. flutter-build-retry.sh runs the build and builds again, up to 3 attempts in all, only when the output names that failure. Any other failure is returned at once. Every native flutter build in build.yml, release-signed.yml, ios-signed.yml and macos-signed.yml goes through it; the Windows steps run it under bash. A new build.yml step proves it: a clean build runs once, a failure that clears runs twice, a lasting one stops at 3 and fails, and a compile error is not retried. Run locally against a retry that never retries and one that retries everything, the step fails both. Co-Authored-By: Claude Opus 5.5 --- .github/scripts/flutter-build-retry.sh | 33 +++++++++++++++++++++++ .github/workflows/build.yml | 37 ++++++++++++++++++++++---- .github/workflows/ios-signed.yml | 2 +- .github/workflows/macos-signed.yml | 2 +- .github/workflows/release-signed.yml | 9 ++++--- 5 files changed, 72 insertions(+), 11 deletions(-) create mode 100755 .github/scripts/flutter-build-retry.sh diff --git a/.github/scripts/flutter-build-retry.sh b/.github/scripts/flutter-build-retry.sh new file mode 100755 index 00000000..b68323cc --- /dev/null +++ b/.github/scripts/flutter-build-retry.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# Run a flutter build, and re-run it only when it failed in the native-assets +# step (#1347). Package build hooks (sqlite3, llamadart) download prebuilt +# libraries during the build; a bad or broken download fails the whole build +# with "Building native assets failed" although the code is fine. Any other +# failure is returned at once, unretried. +# +# Usage: flutter-build-retry.sh [args...] +# FLUTTER_BUILD_ATTEMPTS sets the total number of attempts (default 3). +set -uo pipefail + +attempts="${FLUTTER_BUILD_ATTEMPTS:-3}" +marker='Building native assets failed' +log="$(mktemp)" +trap 'rm -f "${log}"' EXIT + +status=1 +for ((i = 1; i <= attempts; i++)); do + "$@" 2>&1 | tee "${log}" + status=${PIPESTATUS[0]} + if [ "${status}" -eq 0 ]; then + exit 0 + fi + if ! grep -qF "${marker}" "${log}"; then + exit "${status}" + fi + if [ "${i}" -lt "${attempts}" ]; then + echo "::warning::Native assets failed on attempt ${i} of ${attempts}; building again (#1347)." + fi +done + +echo "::error::Native assets failed on all ${attempts} attempts (#1347)." +exit "${status}" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ef3e44bd..f0f68542 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -102,7 +102,7 @@ jobs: env: GIPHY_API_KEY: ${{ secrets.GIPHY_API_KEY }} run: jq -n --arg k "$GIPHY_API_KEY" '{GIPHY_API_KEY:$k}' > dart_defines.json - - run: flutter build apk --release --no-pub --dart-define-from-file=dart_defines.json + - run: bash .github/scripts/flutter-build-retry.sh flutter build apk --release --no-pub --dart-define-from-file=dart_defines.json if: needs.classify.outputs.docs_only != 'true' - name: Upload APK if: needs.classify.outputs.docs_only != 'true' @@ -136,7 +136,7 @@ jobs: env: GIPHY_API_KEY: ${{ secrets.GIPHY_API_KEY }} run: jq -n --arg k "$GIPHY_API_KEY" '{GIPHY_API_KEY:$k}' > dart_defines.json - - run: flutter build ios --release --no-codesign --no-pub --dart-define-from-file=dart_defines.json + - run: bash .github/scripts/flutter-build-retry.sh flutter build ios --release --no-codesign --no-pub --dart-define-from-file=dart_defines.json if: needs.classify.outputs.docs_only != 'true' # The assertion must be able to fail, so it runs against an empty app first. - name: "Negative: the framework assertion refuses an empty app" @@ -277,6 +277,32 @@ jobs: fi done echo "Accepted only CI and docs changes from a real tag, as required." + # The build retry (#1347) must re-run only a native-assets failure, and + # must still fail when that failure doesn't clear or another one hits. + - name: "Negative: the build retry re-runs only a native-assets failure" + if: needs.classify.outputs.docs_only != 'true' + run: | + set -u + RETRY="${GITHUB_WORKSPACE}/.github/scripts/flutter-build-retry.sh" + T="${RUNNER_TEMP}/retry-check" + mkdir -p "${T}" + # fake + printf '%s\n' \ + 'n=$(( $(cat "$1" 2>/dev/null || echo 0) + 1 )); echo "$n" > "$1"' \ + 'if [ "$n" -le "$2" ]; then echo "$3"; exit 1; fi' \ + 'echo built' > "${T}/fake.sh" + run() { rm -f "${T}/count"; bash "${RETRY}" bash "${T}/fake.sh" "${T}/count" "$@" > /dev/null; } + calls() { cat "${T}/count"; } + NA='Target dart_build failed: Error: Building native assets failed.' + run 0 "${NA}" || { echo "::error::A clean build was reported as failed."; exit 1; } + [ "$(calls)" = 1 ] || { echo "::error::A clean build ran $(calls) times."; exit 1; } + run 1 "${NA}" || { echo "::error::A native-assets failure that cleared on retry still failed."; exit 1; } + [ "$(calls)" = 2 ] || { echo "::error::A cleared native-assets failure ran $(calls) times, not 2."; exit 1; } + if run 9 "${NA}"; then echo "::error::A native-assets failure that never cleared passed."; exit 1; fi + [ "$(calls)" = 3 ] || { echo "::error::A lasting native-assets failure ran $(calls) times, not 3."; exit 1; } + if run 1 "error: compile failed in lib/main.dart"; then echo "::error::A compile error was retried into a pass."; exit 1; fi + [ "$(calls)" = 1 ] || { echo "::error::A compile error was retried ($(calls) runs)."; exit 1; } + echo "Retried only native-assets failures, at most 3 attempts, as required." - uses: subosito/flutter-action@v2 if: needs.classify.outputs.docs_only != 'true' with: @@ -297,7 +323,7 @@ jobs: - name: Enable native assets (bundles sqlite3 + llamadart libs, #445) if: needs.classify.outputs.docs_only != 'true' run: flutter config --enable-native-assets - - run: flutter build linux --release --no-pub --dart-define-from-file=dart_defines.json + - run: bash .github/scripts/flutter-build-retry.sh flutter build linux --release --no-pub --dart-define-from-file=dart_defines.json if: needs.classify.outputs.docs_only != 'true' - name: Upload Linux bundle if: needs.classify.outputs.docs_only != 'true' @@ -334,7 +360,7 @@ jobs: - name: Enable native assets (bundles sqlite3 + llamadart libs, #445) if: needs.classify.outputs.docs_only != 'true' run: flutter config --enable-native-assets - - run: flutter build macos --release --no-pub --dart-define-from-file=dart_defines.json + - run: bash .github/scripts/flutter-build-retry.sh flutter build macos --release --no-pub --dart-define-from-file=dart_defines.json if: needs.classify.outputs.docs_only != 'true' # ditto, not zip: it preserves the .app bundle's symlinks, which plain # zip flattens into copies that break code-signing validation (#1108). @@ -431,8 +457,9 @@ jobs: - name: Enable native assets (bundles sqlite3 + llamadart libs, #445) if: needs.classify.outputs.docs_only != 'true' run: flutter config --enable-native-assets - - run: flutter build windows --release --no-pub --dart-define-from-file=dart_defines.json + - run: bash .github/scripts/flutter-build-retry.sh flutter build windows --release --no-pub --dart-define-from-file=dart_defines.json if: needs.classify.outputs.docs_only != 'true' + shell: bash - name: Upload Windows build if: needs.classify.outputs.docs_only != 'true' uses: actions/upload-artifact@v4 diff --git a/.github/workflows/ios-signed.yml b/.github/workflows/ios-signed.yml index d8c3b7e4..5e4807ff 100644 --- a/.github/workflows/ios-signed.yml +++ b/.github/workflows/ios-signed.yml @@ -179,7 +179,7 @@ jobs: echo "BUILD_NAME=${BUILD_NAME}" >> "$GITHUB_ENV" echo "BUILD_NUMBER=${BUILD_NUMBER}" >> "$GITHUB_ENV" echo "Building ${BUILD_NAME} (${BUILD_NUMBER})." - flutter build ipa --release --no-pub \ + bash .github/scripts/flutter-build-retry.sh flutter build ipa --release --no-pub \ --build-name="${BUILD_NAME}" \ --build-number="${BUILD_NUMBER}" \ --dart-define-from-file=dart_defines.json \ diff --git a/.github/workflows/macos-signed.yml b/.github/workflows/macos-signed.yml index 3e3afaf6..73216ef3 100644 --- a/.github/workflows/macos-signed.yml +++ b/.github/workflows/macos-signed.yml @@ -112,7 +112,7 @@ jobs: run: jq -n --arg k "$GIPHY_API_KEY" '{GIPHY_API_KEY:$k}' > dart_defines.json - name: Enable native assets (bundles sqlite3 + llamadart libs, #445) run: flutter config --enable-native-assets - - run: flutter build macos --release --no-pub --dart-define-from-file=dart_defines.json + - run: bash .github/scripts/flutter-build-retry.sh flutter build macos --release --no-pub --dart-define-from-file=dart_defines.json # Inside-out: every nested Mach-O first, then each framework bundle, then # the app with its entitlements. Hardened Runtime and a secure timestamp diff --git a/.github/workflows/release-signed.yml b/.github/workflows/release-signed.yml index 89b64513..25b758eb 100644 --- a/.github/workflows/release-signed.yml +++ b/.github/workflows/release-signed.yml @@ -114,9 +114,9 @@ jobs: GIPHY_API_KEY: ${{ secrets.GIPHY_API_KEY }} run: jq -n --arg k "$GIPHY_API_KEY" '{GIPHY_API_KEY:$k}' > dart_defines.json - name: Build signed APK - run: flutter build apk --release --no-pub --dart-define-from-file=dart_defines.json + run: bash .github/scripts/flutter-build-retry.sh flutter build apk --release --no-pub --dart-define-from-file=dart_defines.json - name: Build signed AAB - run: flutter build appbundle --release --no-pub --dart-define-from-file=dart_defines.json + run: bash .github/scripts/flutter-build-retry.sh flutter build appbundle --release --no-pub --dart-define-from-file=dart_defines.json # A green build does NOT prove release signing: build.gradle.kts silently # falls back to the debug config when key.properties is absent (#111). Read @@ -225,7 +225,8 @@ jobs: Set-Content -Path dart_defines.json -Encoding utf8 -NoNewline - name: Enable native assets (bundles sqlite3 + llamadart libs, #445) run: flutter config --enable-native-assets - - run: flutter build windows --release --no-pub --dart-define-from-file=dart_defines.json + - run: bash .github/scripts/flutter-build-retry.sh flutter build windows --release --no-pub --dart-define-from-file=dart_defines.json + shell: bash - name: Zip Windows build run: Compress-Archive -Path build/windows/x64/runner/Release/* -DestinationPath offband-windows-x64.zip - uses: actions/upload-artifact@v4 @@ -256,7 +257,7 @@ jobs: run: jq -n --arg k "$GIPHY_API_KEY" '{GIPHY_API_KEY:$k}' > dart_defines.json - name: Enable native assets (bundles sqlite3 + llamadart libs, #445) run: flutter config --enable-native-assets - - run: flutter build linux --release --no-pub --dart-define-from-file=dart_defines.json + - run: bash .github/scripts/flutter-build-retry.sh flutter build linux --release --no-pub --dart-define-from-file=dart_defines.json - name: Tar Linux bundle run: tar -czf offband-linux-x64.tar.gz -C build/linux/x64/release/bundle . - uses: actions/upload-artifact@v4