Every pull_request and merge group already took the Bazel lanes for the
retired tiers (BAZEL_RETIRES_LEGACY_* and BAZEL_COVERS_FORKS all "true",
and pr.yml/pr-risk.yml run on no other event), so the legacy jobs those
flags stood down could never run again. Remove them with their decision:
- pr-risk.yml: build-embedded, test-embedded-{storage,conformance,cmd},
test-proxied-cmd, test-server-storage{,-full}, detect-ci-tier (and its
ci-embedded-tier.sh / ci-capability-selector.sh scripts) and
bazel-coverage. PR Risk keeps the Nix packaging check (test-nix) and its
gate, PR Risk Gate / Required.
- pr.yml: build-artifacts, check-cmd-bd-puregeo-tests, pr-core-wrapper and
bazel-coverage; the BAZEL_RETIRES_LEGACY_* and BAZEL_COVERS_FORKS flags.
The three BAZEL_*_RETIRED gate ids become one, BAZEL_REMOTE: the Bazel
call must have run remotely (remote, fork-ro or fork-rw) on every PR and
merge group, each lane's own id still required. Gate names unchanged.
Policy tests: the D2 decision matrix becomes
TestPRGateRequiresRemoteBazelLanes (bazel.yml's actual rbe step and
pr.yml's actual gate over every event/variable/secret/fork/actor/mint
fact); the parity tests that read the legacy jobs now pin the Bazel lanes
against those jobs' frozen commands.
ga-96smfk.22
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
193 lines
5.4 KiB
Go
193 lines
5.4 KiB
Go
package scripts_test
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"runtime"
|
|
"strconv"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
const doltSQLServerImage = "dolthub/dolt-sql-server:2.2.0"
|
|
|
|
func TestPullDoltImageRetriesTransientFailures(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
failures int
|
|
wantExit int
|
|
wantPulls int
|
|
wantSleeps int
|
|
}{
|
|
{name: "immediate success", failures: 0, wantExit: 0, wantPulls: 1, wantSleeps: 0},
|
|
{name: "eventual success", failures: 2, wantExit: 0, wantPulls: 3, wantSleeps: 2},
|
|
{name: "exhausted retries", failures: 3, wantExit: 42, wantPulls: 3, wantSleeps: 2},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
run := runPullDoltImage(t, test.failures)
|
|
if got := pullDoltExitCode(run.err); got != test.wantExit {
|
|
t.Fatalf("exit = %d, want %d; error=%v\n%s", got, test.wantExit, run.err, run.output)
|
|
}
|
|
if len(run.dockerCalls) != test.wantPulls {
|
|
t.Fatalf("docker pull count = %d, want %d; calls=%q\n%s", len(run.dockerCalls), test.wantPulls, run.dockerCalls, run.output)
|
|
}
|
|
for _, call := range run.dockerCalls {
|
|
if call != "pull "+doltSQLServerImage {
|
|
t.Fatalf("docker call = %q, want %q", call, "pull "+doltSQLServerImage)
|
|
}
|
|
}
|
|
if len(run.sleepCalls) != test.wantSleeps {
|
|
t.Fatalf("sleep count = %d, want %d; calls=%q\n%s", len(run.sleepCalls), test.wantSleeps, run.sleepCalls, run.output)
|
|
}
|
|
for _, call := range run.sleepCalls {
|
|
if call != "5" {
|
|
t.Fatalf("sleep call = %q, want 5", call)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestDoltImagePullWorkflowsUseRetryHelper(t *testing.T) {
|
|
// No workflow pulls the image: every Dolt suite runs on hermetic dolt
|
|
// sql-servers (bazel.yml's dolt-server lanes) and needs no docker, since
|
|
// pr-risk.yml's container-backed legacy tiers were retired
|
|
// (ga-96smfk.22). The helper stays for local container-backed runs.
|
|
wantCalls := map[string]int{}
|
|
|
|
workflowsDir := filepath.Join(sourceRepoRoot(t), ".github", "workflows")
|
|
workflowPaths, err := filepath.Glob(filepath.Join(workflowsDir, "*.y*ml"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, path := range workflowPaths {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
text := string(data)
|
|
name := filepath.Base(path)
|
|
if got, want := strings.Count(text, "run: ./scripts/ci/pull-dolt-image.sh"), wantCalls[name]; got != want {
|
|
t.Errorf("%s retry-helper calls = %d, want %d", name, got, want)
|
|
}
|
|
if strings.Contains(text, "docker pull "+doltSQLServerImage) {
|
|
t.Errorf("%s still pulls the Dolt image without retries", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestPullDoltImageHelperIsExecutable(t *testing.T) {
|
|
if runtime.GOOS == "windows" {
|
|
t.Skip("Windows does not preserve Unix executable bits")
|
|
}
|
|
|
|
path := filepath.Join(sourceRepoRoot(t), "scripts", "ci", "pull-dolt-image.sh")
|
|
info, err := os.Stat(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if info.Mode().Perm()&0o111 == 0 {
|
|
t.Fatalf("%s is not executable", path)
|
|
}
|
|
}
|
|
|
|
type pullDoltRun struct {
|
|
output string
|
|
dockerCalls []string
|
|
sleepCalls []string
|
|
err error
|
|
}
|
|
|
|
func runPullDoltImage(t *testing.T, failures int) pullDoltRun {
|
|
t.Helper()
|
|
|
|
bash := requireHostTool(t, "bash")
|
|
|
|
bin := t.TempDir()
|
|
stateDir := t.TempDir()
|
|
dockerLog := filepath.Join(stateDir, "docker-calls")
|
|
sleepLog := filepath.Join(stateDir, "sleep-calls")
|
|
for _, path := range []string{dockerLog, sleepLog} {
|
|
if err := os.WriteFile(path, nil, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
writeExecutable(t, filepath.Join(bin, "docker"), `#!/bin/sh
|
|
set -eu
|
|
count=0
|
|
if [ -s "$DOLT_PULL_CALL_COUNT" ]; then
|
|
IFS= read -r count <"$DOLT_PULL_CALL_COUNT"
|
|
fi
|
|
count=$((count + 1))
|
|
printf '%s\n' "$count" >"$DOLT_PULL_CALL_COUNT"
|
|
printf '%s\n' "$*" >>"$DOLT_PULL_DOCKER_LOG"
|
|
if [ "$count" -le "$DOLT_PULL_FAILURES" ]; then
|
|
exit 42
|
|
fi
|
|
`)
|
|
writeExecutable(t, filepath.Join(bin, "sleep"), `#!/bin/sh
|
|
set -eu
|
|
printf '%s\n' "$*" >>"$DOLT_PULL_SLEEP_LOG"
|
|
`)
|
|
|
|
pathEnv := shellPathEnv()
|
|
binPath := shellPathUnderEnv(t, bash, bin, pathEnv)
|
|
statePath := shellPathUnderEnv(t, bash, stateDir, pathEnv)
|
|
commandPath := binPath + ":" + os.Getenv("PATH") + ":/usr/bin:/bin"
|
|
if runtime.GOOS == "windows" {
|
|
commandPath = binPath + ":/usr/bin:/bin"
|
|
}
|
|
root := sourceRepoRoot(t)
|
|
env := []string{
|
|
"PATH=" + os.Getenv("PATH"),
|
|
"BEADS_TEST_COMMAND_PATH=" + commandPath,
|
|
"LC_ALL=C",
|
|
"LANG=C",
|
|
"BASH_ENV=",
|
|
"ENV=",
|
|
"DOLT_PULL_CALL_COUNT=" + statePath + "/docker-call-count",
|
|
"DOLT_PULL_DOCKER_LOG=" + statePath + "/docker-calls",
|
|
"DOLT_PULL_SLEEP_LOG=" + statePath + "/sleep-calls",
|
|
"DOLT_PULL_FAILURES=" + strconv.Itoa(failures),
|
|
}
|
|
requireShellCommandPath(t, bash, root, env, "docker", binPath+"/docker")
|
|
requireShellCommandPath(t, bash, root, env, "sleep", binPath+"/sleep")
|
|
|
|
cmd := bashScriptCommand(bash, "scripts/ci/pull-dolt-image.sh")
|
|
cmd.Dir = root
|
|
cmd.Env = env
|
|
output, runErr := cmd.CombinedOutput()
|
|
|
|
dockerCalls := readCallLines(t, dockerLog)
|
|
sleepCalls := readCallLines(t, sleepLog)
|
|
return pullDoltRun{output: string(output), dockerCalls: dockerCalls, sleepCalls: sleepCalls, err: runErr}
|
|
}
|
|
|
|
func readCallLines(t *testing.T, path string) []string {
|
|
t.Helper()
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
text := strings.TrimSpace(string(data))
|
|
if text == "" {
|
|
return nil
|
|
}
|
|
return strings.Split(text, "\n")
|
|
}
|
|
|
|
func pullDoltExitCode(err error) int {
|
|
if err == nil {
|
|
return 0
|
|
}
|
|
var exitErr *exec.ExitError
|
|
if errors.As(err, &exitErr) {
|
|
return exitErr.ExitCode()
|
|
}
|
|
return -1
|
|
}
|