fix(ci): rbe pre-warm survives a failed gh run list under bash -e, and clamps an over-long worker count (#7162) (#7163)
Actions runs the dispatch step as bash -e, so a failing gh run list ended the step at the assignment and the could-not-read warning never printed. The assignment now tolerates the failure. A RBE_PREWARM_WORKERS too long for the shell's integer compare slipped past the max-4 clamp and the loop dispatched without bound; two or more digits is now decided in the case (all zeros stays the kill switch). The behaviour test runs the script with bash -e, as Actions does, under a 30s deadline, and pins the clamp. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
0500fc6f40
commit
82872a81a5
2 changed files with 37 additions and 2 deletions
12
.github/workflows/bazel.yml
vendored
12
.github/workflows/bazel.yml
vendored
|
|
@ -621,6 +621,16 @@ jobs:
|
|||
case "$n" in
|
||||
'') n=1 ;;
|
||||
*[!0-9]*) n=1 ;;
|
||||
# Two or more digits is over the cap unless they are all zeros
|
||||
# (still the kill switch); deciding it here keeps a string too
|
||||
# long for the shell's integer compare from slipping past the
|
||||
# -gt below unclamped.
|
||||
??*)
|
||||
case "$n" in
|
||||
*[!0]*) n=4 ;;
|
||||
*) n=0 ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
if [ "$n" -gt 4 ]; then
|
||||
n=4
|
||||
|
|
@ -637,7 +647,7 @@ jobs:
|
|||
fi
|
||||
|
||||
active="$(gh run list -R "$POOL_REPO" --workflow "$POOL_WORKFLOW" --limit 50 \
|
||||
--json status --jq '[.[] | select(.status != "completed")] | length' 2>/dev/null)"
|
||||
--json status --jq '[.[] | select(.status != "completed")] | length' 2>/dev/null)" || true
|
||||
case "$active" in
|
||||
'' | *[!0-9]*)
|
||||
echo "::warning title=rbe-west pre-warm::could not read $POOL_REPO/$POOL_WORKFLOW run status; skipping dispatch"
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
package scripts_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// This file exists alongside ci_workflow_test.go's broader structural checks
|
||||
|
|
@ -494,7 +496,14 @@ exit 127
|
|||
if err := os.WriteFile(callLog, nil, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cmd := exec.Command("bash", scriptPath)
|
||||
// Actions runs a run: step with no shell: as "bash -e {0}", so the
|
||||
// script is run the same way here: a command that fails outside an
|
||||
// if/||/&& ends the step before any warning below it can print.
|
||||
// The deadline bounds a regression in the dispatch loop's clamp,
|
||||
// which would otherwise dispatch (and log) without end.
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
cmd := exec.CommandContext(ctx, "bash", "-e", scriptPath)
|
||||
// fakeGHDir first so it shadows any real gh on PATH; the rest of the
|
||||
// inherited PATH stays so the fake gh's own "#!/usr/bin/env bash"
|
||||
// shebang can still find env and bash.
|
||||
|
|
@ -577,6 +586,22 @@ exit 127
|
|||
}
|
||||
})
|
||||
|
||||
t.Run("an over-long RBE_PREWARM_WORKERS is clamped to 4", func(t *testing.T) {
|
||||
// 20 digits overflows the shell's integer compare; the clamp must
|
||||
// not depend on it.
|
||||
r := run(t, map[string]string{
|
||||
"GH_TOKEN": "tok",
|
||||
"RBE_PREWARM_WORKERS": "99999999999999999999",
|
||||
"FAKE_GH_RUN_LIST_OUTPUT": "1",
|
||||
})
|
||||
if r.code != 0 {
|
||||
t.Errorf("exit code = %d, want 0\nstdout: %s", r.code, r.stdout)
|
||||
}
|
||||
if got := strings.Count(r.calls, "workflow run"); got != 3 {
|
||||
t.Errorf("gh workflow run calls = %d, want 3 (cap 4, 1 active)\nstdout: %s", got, r.stdout)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("gh workflow run failure warns but still exits 0", func(t *testing.T) {
|
||||
r := run(t, map[string]string{
|
||||
"GH_TOKEN": "tok",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue