blob: 7f1d1586ec0522c56ec900fe10b2501a4bae9384 [file] [edit]
#!/usr/bin/env bash
# Parse Bazel console log for failures and optionally rerun with debug.
set -euo pipefail
RUN_CMD="${1:-}"
RERUN_WITH_DEBUG="${2:-false}"
mkdir -p build/failures
awk '$1 ~ /^\/\// && $2 ~ /(FAILED|TIMEOUT|INCOMPLETE)/ && $3 == "in" { print $1 }' build/bazel-console.log > build/failures/_run1.txt
if [ "$RERUN_WITH_DEBUG" != "true" ]; then
echo "::error::Run Bazel failed and rerun-with-debug is not enabled — propagating failure without retry."
exit 1
fi
if [ ! -s build/failures/_run1.txt ]; then
echo "::error::Run Bazel failed but no test failures were parsed — likely a build error or infra failure."
exit 1
fi
if [[ "$RUN_CMD" == *"/ci-build.sh"* ]]; then
base_cmd="bazel test --config=rbe-ci --build_tests_only --keep_going"
else
base_cmd=$(echo "$RUN_CMD" | sed 's| //[^ ]*||g')
fi
targets=$(tr '\n' ' ' < build/failures/_run1.txt)
echo "Rerunning tests: $base_cmd --test_env=SE_DEBUG=true --flaky_test_attempts=1 $targets"
set +e
{
$base_cmd --test_env=SE_DEBUG=true --flaky_test_attempts=1 $targets
} 2>&1 | tee build/bazel-console2.log
status=$?
set -e
awk '$1 ~ /^\/\// && $2 ~ /FAILED/ && $3 == "in" { print $1 }' build/bazel-console2.log > build/failures/_run2.txt
exit $status