11#! /bin/bash
2- # Provides retry_build(): 3-attempt loop with configurable cleanup.
3- # Set RETRY_CLEAN_CMD to override cleanup (default: rm -rf build/staging build/install build/lock.yaml).
4- # Set RETRY_VALIDATE_CMD to run a post-build validation; failure triggers a retry.
2+ # Provides retry_build(): 2-attempt loop.
3+ # On failure of attempt 1, nukes the entire build directory before attempt 2.
4+ # If RETRY_VALIDATE_CMD is set, runs it after a successful build; a non-zero
5+ # exit triggers the same nuke-and-retry, catching e.g. SIGILL from binaries
6+ # compiled on a different CPU architecture.
57# Usage: source .github/scripts/retry-build.sh
68# retry_build ./mfc.sh build -j 8 --gpu acc
7-
8- # Try normal cleanup; if it fails, escalate to cache nuke.
9- _retry_clean () {
10- local clean_cmd=" $1 "
11- if eval " $clean_cmd " 2> /dev/null; then
12- return 0
13- fi
14- echo " Normal cleanup failed."
15- if type _cache_nuke > /dev/null 2>&1 ; then
16- echo " Escalating to NFS cache nuke..."
17- _cache_nuke
18- else
19- echo " _cache_nuke not available, best-effort rm."
20- rm -rf build/staging build/install build/lock.yaml 2> /dev/null || true
21- fi
22- }
9+ # RETRY_VALIDATE_CMD='./syscheck' retry_build ./mfc.sh build -j 8
2310
2411retry_build () {
25- local clean_cmd= " ${RETRY_CLEAN_CMD :- rm -rf build / staging build / install build / lock.yaml} "
12+ local max_attempts=2
2613 local validate_cmd=" ${RETRY_VALIDATE_CMD:- } "
27- local max_attempts=3
2814 local attempt=1
2915 while [ $attempt -le $max_attempts ]; do
3016 echo " Build attempt $attempt of $max_attempts ..."
@@ -33,8 +19,8 @@ retry_build() {
3319 if ! eval " $validate_cmd " ; then
3420 echo " Post-build validation failed on attempt $attempt ."
3521 if [ $attempt -lt $max_attempts ]; then
36- echo " Cleaning and retrying in 5s ..."
37- _retry_clean " $clean_cmd "
22+ echo " Nuking build directory before retry ..."
23+ rm -rf build 2> /dev/null || true
3824 sleep 5
3925 attempt=$(( attempt + 1 ))
4026 continue
@@ -48,8 +34,8 @@ retry_build() {
4834 return 0
4935 fi
5036 if [ $attempt -lt $max_attempts ]; then
51- echo " Build failed on attempt $attempt . Retrying in 30s ..."
52- _retry_clean " $clean_cmd "
37+ echo " Build failed — nuking build directory before retry ..."
38+ rm -rf build 2> /dev/null || true
5339 sleep 30
5440 else
5541 echo " Build failed after $max_attempts attempts."
0 commit comments