diff --git a/.bazelrc b/.bazelrc index 24311ce7..15df5cb2 100644 --- a/.bazelrc +++ b/.bazelrc @@ -17,6 +17,10 @@ import %workspace%/ci.bazelrc # import ci.bazelrc and they do not have a //build:execution_env flag. build:ci --//build:execution_env=ci +# The parent workspace always runs with bzlmod enabled. +common --enable_bzlmod +build --@cgrindel_bazel_starlib//bzlmod:enabled + # Try to import a local.rc file; typically, written by CI try-import %workspace%/local.bazelrc diff --git a/.github/actions/configure_bzlmod/action.yml b/.github/actions/configure_bzlmod/action.yml index 4d24d755..fc7fcc0d 100644 --- a/.github/actions/configure_bzlmod/action.yml +++ b/.github/actions/configure_bzlmod/action.yml @@ -12,7 +12,7 @@ runs: if: inputs.enabled == 'true' shell: bash run: | - cat >> "shared.bazelrc" <> "child_workspace.bazelrc" <> "shared.bazelrc" <> "child_workspace.bazelrc" < -int_test_params_json -output + +This utility generates a new GitHub actions workflow file for this project. + +`) + flag.PrintDefaults() + } + flag.Parse() + + // Read the workflow YAML + workflowYAML, err := os.ReadFile(templatePath) + if err != nil { + return fmt.Errorf("could not read template at '%s': %w", templatePath, err) + } + workflow, err := github.NewWorkflowFromYAML(workflowYAML) + if err != nil { + return err + } + + // Read the example JSON + intTestParamsJSON, err := os.ReadFile(intTestParamsJSONPath) + if err != nil { + return fmt.Errorf( + "could not read integration test params JSON at '%s': %w", + intTestParamsJSONPath, + err, + ) + } + intTestParams, err := testparams.NewIntTestParamsFromJSON(intTestParamsJSON) + if err != nil { + return err + } + + // Set up the macOS matrix + if err := updateJob(workflow.Jobs, intTestMatrixKey, intTestParams); err != nil { + return err + } + + // Write the output file + var outBuf bytes.Buffer + if _, err := outBuf.WriteString(hdrMsg); err != nil { + return err + } + yamlEncoder := yaml.NewEncoder(&outBuf) + yamlEncoder.SetIndent(2) + err = yamlEncoder.Encode(&workflow) + if err != nil { + return err + } + if err := os.WriteFile(outputPath, outBuf.Bytes(), 0666); err != nil { + return fmt.Errorf("failed to write output YAML to '%s': %w", outputPath, err) + } + + return nil +} + +func updateJob(jobs map[string]github.Job, key string, intTestParams []testparams.IntTestParams) error { + job, ok := jobs[key] + if !ok { + return fmt.Errorf("did not find '%s' job", key) + } + matrix := job.Strategy.Matrix + updateMatrix(&matrix, intTestParams) + job.Strategy.Matrix = matrix + jobs[key] = job + + return nil +} + +func updateMatrix(m *github.SBMatrixStrategy, intTestParams []testparams.IntTestParams) { + newM := github.SBMatrixStrategy{} + for _, itp := range intTestParams { + inc := github.SBMatrixInclude{ + Test: itp.Test, + Runner: itp.Runner(), + EnableBzlmod: itp.EnableBzlmod(), + } + newM.Include = append(newM.Include, inc) + } + *m = newM +} + +const hdrMsg = `# Portions of this file are generated by the build. +# +# Note: +# - Modification to values outside of the matrix strategy sections should +# persist. +# - Comments and custom formatting will be lost. +` diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel index dd5f6cca..3798637a 100644 --- a/examples/BUILD.bazel +++ b/examples/BUILD.bazel @@ -1,4 +1,5 @@ load("@bazel_binaries//:defs.bzl", "bazel_binaries") +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load( "@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "bazel_integration_tests", @@ -7,6 +8,8 @@ load( ) load("//bzlformat:defs.bzl", "bzlformat_pkg") load("//bzllib:defs.bzl", "lists") +load("//ci:defs.bzl", "ci_integration_test_params", "ci_test_params_suite") +load(":examples.bzl", "examples") bzlformat_pkg(name = "bzlformat") @@ -15,51 +18,84 @@ bzlformat_pkg(name = "bzlformat") # MARK: - Integration Tests -_EXAMPLE_DIRS = ["bzlmod_e2e"] +_EXAMPLES = [ + examples.new( + bzlmod_modes = ["enabled"], + dirname = "bzlmod_e2e", + oss = [ + "macos", + "linux", + ], + target_compatible_with = select({ + "@cgrindel_bazel_starlib//bzlmod:is_enabled": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + ), +] default_test_runner(name = "default_test_runner") [ bazel_integration_tests( - name = "{}_test".format(dirname), + name = "{}_test".format(example.dirname), timeout = "eternal", bazel_binaries = bazel_binaries, bazel_versions = bazel_binaries.versions.all, - target_compatible_with = select({ - "@cgrindel_bazel_starlib//bzlmod:is_enabled": [], - "//conditions:default": ["@platforms//:incompatible"], - }), + target_compatible_with = example.target_compatible_with, test_runner = ":default_test_runner", - workspace_files = integration_test_utils.glob_workspace_files(dirname) + [ + workspace_files = integration_test_utils.glob_workspace_files(example.dirname) + [ "//:workspace_integration_test_files", ], - workspace_path = dirname, + workspace_path = example.dirname, ) - for dirname in _EXAMPLE_DIRS + for example in _EXAMPLES ] +[ + ci_integration_test_params( + name = "{}_test_params".format(example.dirname), + bzlmod_modes = example.bzlmod_modes, + oss = example.oss, + test_names = integration_test_utils.bazel_integration_test_names( + "{}_test".format(example.dirname), + bazel_binaries.versions.all, + ), + visibility = ["//:__subpackages__"], + ) + for example in _EXAMPLES +] + +ci_test_params_suite( + name = "all_test_params", + test_params = [ + "{}_test_params".format(example.dirname) + for example in _EXAMPLES + ], + visibility = ["//:__subpackages__"], +) + test_suite( name = "smoke_integration_tests", tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS, tests = [ integration_test_utils.bazel_integration_test_name( - ":{}_test".format(dirname), + ":{}_test".format(example.dirname), bazel_binaries.versions.current, ) - for dirname in _EXAMPLE_DIRS + for example in _EXAMPLES ], visibility = ["//:__subpackages__"], ) test_suite( - name = "integration_tests", + name = "all_integration_tests", tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS, tests = lists.flatten([ integration_test_utils.bazel_integration_test_names( - ":{}_test".format(dirname), + ":{}_test".format(example.dirname), bazel_binaries.versions.all, ) - for dirname in _EXAMPLE_DIRS + for example in _EXAMPLES ]), visibility = ["//:__subpackages__"], ) @@ -71,3 +107,9 @@ filegroup( srcs = glob(["bzlmod_e2e/**"]), visibility = ["//:__subpackages__"], ) + +bzl_library( + name = "examples", + srcs = ["examples.bzl"], + visibility = ["//visibility:public"], +) diff --git a/examples/bzlformat/BUILD.bazel b/examples/bzlformat/BUILD.bazel index 37a62197..b38c731c 100644 --- a/examples/bzlformat/BUILD.bazel +++ b/examples/bzlformat/BUILD.bazel @@ -5,6 +5,7 @@ load( "integration_test_utils", ) load("//bzlformat:defs.bzl", "bzlformat_pkg") +load("//ci:defs.bzl", "ci_integration_test_params") bzlformat_pkg(name = "bzlformat") @@ -66,7 +67,7 @@ test_suite( ) test_suite( - name = "integration_tests", + name = "all_integration_tests", tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS, tests = integration_test_utils.bazel_integration_test_names( ":simple_test", @@ -74,3 +75,26 @@ test_suite( ), visibility = ["//:__subpackages__"], ) + +ci_integration_test_params( + name = "simple_test_params", + bzlmod_modes = [ + "enabled", + "disabled", + ], + oss = [ + "macos", + "linux", + ], + test_names = integration_test_utils.bazel_integration_test_names( + "simple_test", + bazel_binaries.versions.all, + ), + visibility = ["//:__subpackages__"], +) + +alias( + name = "all_test_params", + actual = ":simple_test_params", + visibility = ["//:__subpackages__"], +) diff --git a/examples/bzlformat/simple/.bazelrc b/examples/bzlformat/simple/.bazelrc index cb4f7903..d95ba88d 100644 --- a/examples/bzlformat/simple/.bazelrc +++ b/examples/bzlformat/simple/.bazelrc @@ -7,3 +7,6 @@ import %workspace%/../../../ci.bazelrc # Try to import a local.rc file; typically, written by CI try-import %workspace%/../../../local.bazelrc +# Try to load parameters for the child workspace(s). These configuration values +# should not be loaded by the parent workspace. +try-import %workspace%/../../../child_workspace.bazelrc diff --git a/examples/examples.bzl b/examples/examples.bzl new file mode 100644 index 00000000..cd3e1c41 --- /dev/null +++ b/examples/examples.bzl @@ -0,0 +1,25 @@ +"""Implementation for `examples` module.""" + +def _new(dirname, bzlmod_modes = ["enabled"], oss = ["macos", "linux"], target_compatible_with = None): + """Create an example struct. + + Args: + dirname: The directory name as a `string`. + bzlmod_modes: A `list` of `string` values representing the bzlmod + modes (e.g., `enabled`, `disabled`). + oss: A `list` of operating systems (e.g., `linux`, `macos`). + target_compatible_with: Optional. The value that should be set for the + the integration test. + + Returns: + """ + return struct( + dirname = dirname, + bzlmod_modes = bzlmod_modes, + oss = oss, + target_compatible_with = target_compatible_with, + ) + +examples = struct( + new = _new, +) diff --git a/examples/markdown/BUILD.bazel b/examples/markdown/BUILD.bazel index edb3a210..d0a5c295 100644 --- a/examples/markdown/BUILD.bazel +++ b/examples/markdown/BUILD.bazel @@ -6,6 +6,7 @@ load( "bazel_integration_tests", "integration_test_utils", ) +load("//ci:defs.bzl", "ci_integration_test_params") bzlformat_pkg(name = "bzlformat") @@ -90,7 +91,7 @@ test_suite( ) test_suite( - name = "integration_tests", + name = "all_integration_tests", tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS, tests = integration_test_utils.bazel_integration_test_names( "simple_test", @@ -98,3 +99,26 @@ test_suite( ), visibility = ["//:__subpackages__"], ) + +ci_integration_test_params( + name = "simple_test_params", + bzlmod_modes = [ + "enabled", + "disabled", + ], + oss = [ + "macos", + "linux", + ], + test_names = integration_test_utils.bazel_integration_test_names( + "simple_test", + bazel_binaries.versions.all, + ), + visibility = ["//:__subpackages__"], +) + +alias( + name = "all_test_params", + actual = ":simple_test_params", + visibility = ["//:__subpackages__"], +) diff --git a/examples/markdown/simple/.bazelrc b/examples/markdown/simple/.bazelrc index 63ab7f51..d95ba88d 100644 --- a/examples/markdown/simple/.bazelrc +++ b/examples/markdown/simple/.bazelrc @@ -6,3 +6,7 @@ import %workspace%/../../../ci.bazelrc # Try to import a local.rc file; typically, written by CI try-import %workspace%/../../../local.bazelrc + +# Try to load parameters for the child workspace(s). These configuration values +# should not be loaded by the parent workspace. +try-import %workspace%/../../../child_workspace.bazelrc diff --git a/examples/updatesrc/BUILD.bazel b/examples/updatesrc/BUILD.bazel index 90d92369..323b0165 100644 --- a/examples/updatesrc/BUILD.bazel +++ b/examples/updatesrc/BUILD.bazel @@ -6,6 +6,7 @@ load( "default_test_runner", "integration_test_utils", ) +load("//ci:defs.bzl", "ci_integration_test_params") bzlformat_pkg(name = "bzlformat") @@ -59,7 +60,7 @@ test_suite( ) test_suite( - name = "integration_tests", + name = "all_integration_tests", tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS, tests = integration_test_utils.bazel_integration_test_names( "simple_test", @@ -67,3 +68,26 @@ test_suite( ), visibility = ["//:__subpackages__"], ) + +ci_integration_test_params( + name = "simple_test_params", + bzlmod_modes = [ + "enabled", + "disabled", + ], + oss = [ + "macos", + "linux", + ], + test_names = integration_test_utils.bazel_integration_test_names( + "simple_test", + bazel_binaries.versions.all, + ), + visibility = ["//:__subpackages__"], +) + +alias( + name = "all_test_params", + actual = ":simple_test_params", + visibility = ["//:__subpackages__"], +) diff --git a/examples/updatesrc/simple/.bazelrc b/examples/updatesrc/simple/.bazelrc index 63ab7f51..d95ba88d 100644 --- a/examples/updatesrc/simple/.bazelrc +++ b/examples/updatesrc/simple/.bazelrc @@ -6,3 +6,7 @@ import %workspace%/../../../ci.bazelrc # Try to import a local.rc file; typically, written by CI try-import %workspace%/../../../local.bazelrc + +# Try to load parameters for the child workspace(s). These configuration values +# should not be loaded by the parent workspace. +try-import %workspace%/../../../child_workspace.bazelrc diff --git a/go.mod b/go.mod index 8aff3d7d..77352a49 100644 --- a/go.mod +++ b/go.mod @@ -3,14 +3,17 @@ module github.com/cgrindel/bazel-starlib go 1.19 require ( + github.com/creasty/defaults v1.7.0 github.com/ekalinin/github-markdown-toc.go v1.2.1 + github.com/stretchr/testify v1.8.4 gopkg.in/alecthomas/kingpin.v2 v2.2.4 + gopkg.in/yaml.v3 v3.0.1 ) require ( github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect golang.org/x/sys v0.10.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 7261ca83..4c4a4be6 100644 --- a/go.sum +++ b/go.sum @@ -5,18 +5,23 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5Vpd github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/creasty/defaults v1.7.0 h1:eNdqZvc5B509z18lD8yc212CAqJNvfT1Jq6L8WowdBA= +github.com/creasty/defaults v1.7.0/go.mod h1:iGzKe6pbEHnpMPtfDXZEr0NVxWnPTjb1bbDy08fPzYM= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/ekalinin/github-markdown-toc.go v1.2.1 h1:6jRFt5qg61XfXZbP3SDaeTX+1OC1EgbHvRceYDmPAUE= github.com/ekalinin/github-markdown-toc.go v1.2.1/go.mod h1:V5aiwoSLm1+er91D4l0AXn8vr4FX07Iu+zgDMFj3FeU= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= gopkg.in/alecthomas/kingpin.v2 v2.2.4 h1:CC8tJ/xljioKrK6ii3IeWVXU4Tw7VB+LbjZBJaBxN50= gopkg.in/alecthomas/kingpin.v2 v2.2.4/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/go_deps.bzl b/go_deps.bzl index c69768f4..5c020886 100644 --- a/go_deps.bzl +++ b/go_deps.bzl @@ -5,7 +5,7 @@ bazel-starlib repository. load("@bazel_gazelle//:deps.bzl", "go_repository") def bazel_starlib_go_dependencies(): - """Declare dependencies for bazel-starlib.""" + """Load dependencies for `bazel-starlib`.""" go_repository( name = "com_github_alecthomas_assert", build_external = "external", @@ -20,7 +20,6 @@ def bazel_starlib_go_dependencies(): sum = "h1:nOE9rJm6dsZ66RGWYSFrXw461ZIt9A6+nHgL7FRrDUk=", version = "v0.1.0", ) - go_repository( name = "com_github_alecthomas_repr", build_external = "external", @@ -42,6 +41,13 @@ def bazel_starlib_go_dependencies(): sum = "h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=", version = "v0.0.0-20151022065526-2efee857e7cf", ) + go_repository( + name = "com_github_creasty_defaults", + build_external = "external", + importpath = "github.com/creasty/defaults", + sum = "h1:eNdqZvc5B509z18lD8yc212CAqJNvfT1Jq6L8WowdBA=", + version = "v1.7.0", + ) go_repository( name = "com_github_davecgh_go_spew", build_external = "external", @@ -70,7 +76,6 @@ def bazel_starlib_go_dependencies(): sum = "h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=", version = "v1.0.0", ) - go_repository( name = "com_github_sergi_go_diff", build_external = "external", @@ -78,15 +83,20 @@ def bazel_starlib_go_dependencies(): sum = "h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=", version = "v1.2.0", ) - + go_repository( + name = "com_github_stretchr_objx", + build_external = "external", + importpath = "github.com/stretchr/objx", + sum = "h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=", + version = "v0.5.0", + ) go_repository( name = "com_github_stretchr_testify", build_external = "external", importpath = "github.com/stretchr/testify", - sum = "h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=", - version = "v1.7.0", + sum = "h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=", + version = "v1.8.4", ) - go_repository( name = "in_gopkg_alecthomas_kingpin_v2", build_external = "external", @@ -101,7 +111,6 @@ def bazel_starlib_go_dependencies(): sum = "h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=", version = "v0.0.0-20161208181325-20d25e280405", ) - go_repository( name = "in_gopkg_yaml_v3", build_external = "external", diff --git a/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/BUILD.bazel b/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/BUILD.bazel index dbb402f9..322e020d 100644 --- a/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/BUILD.bazel +++ b/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/BUILD.bazel @@ -5,6 +5,7 @@ load( "integration_test_utils", ) load("//bzlformat:defs.bzl", "bzlformat_pkg") +load("//ci:defs.bzl", "ci_integration_test_params") bzlformat_pkg(name = "bzlformat") @@ -55,7 +56,7 @@ test_suite( ) test_suite( - name = "integration_tests", + name = "all_integration_tests", tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS, tests = integration_test_utils.bazel_integration_test_names( ":missing_pkgs_test", @@ -63,3 +64,23 @@ test_suite( ), visibility = ["//:__subpackages__"], ) + +ci_integration_test_params( + name = "missing_pkgs_test_params", + bzlmod_modes = ["enabled"], + oss = [ + "macos", + "linux", + ], + test_names = integration_test_utils.bazel_integration_test_names( + "missing_pkgs_test", + bazel_binaries.versions.all, + ), + visibility = ["//:__subpackages__"], +) + +alias( + name = "all_test_params", + actual = ":missing_pkgs_test_params", + visibility = ["//:__subpackages__"], +) diff --git a/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/missing_pkgs_test.sh b/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/missing_pkgs_test.sh index acb76541..e505b68a 100755 --- a/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/missing_pkgs_test.sh +++ b/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/missing_pkgs_test.sh @@ -59,6 +59,7 @@ cd "${scratch_dir}" # MARK - Find the missing packages without exclusions +missing_pkgs=() while IFS=$'\n' read -r line; do missing_pkgs+=("$line"); done < <( "${bazel}" run "//:bzlformat_missing_pkgs_find" ) diff --git a/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/.bazelrc b/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/.bazelrc index 9ef42101..8794ad4b 100644 --- a/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/.bazelrc +++ b/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/workspace/.bazelrc @@ -7,5 +7,9 @@ import %workspace%/../../../../../ci.bazelrc # Try to import a local.rc file; typically, written by CI try-import %workspace%/../../../../../local.bazelrc +# Try to load parameters for the child workspace(s). These configuration values +# should not be loaded by the parent workspace. +try-import %workspace%/../../../../../child_workspace.bazelrc + # Explicitly enable bzlmod common --enable_bzlmod diff --git a/tests/bzlrelease_tests/BUILD.bazel b/tests/bzlrelease_tests/BUILD.bazel deleted file mode 100644 index a49b8a3e..00000000 --- a/tests/bzlrelease_tests/BUILD.bazel +++ /dev/null @@ -1,16 +0,0 @@ -load("//bzlformat:defs.bzl", "bzlformat_pkg") -load("//tests:integration_test_common.bzl", "INTEGRATION_TEST_TAGS") - -bzlformat_pkg(name = "bzlformat") - -test_suite( - name = "all_integration_tests", - tags = INTEGRATION_TEST_TAGS, - tests = [ - "//tests/bzlrelease_tests/rules_tests/generate_release_notes_tests:integration_tests", - "//tests/bzlrelease_tests/rules_tests/generate_workspace_snippet_tests:integration_tests", - "//tests/bzlrelease_tests/rules_tests/update_readme_tests:integration_tests", - "//tests/bzlrelease_tests/tools_tests:integration_tests", - ], - visibility = ["//:__subpackages__"], -) diff --git a/tests/bzlrelease_tests/rules_tests/generate_release_notes_tests/BUILD.bazel b/tests/bzlrelease_tests/rules_tests/generate_release_notes_tests/BUILD.bazel index 55b547d8..0eb2e249 100644 --- a/tests/bzlrelease_tests/rules_tests/generate_release_notes_tests/BUILD.bazel +++ b/tests/bzlrelease_tests/rules_tests/generate_release_notes_tests/BUILD.bazel @@ -5,6 +5,7 @@ load( "generate_release_notes", "generate_workspace_snippet", ) +load("//ci:defs.bzl", "ci_integration_test_params") load("//tests:integration_test_common.bzl", "GH_ENV_INHERIT", "INTEGRATION_TEST_TAGS") bzlformat_pkg(name = "bzlformat") @@ -52,11 +53,35 @@ sh_test( ], ) +_TEST_NAMES = [ + "generate_release_notes_test", +] + test_suite( - name = "integration_tests", + name = "all_integration_tests", tags = INTEGRATION_TEST_TAGS, tests = [ - ":generate_release_notes_test", + ":{}".format(name) + for name in _TEST_NAMES ], visibility = ["//:__subpackages__"], ) + +test_suite( + name = "smoke_integration_tests", + tags = INTEGRATION_TEST_TAGS, + tests = [ + ":{}".format(name) + for name in _TEST_NAMES + ], + visibility = ["//:__subpackages__"], +) + +ci_integration_test_params( + name = "all_test_params", + bzlmod_modes = ["enabled"], + # We only run this on linux. + oss = ["linux"], + test_names = _TEST_NAMES, + visibility = ["//:__subpackages__"], +) diff --git a/tests/bzlrelease_tests/rules_tests/generate_workspace_snippet_tests/BUILD.bazel b/tests/bzlrelease_tests/rules_tests/generate_workspace_snippet_tests/BUILD.bazel index 1010aee9..cb62dc17 100644 --- a/tests/bzlrelease_tests/rules_tests/generate_workspace_snippet_tests/BUILD.bazel +++ b/tests/bzlrelease_tests/rules_tests/generate_workspace_snippet_tests/BUILD.bazel @@ -1,6 +1,7 @@ load("@bazel_skylib//rules:write_file.bzl", "write_file") load("//bzlformat:defs.bzl", "bzlformat_pkg") load("//bzlrelease:defs.bzl", "generate_workspace_snippet", "hash_sha256", "release_archive") +load("//ci:defs.bzl", "ci_integration_test_params") load("//tests:integration_test_common.bzl", "GH_ENV_INHERIT", "INTEGRATION_TEST_TAGS") bzlformat_pkg(name = "bzlformat") @@ -57,11 +58,41 @@ sh_test( ], ) +_TEST_NAMES = [ + "generate_workspace_snippet_test", +] + +test_suite( + name = "all_integration_tests", + tags = INTEGRATION_TEST_TAGS, + tests = [ + ":{}".format(name) + for name in _TEST_NAMES + ], + visibility = ["//:__subpackages__"], +) + test_suite( - name = "integration_tests", + name = "smoke_integration_tests", tags = INTEGRATION_TEST_TAGS, tests = [ - ":generate_workspace_snippet_test", + ":{}".format(name) + for name in _TEST_NAMES ], visibility = ["//:__subpackages__"], ) + +ci_integration_test_params( + name = "generate_workspace_snippet_test_params", + bzlmod_modes = ["enabled"], + # We only run this on linux. + oss = ["linux"], + test_names = _TEST_NAMES, + visibility = ["//:__subpackages__"], +) + +alias( + name = "all_test_params", + actual = ":generate_workspace_snippet_test_params", + visibility = ["//:__subpackages__"], +) diff --git a/tests/bzlrelease_tests/rules_tests/update_readme_tests/BUILD.bazel b/tests/bzlrelease_tests/rules_tests/update_readme_tests/BUILD.bazel index 4b6e505f..12945e0d 100644 --- a/tests/bzlrelease_tests/rules_tests/update_readme_tests/BUILD.bazel +++ b/tests/bzlrelease_tests/rules_tests/update_readme_tests/BUILD.bazel @@ -5,6 +5,7 @@ load( "generate_workspace_snippet", "update_readme", ) +load("//ci:defs.bzl", "ci_integration_test_params") load("//tests:integration_test_common.bzl", "GH_ENV_INHERIT", "INTEGRATION_TEST_TAGS") bzlformat_pkg(name = "bzlformat") @@ -40,11 +41,35 @@ sh_test( ], ) +_TEST_NAMES = [ + "update_readme_test", +] + test_suite( - name = "integration_tests", + name = "all_integration_tests", tags = INTEGRATION_TEST_TAGS, tests = [ - ":update_readme_test", + ":{}".format(name) + for name in _TEST_NAMES ], visibility = ["//:__subpackages__"], ) + +test_suite( + name = "smoke_integration_tests", + tags = INTEGRATION_TEST_TAGS, + tests = [ + ":{}".format(name) + for name in _TEST_NAMES + ], + visibility = ["//:__subpackages__"], +) + +ci_integration_test_params( + name = "all_test_params", + bzlmod_modes = ["enabled"], + # We only run this on linux. + oss = ["linux"], + test_names = _TEST_NAMES, + visibility = ["//:__subpackages__"], +) diff --git a/tests/bzlrelease_tests/tools_tests/BUILD.bazel b/tests/bzlrelease_tests/tools_tests/BUILD.bazel index 53100f15..a5d5e38d 100644 --- a/tests/bzlrelease_tests/tools_tests/BUILD.bazel +++ b/tests/bzlrelease_tests/tools_tests/BUILD.bazel @@ -1,4 +1,5 @@ load("//bzlformat:defs.bzl", "bzlformat_pkg") +load("//ci:defs.bzl", "ci_integration_test_params") load("//tests:integration_test_common.bzl", "GH_ENV_INHERIT", "INTEGRATION_TEST_TAGS") bzlformat_pkg(name = "bzlformat") @@ -106,14 +107,38 @@ sh_test( ], ) +_TEST_NAMES = [ + "generate_gh_changelog_test", + "generate_git_archive_test", + "generate_release_notes_test", + "generate_workspace_snippet_test", +] + test_suite( - name = "integration_tests", + name = "all_integration_tests", tags = INTEGRATION_TEST_TAGS, tests = [ - ":generate_gh_changelog_test", - ":generate_git_archive_test", - ":generate_release_notes_test", - ":generate_workspace_snippet_test", + ":{}".format(name) + for name in _TEST_NAMES ], visibility = ["//:__subpackages__"], ) + +test_suite( + name = "smoke_integration_tests", + tags = INTEGRATION_TEST_TAGS, + tests = [ + ":{}".format(name) + for name in _TEST_NAMES + ], + visibility = ["//:__subpackages__"], +) + +ci_integration_test_params( + name = "all_test_params", + bzlmod_modes = ["enabled"], + # We only run this on linux. + oss = ["linux"], + test_names = _TEST_NAMES, + visibility = ["//:__subpackages__"], +) diff --git a/tests/bzltidy_tests/BUILD.bazel b/tests/bzltidy_tests/BUILD.bazel index 4212a3d1..e47d84fd 100644 --- a/tests/bzltidy_tests/BUILD.bazel +++ b/tests/bzltidy_tests/BUILD.bazel @@ -5,6 +5,7 @@ load( "integration_test_utils", ) load("//bzlformat:defs.bzl", "bzlformat_pkg") +load("//ci:defs.bzl", "ci_integration_test_params") bzlformat_pkg(name = "bzlformat") @@ -15,7 +16,6 @@ sh_binary( testonly = True, srcs = ["tidy_all_test.sh"], data = [ - # "@buildifier_prebuilt//buildozer", "@rules_bazel_integration_test//tools:create_scratch_dir", ], deps = [ @@ -54,7 +54,7 @@ test_suite( ) test_suite( - name = "integration_tests", + name = "all_integration_tests", tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS, tests = integration_test_utils.bazel_integration_test_names( ":tidy_all_test", @@ -62,3 +62,17 @@ test_suite( ), visibility = ["//:__subpackages__"], ) + +ci_integration_test_params( + name = "all_test_params", + bzlmod_modes = ["enabled"], + oss = [ + "linux", + "macos", + ], + test_names = integration_test_utils.bazel_integration_test_names( + "tidy_all_test", + bazel_binaries.versions.all, + ), + visibility = ["//:__subpackages__"], +) diff --git a/tests/bzltidy_tests/tidy_all_test.sh b/tests/bzltidy_tests/tidy_all_test.sh index 23a816c1..d7c8c5d5 100755 --- a/tests/bzltidy_tests/tidy_all_test.sh +++ b/tests/bzltidy_tests/tidy_all_test.sh @@ -72,7 +72,7 @@ output_prefix_regex='\[tidy_all\]' # Tidy all modified workspaces, but there are none. assert_msg="//:tidy_modified, no modifications" revert_changes "${scratch_dir}" -output="$( bazel run //:tidy_modified )" +output="$( "${bazel}" run //:tidy_modified )" tidy_out_files=() while IFS=$'\n' read -r line; do tidy_out_files+=("$line"); done < <( find_tidy_out_files "${scratch_dir}" @@ -84,7 +84,7 @@ assert_match "${output_prefix_regex}"\ No\ workspaces\ to\ tidy\. "${output}" "$ assert_msg="//:tidy_modified, modification in bar" revert_changes "${scratch_dir}" echo "# Modification" >> child_workspaces/bar/BUILD.bazel -output="$( bazel run //:tidy_modified )" +output="$( "${bazel}" run //:tidy_modified )" tidy_out_files=() while IFS=$'\n' read -r line; do tidy_out_files+=("$line"); done < <( find_tidy_out_files "${scratch_dir}" @@ -98,7 +98,7 @@ assert_msg="//:tidy_modified, modification in parent and bar" revert_changes "${scratch_dir}" echo "# Modification" >> BUILD.bazel echo "# Modification" >> child_workspaces/bar/BUILD.bazel -output="$( bazel run //:tidy_modified )" +output="$( "${bazel}" run //:tidy_modified )" tidy_out_files=() while IFS=$'\n' read -r line; do tidy_out_files+=("$line"); done < <( find_tidy_out_files "${scratch_dir}" @@ -113,7 +113,7 @@ assert_match \ # Tidy all all workspaces. assert_msg="//:tidy_all" revert_changes "${scratch_dir}" -output="$( bazel run //:tidy_all )" +output="$( "${bazel}" run //:tidy_all )" tidy_out_files=() while IFS=$'\n' read -r line; do tidy_out_files+=("$line"); done < <( find_tidy_out_files "${scratch_dir}" diff --git a/tests/bzltidy_tests/workspace/.bazelrc b/tests/bzltidy_tests/workspace/.bazelrc index 6009b2ae..ab64f9ae 100644 --- a/tests/bzltidy_tests/workspace/.bazelrc +++ b/tests/bzltidy_tests/workspace/.bazelrc @@ -9,6 +9,10 @@ import %workspace%/../../../ci.bazelrc # Try to import a local.rc file; typically, written by CI try-import %workspace%/../../../local.bazelrc +# Try to load parameters for the child workspace(s). These configuration values +# should not be loaded by the parent workspace. +try-import %workspace%/../../../child_workspace.bazelrc + # Explicitly enable bzlmod common --enable_bzlmod diff --git a/tests/bzltidy_tests/workspace/child_workspaces/bar/.bazelrc b/tests/bzltidy_tests/workspace/child_workspaces/bar/.bazelrc index 005fb31a..db8dd6ad 100644 --- a/tests/bzltidy_tests/workspace/child_workspaces/bar/.bazelrc +++ b/tests/bzltidy_tests/workspace/child_workspaces/bar/.bazelrc @@ -1,11 +1,5 @@ -# Import shared settings -import %workspace%/../../../../../shared.bazelrc - -# Import CI settings. -import %workspace%/../../../../../ci.bazelrc - -# Try to import a local.rc file; typically, written by CI -try-import %workspace%/../../../../../local.bazelrc +# Purposefully not importing the shared bazelrc files as they are +# not needed and saw failures when run in CI. # Explicitly enable bzlmod common --enable_bzlmod diff --git a/tests/bzltidy_tests/workspace/child_workspaces/foo/.bazelrc b/tests/bzltidy_tests/workspace/child_workspaces/foo/.bazelrc index 005fb31a..db8dd6ad 100644 --- a/tests/bzltidy_tests/workspace/child_workspaces/foo/.bazelrc +++ b/tests/bzltidy_tests/workspace/child_workspaces/foo/.bazelrc @@ -1,11 +1,5 @@ -# Import shared settings -import %workspace%/../../../../../shared.bazelrc - -# Import CI settings. -import %workspace%/../../../../../ci.bazelrc - -# Try to import a local.rc file; typically, written by CI -try-import %workspace%/../../../../../local.bazelrc +# Purposefully not importing the shared bazelrc files as they are +# not needed and saw failures when run in CI. # Explicitly enable bzlmod common --enable_bzlmod diff --git a/tests/shlib_tests/lib_tests/git_tests/BUILD.bazel b/tests/shlib_tests/lib_tests/git_tests/BUILD.bazel index 3f13fc4f..5b243100 100644 --- a/tests/shlib_tests/lib_tests/git_tests/BUILD.bazel +++ b/tests/shlib_tests/lib_tests/git_tests/BUILD.bazel @@ -1,4 +1,5 @@ load("//bzlformat:defs.bzl", "bzlformat_pkg") +load("//ci:defs.bzl", "ci_integration_test_params") load("//tests:integration_test_common.bzl", "GH_ENV_INHERIT", "INTEGRATION_TEST_TAGS") bzlformat_pkg(name = "bzlformat") @@ -20,11 +21,35 @@ sh_test( ], ) +_TEST_NAMES = [ + "git_integration_test", +] + test_suite( - name = "integration_tests", + name = "all_integration_tests", tags = INTEGRATION_TEST_TAGS, tests = [ - ":git_integration_test", + ":{}".format(name) + for name in _TEST_NAMES ], visibility = ["//:__subpackages__"], ) + +test_suite( + name = "smoke_integration_tests", + tags = INTEGRATION_TEST_TAGS, + tests = [ + ":{}".format(name) + for name in _TEST_NAMES + ], + visibility = ["//:__subpackages__"], +) + +ci_integration_test_params( + name = "all_test_params", + bzlmod_modes = ["enabled"], + # We only run this on linux. + oss = ["linux"], + test_names = ["git_integration_test"], + visibility = ["//:__subpackages__"], +) diff --git a/tests/shlib_tests/lib_tests/github_tests/BUILD.bazel b/tests/shlib_tests/lib_tests/github_tests/BUILD.bazel index e588b7cc..a283c09c 100644 --- a/tests/shlib_tests/lib_tests/github_tests/BUILD.bazel +++ b/tests/shlib_tests/lib_tests/github_tests/BUILD.bazel @@ -1,4 +1,5 @@ load("//bzlformat:defs.bzl", "bzlformat_pkg") +load("//ci:defs.bzl", "ci_integration_test_params") load("//tests:integration_test_common.bzl", "GH_ENV_INHERIT", "INTEGRATION_TEST_TAGS") bzlformat_pkg(name = "bzlformat") @@ -92,12 +93,36 @@ sh_test( ], ) +_TEST_NAMES = [ + "get_gh_auth_status_test", + "get_gh_changelog_test", +] + test_suite( - name = "integration_tests", + name = "all_integration_tests", tags = INTEGRATION_TEST_TAGS, tests = [ - ":get_gh_auth_status_test", - ":get_gh_changelog_test", + ":{}".format(name) + for name in _TEST_NAMES ], visibility = ["//:__subpackages__"], ) + +test_suite( + name = "smoke_integration_tests", + tags = INTEGRATION_TEST_TAGS, + tests = [ + ":{}".format(name) + for name in _TEST_NAMES + ], + visibility = ["//:__subpackages__"], +) + +ci_integration_test_params( + name = "all_test_params", + bzlmod_modes = ["enabled"], + # We only run this on linux. + oss = ["linux"], + test_names = _TEST_NAMES, + visibility = ["//:__subpackages__"], +) diff --git a/tests/updatesrc_tests/BUILD.bazel b/tests/updatesrc_tests/BUILD.bazel index 9c918021..168b41a4 100644 --- a/tests/updatesrc_tests/BUILD.bazel +++ b/tests/updatesrc_tests/BUILD.bazel @@ -7,6 +7,7 @@ load( "integration_test_utils", ) load("//bzlformat:defs.bzl", "bzlformat_pkg") +load("//ci:defs.bzl", "ci_integration_test_params") bzlformat_pkg(name = "bzlformat") @@ -50,7 +51,7 @@ test_suite( ) test_suite( - name = "integration_tests", + name = "all_integration_tests", tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS, tests = integration_test_utils.bazel_integration_test_names( ":updatesrc_test", @@ -58,3 +59,20 @@ test_suite( ), visibility = ["//:__subpackages__"], ) + +ci_integration_test_params( + name = "all_test_params", + bzlmod_modes = [ + "enabled", + "disabled", + ], + oss = [ + "linux", + "macos", + ], + test_names = integration_test_utils.bazel_integration_test_names( + "updatesrc_test", + bazel_binaries.versions.all, + ), + visibility = ["//:__subpackages__"], +) diff --git a/tests/updatesrc_tests/workspace/.bazelrc b/tests/updatesrc_tests/workspace/.bazelrc index 4e2b1ed9..d95ba88d 100644 --- a/tests/updatesrc_tests/workspace/.bazelrc +++ b/tests/updatesrc_tests/workspace/.bazelrc @@ -7,4 +7,6 @@ import %workspace%/../../../ci.bazelrc # Try to import a local.rc file; typically, written by CI try-import %workspace%/../../../local.bazelrc - +# Try to load parameters for the child workspace(s). These configuration values +# should not be loaded by the parent workspace. +try-import %workspace%/../../../child_workspace.bazelrc