* ci(bazel): serve gazelle's go_repository tools from the repository cache Every bazel.yml lane starts from a fresh output base, and before any go_deps repository can be fetched gazelle compiles fetch_repo and gazelle with `go build` in @bazel_gazelle_go_repository_tools: 18-24 s of every 2 vCPU lane's loading phase (the top ci-analytics repo_fetch entry in the embedded, proxied, cmd-dolt and test lanes). tools/bazel/go_repository_tools.bzl replaces that repository (override_repo on gazelle's non_module_deps extension). The build is reproducible, so the three binaries are pinned by sha256 per gazelle release, Go SDK and host. The rule asks the repository cache for the pinned digests first (Bazel re-hashes every hit, so a restored runner cache can only yield the pinned bytes); on a miss it builds exactly as gazelle does, inside env -i, and stores a matching build in the repository cache. An unpinned or stale combination still builds from source and prints the digests to pin. scripts/bazel_go_repository_tools_test.go keeps the pins in step with MODULE.bazel's gazelle and go_sdk versions. The runner cache key already includes MODULE.bazel, so the first push to main after this saves them. Analysis-only (--nobuild) per lane on Blacksmith 2 vCPU, main vs this change with a seeded runner cache (ga-vnycm2.8): test 54.0 -> 38.3 s, embedded 53.6 -> 31.1 s, integration 49.6 -> 35.2 s, doltserver 48.5 -> 33.0 s, proxied 46.6 -> 31.6 s, server-storage 33.5 -> 17.3 s, cmd-dolt 50.3 -> 33.0 s. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * ci(bazel): pin gazelle's go_repository tools for Go 1.26.9 too Ready for the next go_sdk bump (gascity#7387 moves to 1.26.9 for the 2026-10-08 advisories): the same binaries keep coming from the repository cache instead of failing the pin test. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
73 lines
3 KiB
Go
73 lines
3 KiB
Go
package scripts_test
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// MODULE.bazel substitutes tools/bazel/go_repository_tools.bzl for
|
|
// gazelle's @bazel_gazelle_go_repository_tools, which serves fetch_repo and
|
|
// gazelle from the repository cache by pinned sha256 instead of compiling
|
|
// them in every fresh output base. A gazelle or Go SDK bump without new pins
|
|
// still builds (from source) but silently loses that, so the pins must name
|
|
// the versions MODULE.bazel pins.
|
|
|
|
const goRepositoryToolsRule = "tools/bazel/go_repository_tools.bzl"
|
|
|
|
var goRepositoryToolsNames = []string{"fetch_repo", "gazelle", "generate_repo_config"}
|
|
|
|
func TestGoRepositoryToolsOverridesGazelle(t *testing.T) {
|
|
module := readPolicyFile(t, bazelPolicyRoot(t), hermeticCCModuleFile)
|
|
for _, want := range []string{
|
|
`gazelle_non_module_deps = use_extension("@gazelle//internal/bzlmod:non_module_deps.bzl", "non_module_deps")`,
|
|
`go_repository_tools = use_repo_rule("//tools/bazel:go_repository_tools.bzl", "go_repository_tools")`,
|
|
`go_repository_tools(name = "gazelle_go_repository_tools")`,
|
|
} {
|
|
if !strings.Contains(module, want) {
|
|
t.Errorf("%s must contain %s", hermeticCCModuleFile, want)
|
|
}
|
|
}
|
|
override, err := moduleCall(module, "override_repo", "gazelle_non_module_deps")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(override, `bazel_gazelle_go_repository_tools = "gazelle_go_repository_tools"`) {
|
|
t.Errorf("override_repo(gazelle_non_module_deps, ...) must map bazel_gazelle_go_repository_tools to gazelle_go_repository_tools, got:\n%s", override)
|
|
}
|
|
}
|
|
|
|
func TestGoRepositoryToolsPinnedForModuleVersions(t *testing.T) {
|
|
root := bazelPolicyRoot(t)
|
|
module := readPolicyFile(t, root, hermeticCCModuleFile)
|
|
gazelle := regexp.MustCompile(`(?m)^bazel_dep\(name = "gazelle", version = "([^"]+)"\)`).FindStringSubmatch(module)
|
|
if gazelle == nil {
|
|
t.Fatalf("%s: no bazel_dep(name = \"gazelle\", version = ...)", hermeticCCModuleFile)
|
|
}
|
|
sdk, err := moduleCall(module, "go_sdk.download", `name = "go_sdk"`)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
goVersion := regexp.MustCompile(`version = "([^"]+)"`).FindStringSubmatch(sdk)
|
|
if goVersion == nil {
|
|
t.Fatalf("%s: go_sdk.download(name = \"go_sdk\") has no version", hermeticCCModuleFile)
|
|
}
|
|
|
|
// CI's lanes run on linux/amd64; that host must always be pinned.
|
|
key := gazelle[1] + "/go" + goVersion[1] + "/linux_amd64"
|
|
rule := readPolicyFile(t, root, goRepositoryToolsRule)
|
|
entry := regexp.MustCompile(`(?s)"` + regexp.QuoteMeta(key) + `": \{(.*?)\}`).FindStringSubmatch(rule)
|
|
if entry == nil {
|
|
t.Fatalf("%s: _PINS has no %q entry (gazelle %s, Go %s from %s); fetch @gazelle_go_repository_tools on linux/amd64 and copy the digests it prints",
|
|
goRepositoryToolsRule, key, gazelle[1], goVersion[1], hermeticCCModuleFile)
|
|
}
|
|
pins := quotedPairs(entry[1])
|
|
if len(pins) != len(goRepositoryToolsNames) {
|
|
t.Errorf("_PINS[%q] = %v, want exactly %v", key, pins, goRepositoryToolsNames)
|
|
}
|
|
for _, tool := range goRepositoryToolsNames {
|
|
if !sha256HexRE.MatchString(pins[tool]) {
|
|
t.Errorf("_PINS[%q][%q] = %q, want a sha256", key, tool, pins[tool])
|
|
}
|
|
}
|
|
}
|