Merge pull request #1356 from OffbandMesh/ci/1347-native-assets-retry

ci(#1347): re-run a build that failed only in its native-assets downloads
pull/1359/head
Strycher 2 days ago committed by GitHub
commit 7d0941be47
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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 <command> [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}"

@ -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 <count file> <failures before success> <message>
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

@ -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 \

@ -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

@ -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

Loading…
Cancel
Save

Powered by TurnKey Linux.