beads/scripts/BUILD.bazel
Julian Knutsen a4509deb2d
ci(bazel): nogo replaces go vet and golangci-lint (ga-96smfk.18) (#7341)
* ci(bazel): nogo replaces go vet and golangci-lint (ga-96smfk.18)

Lint and vet now run as nogo inside the Bazel build, so they gate wherever
the Bazel lanes execute (rbe-west), and the golangci-lint and go vet jobs
leave pr.yml and main.yml.

- //tools/nogo (own go.mod, joined to beads' for go_deps only through
  gazelle.go.work): go test's vet checks (cmd/go's defaultVetFlags, the set
  scripts/ci/go-test-vet.sh ran) plus the eight linters .golangci.yml
  enables, each a wrapper over the library version golangci-lint v2.10.1
  uses (depguard, errcheck, forbidigo, gosec, misspell, sloglint, unconvert,
  unparam).
- .golangci.yml stays the single lint policy: Bazel embeds it and
  tools/nogo/internal/golangci applies it as golangci-lint does (enabled
  set, settings, run.tests: false as library-unit-only analysis, lax
  generated-file detection, path/path-except/text exclusion rules), with
  strict decoding so an unimplemented key fails the build.
- gascity's rules_go //nolint-range patch and x/tools ctrlflow patch,
  byte-identical.
- Windows/darwin: cross-configured, not a golangci leg. The pure lane's
  release cross-compile (//tools/bazel:release_cross, every library and
  binary for all eight release platforms, cgo off) runs nogo on every
  compile, a superset of golangci-lint's windows and darwin legs.
  scripts/pr-lint (make ci-pr-lint, bd preflight) runs `bazel build
  --config=nogo //...` plus release_cross for windows_amd64,darwin_arm64.
  release_cross skips tools/nogo, a separate Go module `go build ./...`
  never compiled.
- pr.yml: scripts-go-checks (vet) and pr-lint-wrapper (x3) are gone, with
  their ci-gate entries; main.yml: pr-lint-wrapper (x6) and go-vet-cache.
  scripts/ci/go-test-vet.sh and install-golangci-lint.sh are deleted.
- pre-commit hook and .pre-commit-config.yaml run `make lint-changed
  LINT_CHANGED_SCOPE=staged` (nogo over the staged packages); Makefile adds
  lint, vet and lint-changed. pr-lint.sh no longer runs gofmt
  (//scripts/repochecks:fmt_test owns it; ga-96smfk.41).
- internal/testutil/integration: five gosec findings in integration-tagged
  library files golangci-lint never built, now linted by the integration
  lanes, carry reasoned //nolint directives.

Parity: with the exclusion rules removed, golangci-lint and nogo report the
same 3,916 findings natively and 3,859 each for windows and darwin (file,
line, linter, text); with .golangci.yml as committed both report none.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): equivalence.py leaves nested Go modules' tests out of go test's set

tools/nogo is its own Go module, so `go test ./...` in the root never runs
its tests; Bazel's unit lane does. Its packages are neither expected nor
extra.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-07 05:17:22 +00:00

175 lines
5.7 KiB
Python

load("@rules_go//go:def.bzl", "go_test")
# CI and repo-policy tests: they parse the workflows, run the CI shell scripts
# against fixtures, and check repository-wide rules (BUILD tag taxonomy, skip
# allowlist, managed BUILD blocks, shard manifests, tracked-file scans) over
# //:repo_files, the checkout as Bazel sees it.
#
# No tags: they run remotely like any other target. The scripts and fixtures
# run bash, git, python3, jq, yq, curl, openssl, unzip and coreutils from the
# executor (the rbe-west worker image, or the runner in fork-cache mode); a
# missing tool fails the test under Bazel instead of skipping it
# (host_tools_test.go), so a cached pass never stands for an executor that
# could not run it. Go and the release formula come in hermetically.
go_test(
name = "scripts_test",
srcs = [
"bazel_autofix_push_test.go",
"bazel_cache_mode_test.go",
"bazel_farm_workflow_test.go",
"bazel_fork_mode_test.go",
"bazel_hermetic_cc_test.go",
"bazel_policy_test.go",
"bazel_rbe_prewarm_test.go",
"bazel_skip_allowlist_test.go",
"check_build_tags_test.go",
"check_doc_freshness_test.go",
"check_release_cross_compile_test.go",
"check_testing_short_test.go",
"check_winget_portable_alias_test.go",
"ci_actions_policy_test.go",
"ci_blacksmith_runner_test.go",
"ci_capability_selector_test.go",
"ci_f7b_review_test.go",
"ci_f7c_advisory_test.go",
"ci_merge_queue_test.go",
"ci_workflow_apt_get_timeout_test.go",
"ci_workflow_test.go",
"complexity_script_test.go",
"conformance_script_test.go",
"embedded_shard_count_test.go",
"host_tools_test.go",
"install_dolt_test.go",
"managed_local_lane_test.go",
"migration_corpus_bazel_test.go",
"nogo_lint_policy_test.go",
"pr_lanes_bazel_coverage_test.go",
"pr_preflight_test.go",
"pr_risk_bazel_coverage_test.go",
"pull_dolt_image_test.go",
"rbe_worker_env_test.go",
"release_script_test.go",
"repo_helpers_test.go",
"required_suite_test.go",
"test_script_test.go",
"upgrade_smoke_loop_test.go",
"windows_test_binaries_manifest_test.go",
],
data = [
"//:repo_files",
"@beads_formulas//:beads-release.formula.toml",
"@go_sdk//:bin/go",
"@go_sdk//:files",
],
# The release formula lives in .beads/ (in .bazelignore: it also holds
# live bd data), so it comes in through its own local repository. The Go
# SDK is go.mod's toolchain, whatever go the executor has on PATH.
env = {
"BEADS_TEST_GO": "$(rlocationpath @go_sdk//:bin/go)",
"BEADS_TEST_RELEASE_FORMULA": "$(rlocationpath @beads_formulas//:beads-release.formula.toml)",
},
deps = [
"//internal/formula",
"//internal/testutil/bazeltest",
"//scripts/internal/testbash",
"@in_gopkg_yaml_v3//:yaml_v3",
],
)
# pr.yml's check-doc-freshness-platforms Linux leg: `go test
# -tags integration ./scripts -count=1 -run '^(TestDocFreshness.*|
# TestRequiredSuiteContract)$' -args -required-suite=doc-freshness`, whose
# TestMain fails unless exactly the doc-freshness inventory is compiled and
# selected. scripts_test runs those tests too (in the integration lane); this
# target adds the inventory and selection contract, over only the files the
# suite reads (its fixtures copy check-doc-freshness.sh). The macOS and
# Windows legs stay in pr.yml.
# Tags:
# integration-only: every TestDocFreshness test is //go:build integration,
# so --config=integration's lane runs it.
go_test(
name = "doc_freshness_required_test",
srcs = [
"check_doc_freshness_test.go",
"repo_helpers_test.go",
"required_suite_test.go",
],
args = [
"-test.count=1",
"-test.run=^(TestDocFreshness.*|TestRequiredSuiteContract)$$",
"-required-suite=doc-freshness",
],
data = ["check-doc-freshness.sh"],
tags = ["integration-only"],
deps = [
"//internal/testutil/bazeltest",
"//scripts/internal/testbash",
],
)
exports_files(
["migration-test/release-catalog.json"],
visibility = ["//scripts/migration-test/catalog:__pkg__"],
)
# The historical-upgrade harness (scripts/migration-test) and the public
# SQLite bridge it drives, for //tests/migration's per-release targets.
filegroup(
name = "migration_harness",
srcs = [
"migrate-legacy-to-current.sh",
"migration-test/historical-dolt-upgrade-test.sh",
"migration-test/legacy-bridge-test.sh",
"migration-test/lib/binary.sh",
"migration-test/lib/versions.sh",
],
visibility = ["//tests/migration:__pkg__"],
)
exports_files(
["upgrade-smoke-test.sh"],
visibility = ["//tests/upgrade_smoke:__pkg__"],
)
exports_files(
[
"ci/fmt-check.sh",
"ci/lib/timing.sh",
"ci/pr-lint.sh",
],
visibility = ["//scripts/prlintmake:__pkg__"],
)
exports_files(
["ci/gofmt-bin.sh"],
visibility = ["//scripts/prlintmake:__pkg__"],
)
# The compatibility entrypoint whose exit-status contract
# //scripts/check-versions:check-versions_test drives.
exports_files(
["check-versions.sh"],
visibility = ["//scripts/check-versions:__pkg__"],
)
# --- begin repo_files (managed by tools/bazel/go_srcs.py; run `make bazel-sync`) ---
filegroup(
name = "repo_files",
srcs = glob(
["**"],
exclude = [
"**/*.db",
"**/*.exe",
"**/*.out",
"**/*.prof",
"**/*.pyc",
"**/*.test",
"**/__pycache__/**",
"**/node_modules/**",
],
),
visibility = ["//:__pkg__"],
)
# --- end repo_files ---