diff --git a/check-nested-modules.sh b/check-nested-modules.sh new file mode 100644 index 00000000..ce37d2f9 --- /dev/null +++ b/check-nested-modules.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# The unit tests of every Go module of its own below this repository's root, run from the root, for merge-check.sh +# and for the test that tries it on a tree (merge_check_nested_test.go). Its own file so that the test needs no +# particular merge-check.sh: the check that judges a change to merge-check.sh is main's. +set -eu +cgo="${cgo:-0}" +race="${race:-}" + +# nested_modules vets and tests every Go module of its own below the root, `modules//go.mod` (novox/hq ADR 0420 +# §5, issue 1025): `./...` stops at a nested go.mod, so a module that lives whole in this repository would have its +# unit tests run by nobody. None is a pass. Each runs in its own directory, outside the vendor directory this +# repository's own packages are built from; how its dependencies are found offline is issue 1019's (the move of the +# first two modules in), and it is settled there. A failing module fails the check; the others are still run. +nested_modules() { + nested=0 + for gomod in modules/*/go.mod; do + [ -e "$gomod" ] || continue + dir=$(dirname "$gomod") + echo "nested module $dir:" + if ! (cd "$dir" && GOFLAGS= CGO_ENABLED=0 go vet ./... && + GOFLAGS= CGO_ENABLED="${cgo:-0}" go test ${race:-} -count=1 -timeout 30m ./...); then + echo "nested module $dir FAILED" + nested=1 + fi + done + return $nested +} + +nested_modules diff --git a/cmd/mesh-controller/merge_check_nested_test.go b/cmd/mesh-controller/merge_check_nested_test.go index 933c7a5d..e8888954 100644 --- a/cmd/mesh-controller/merge_check_nested_test.go +++ b/cmd/mesh-controller/merge_check_nested_test.go @@ -9,10 +9,10 @@ import ( ) // **A repository's merge check runs every module's unit tests, a Go module of its own below the root included** -// (novox/hq ADR 0420 §5, issue 1025): `./...` stops at a nested go.mod. This runs the script's own -// `nested-modules` mode in a tree with a `go` that only records where it was run and fails for a module named bad. +// (novox/hq ADR 0420 §5, issue 1025): `./...` stops at a nested go.mod. This runs the script +// check-nested-modules.sh in a tree with a `go` that only records where it was run and fails for a module named bad. func TestTheMergeCheckVetsAndTestsEveryNestedGoModule(t *testing.T) { - script, err := filepath.Abs("../../merge-check.sh") + script, err := filepath.Abs("../../check-nested-modules.sh") if err != nil { t.Fatal(err) } @@ -24,7 +24,7 @@ func TestTheMergeCheckVetsAndTestsEveryNestedGoModule(t *testing.T) { t.Fatal(err) } run := func() (string, error) { - cmd := exec.Command("sh", script, "nested-modules") + cmd := exec.Command("sh", script) cmd.Dir = tree cmd.Env = append(os.Environ(), "PATH="+bin+":"+os.Getenv("PATH"), "LOG="+log, "GOFLAGS=-mod=vendor") out, err := cmd.CombinedOutput() diff --git a/cmd/mesh-controller/merge_gate_test.go b/cmd/mesh-controller/merge_gate_test.go index e50cb483..9852431d 100644 --- a/cmd/mesh-controller/merge_gate_test.go +++ b/cmd/mesh-controller/merge_gate_test.go @@ -527,6 +527,10 @@ func TestADeliveryGroupMovingAModuleMachinesRunPassesTheGate(t *testing.T) { f, manifests := catalogueMeshWithAnApp(t) catTree := aTree(t, withEdit(manifests, "album", "")) app := t.TempDir() + // The app module is built from this repository's root, and stays there: only album moves. + if err := os.WriteFile(filepath.Join(app, "module.json"), []byte(`{"module":"app","version":"1"}`), 0o644); err != nil { + t.Fatal(err) + } if err := os.MkdirAll(filepath.Join(app, "modules", "album"), 0o755); err != nil { t.Fatal(err) } diff --git a/merge-check.sh b/merge-check.sh index f30cc9de..239bf8ac 100755 --- a/merge-check.sh +++ b/merge-check.sh @@ -36,30 +36,11 @@ judge_store_tests() { missing=$((missing + 1)) fi } -# nested_modules vets and tests every Go module of its own below the root, `modules//go.mod` (novox/hq ADR 0420 -# §5, issue 1025): `./...` stops at a nested go.mod, so a module that lives whole in this repository would have its -# unit tests run by nobody. None is a pass. Each runs in its own directory, outside the vendor directory this -# repository's own packages are built from; how its dependencies are found offline is issue 1019's (the move of the -# first two modules in), and it is settled there. A failing module fails the check; the others are still run. +# Every Go module of its own below the root, vetted and tested (novox/hq ADR 0420 §5, issue 1025): `./...` stops at a +# nested go.mod. Its own file, check-nested-modules.sh, which takes $cgo and $race from here. nested_modules() { - nested=0 - for gomod in modules/*/go.mod; do - [ -e "$gomod" ] || continue - dir=$(dirname "$gomod") - echo "nested module $dir:" - if ! (cd "$dir" && GOFLAGS= CGO_ENABLED=0 go vet ./... && - GOFLAGS= CGO_ENABLED="${cgo:-0}" go test ${race:-} -count=1 -timeout 30m ./...); then - echo "nested module $dir FAILED" - nested=1 - fi - done - return $nested + cgo="$cgo" race="$race" sh ./check-nested-modules.sh } -# `sh merge-check.sh nested-modules` runs only that, to try it on a tree. -if [ "${1:-}" = nested-modules ]; then - nested_modules - exit -fi # `sh merge-check.sh judge-store-tests …` runs only the judging, to try it on a # recorded `go test -v` output. if [ "${1:-}" = judge-store-tests ]; then