From 52644d869165f6571c0f6760a886090afaf97bc3 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Fri, 21 Jul 2023 12:55:11 -0600 Subject: [PATCH 01/37] Updated cmd/go_deps to reference the github-markdown-toc.go and kingpin.v2. --- go_deps.bzl | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/go_deps.bzl b/go_deps.bzl index c69768f4..f94e638b 100644 --- a/go_deps.bzl +++ b/go_deps.bzl @@ -39,8 +39,8 @@ def bazel_starlib_go_dependencies(): name = "com_github_alecthomas_units", build_external = "external", importpath = "github.com/alecthomas/units", - sum = "h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=", - version = "v0.0.0-20151022065526-2efee857e7cf", + sum = "h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc=", + version = "v0.0.0-20211218093645-b94a6e3cc137", ) go_repository( name = "com_github_davecgh_go_spew", @@ -79,20 +79,58 @@ def bazel_starlib_go_dependencies(): version = "v1.2.0", ) + go_repository( + name = "com_github_stretchr_objx", + build_external = "external", + importpath = "github.com/stretchr/objx", + sum = "h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=", + version = "v0.1.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:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=", + version = "v1.8.2", + ) + + go_repository( + name = "com_github_xhit_go_str2duration_v2", + build_external = "external", + importpath = "github.com/xhit/go-str2duration/v2", + sum = "h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc=", + version = "v2.1.0", ) go_repository( name = "in_gopkg_alecthomas_kingpin_v2", build_external = "external", importpath = "gopkg.in/alecthomas/kingpin.v2", - sum = "h1:CC8tJ/xljioKrK6ii3IeWVXU4Tw7VB+LbjZBJaBxN50=", - version = "v2.2.4", + replace = "github.com/alecthomas/kingpin/v2", + sum = "h1:H0aULhgmSzN8xQ3nX1uxtdlTHYoPLu5AhHxWrKI6ocU=", + version = "v2.3.2", + ) + go_repository( + name = "in_gopkg_check_v1", + build_external = "external", + importpath = "gopkg.in/check.v1", + sum = "h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=", + version = "v0.0.0-20161208181325-20d25e280405", + ) + go_repository( + name = "in_gopkg_yaml_v2", + build_external = "external", + importpath = "gopkg.in/yaml.v2", + sum = "h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=", + version = "v2.2.2", + ) + go_repository( + name = "in_gopkg_yaml_v3", + build_external = "external", + importpath = "gopkg.in/yaml.v3", + sum = "h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=", + version = "v3.0.1", ) go_repository( name = "in_gopkg_check_v1", From 10b05664c0fe80a1c2d3998bdc249cc20cfb1b63 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Fri, 21 Jul 2023 13:11:08 -0600 Subject: [PATCH 02/37] Ran tidy --- go_deps.bzl | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/go_deps.bzl b/go_deps.bzl index f94e638b..a1865bc4 100644 --- a/go_deps.bzl +++ b/go_deps.bzl @@ -39,8 +39,8 @@ def bazel_starlib_go_dependencies(): name = "com_github_alecthomas_units", build_external = "external", importpath = "github.com/alecthomas/units", - sum = "h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc=", - version = "v0.0.0-20211218093645-b94a6e3cc137", + sum = "h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=", + version = "v0.0.0-20151022065526-2efee857e7cf", ) go_repository( name = "com_github_davecgh_go_spew", @@ -107,9 +107,8 @@ def bazel_starlib_go_dependencies(): name = "in_gopkg_alecthomas_kingpin_v2", build_external = "external", importpath = "gopkg.in/alecthomas/kingpin.v2", - replace = "github.com/alecthomas/kingpin/v2", - sum = "h1:H0aULhgmSzN8xQ3nX1uxtdlTHYoPLu5AhHxWrKI6ocU=", - version = "v2.3.2", + sum = "h1:CC8tJ/xljioKrK6ii3IeWVXU4Tw7VB+LbjZBJaBxN50=", + version = "v2.2.4", ) go_repository( name = "in_gopkg_check_v1", @@ -118,13 +117,7 @@ def bazel_starlib_go_dependencies(): sum = "h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=", version = "v0.0.0-20161208181325-20d25e280405", ) - go_repository( - name = "in_gopkg_yaml_v2", - build_external = "external", - importpath = "gopkg.in/yaml.v2", - sum = "h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=", - version = "v2.2.2", - ) + go_repository( name = "in_gopkg_yaml_v3", build_external = "external", From 0a4a660d15b46d3540288c2bbf84c1372be2559a Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Fri, 21 Jul 2023 13:29:49 -0600 Subject: [PATCH 03/37] Brought over the ci workflow rules and tools --- .github/actions/execute_test/action.yml | 24 +++ BUILD.bazel | 1 + MODULE.bazel | 3 + ci/BUILD.bazel | 22 +++ ci/defs.bzl | 27 +++ ci/internal/BUILD.bazel | 56 ++++++ ci/internal/bzlmod_modes.bzl | 19 ++ ci/internal/ci_integration_test_params.bzl | 62 ++++++ ci/internal/ci_test_params.bzl | 49 +++++ ci/internal/ci_test_params_suite.bzl | 20 ++ ci/internal/ci_workflow.bzl | 91 +++++++++ ci/internal/providers.bzl | 10 + ci/tests/BUILD.bazel | 9 + ci/tests/bzlmod_modes_tests.bzl | 35 ++++ ci/tests/ci_test_params_tests.bzl | 130 ++++++++++++ ci/tools/generate_ci_workflow/BUILD.bazel | 22 +++ .../internal/github/BUILD.bazel | 25 +++ .../internal/github/workflow.go | 130 ++++++++++++ .../internal/github/workflow_test.go | 185 ++++++++++++++++++ .../internal/testparams/BUILD.bazel | 20 ++ .../internal/testparams/int_test_params.go | 42 ++++ .../testparams/int_test_params_test.go | 26 +++ ci/tools/generate_ci_workflow/main.go | 125 ++++++++++++ go.mod | 5 +- go.sum | 7 +- go_deps.bzl | 18 ++ 26 files changed, 1161 insertions(+), 2 deletions(-) create mode 100644 .github/actions/execute_test/action.yml create mode 100644 ci/BUILD.bazel create mode 100644 ci/defs.bzl create mode 100644 ci/internal/BUILD.bazel create mode 100644 ci/internal/bzlmod_modes.bzl create mode 100644 ci/internal/ci_integration_test_params.bzl create mode 100644 ci/internal/ci_test_params.bzl create mode 100644 ci/internal/ci_test_params_suite.bzl create mode 100644 ci/internal/ci_workflow.bzl create mode 100644 ci/internal/providers.bzl create mode 100644 ci/tests/BUILD.bazel create mode 100644 ci/tests/bzlmod_modes_tests.bzl create mode 100644 ci/tests/ci_test_params_tests.bzl create mode 100644 ci/tools/generate_ci_workflow/BUILD.bazel create mode 100644 ci/tools/generate_ci_workflow/internal/github/BUILD.bazel create mode 100644 ci/tools/generate_ci_workflow/internal/github/workflow.go create mode 100644 ci/tools/generate_ci_workflow/internal/github/workflow_test.go create mode 100644 ci/tools/generate_ci_workflow/internal/testparams/BUILD.bazel create mode 100644 ci/tools/generate_ci_workflow/internal/testparams/int_test_params.go create mode 100644 ci/tools/generate_ci_workflow/internal/testparams/int_test_params_test.go create mode 100644 ci/tools/generate_ci_workflow/main.go diff --git a/.github/actions/execute_test/action.yml b/.github/actions/execute_test/action.yml new file mode 100644 index 00000000..0ab3822d --- /dev/null +++ b/.github/actions/execute_test/action.yml @@ -0,0 +1,24 @@ +name: Execute Test + +inputs: + test_target: + description: The test target to execute. + required: true + bzlmod_enabled: + description: Boolean value that specifies whether bzlmod should be enabled. + required: true + +runs: + using: composite + steps: + - name: Execute Test + shell: bash + env: + TEST_TARGET: ${{ inputs.test_target }} + BZLMOD_ENABLED: ${{ inputs.bzlmod_enabled }} + run: | + if [[ "${BZLMOD_ENABLED}" == "false" ]] && [[ "${TEST_TARGET}" =~ ^@@ ]]; then + # Strip the first @ from test target + TEST_TARGET="${TEST_TARGET#@}" + fi + bazelisk test "${TEST_TARGET}" diff --git a/BUILD.bazel b/BUILD.bazel index 13728a8a..2cbf6e90 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -20,6 +20,7 @@ gazelle_binary( ) # gazelle:prefix github.com/cgrindel/bazel-starlib +# gazelle:go_naming_convention import gazelle( name = "update_build_files", gazelle = ":gazelle_bin", diff --git a/MODULE.bazel b/MODULE.bazel index 0f4a1906..3709e597 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -32,8 +32,11 @@ go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps") go_deps.from_file(go_mod = "//:go.mod") use_repo( go_deps, + "com_github_creasty_defaults", "com_github_ekalinin_github_markdown_toc_go", + "com_github_stretchr_testify", "in_gopkg_alecthomas_kingpin_v2", + "in_gopkg_yaml_v3", ) # MARK: - Dev Dependencies diff --git a/ci/BUILD.bazel b/ci/BUILD.bazel new file mode 100644 index 00000000..76d4ab6b --- /dev/null +++ b/ci/BUILD.bazel @@ -0,0 +1,22 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") + +bzlformat_pkg(name = "bzlformat") + +bzl_library( + name = "defs", + srcs = ["defs.bzl"], + visibility = ["//visibility:public"], + deps = [ + "//ci/internal:bzlmod_modes", + "//ci/internal:ci_integration_test_params", + "//ci/internal:ci_workflow", + "//ci/internal:providers", + ], +) + +filegroup( + name = "all_files", + srcs = glob(["*"]), + visibility = ["//:__subpackages__"], +) diff --git a/ci/defs.bzl b/ci/defs.bzl new file mode 100644 index 00000000..2bfc56e2 --- /dev/null +++ b/ci/defs.bzl @@ -0,0 +1,27 @@ +"""Public API for CI workflow generation.""" + +load("//ci/internal:bzlmod_modes.bzl", _bzlmod_modes = "bzlmod_modes") +load( + "//ci/internal:ci_integration_test_params.bzl", + _ci_integration_test_params = "ci_integration_test_params", +) +load( + "//ci/internal:ci_test_params_suite.bzl", + _ci_test_params_suite = "ci_test_params_suite", +) +load("//ci/internal:ci_workflow.bzl", _ci_workflow = "ci_workflow") +load( + "//ci/internal:providers.bzl", + _CITestParamsInfo = "CITestParamsInfo", +) + +# Modules +bzlmod_modes = _bzlmod_modes + +# Rules +ci_integration_test_params = _ci_integration_test_params +ci_workflow = _ci_workflow +ci_test_params_suite = _ci_test_params_suite + +# Providers +CITestParamsInfo = _CITestParamsInfo diff --git a/ci/internal/BUILD.bazel b/ci/internal/BUILD.bazel new file mode 100644 index 00000000..f12f5a7e --- /dev/null +++ b/ci/internal/BUILD.bazel @@ -0,0 +1,56 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") + +bzlformat_pkg(name = "bzlformat") + +bzl_library( + name = "ci_integration_test_params", + srcs = ["ci_integration_test_params.bzl"], + visibility = ["//visibility:public"], + deps = [":providers"], +) + +bzl_library( + name = "ci_workflow", + srcs = ["ci_workflow.bzl"], + visibility = ["//visibility:public"], + deps = [ + ":providers", + "@cgrindel_bazel_starlib//updatesrc:defs", + ], +) + +bzl_library( + name = "ci_test_params", + srcs = ["ci_test_params.bzl"], + visibility = ["//ci:__subpackages__"], + deps = [":providers"], +) + +bzl_library( + name = "ci_test_params_suite", + srcs = ["ci_test_params_suite.bzl"], + visibility = ["//ci:__subpackages__"], + deps = [ + ":ci_test_params", + ":providers", + ], +) + +filegroup( + name = "all_files", + srcs = glob(["*"]), + visibility = ["//:__subpackages__"], +) + +bzl_library( + name = "bzlmod_modes", + srcs = ["bzlmod_modes.bzl"], + visibility = ["//ci:__subpackages__"], +) + +bzl_library( + name = "providers", + srcs = ["providers.bzl"], + visibility = ["//ci:__subpackages__"], +) diff --git a/ci/internal/bzlmod_modes.bzl b/ci/internal/bzlmod_modes.bzl new file mode 100644 index 00000000..effd462c --- /dev/null +++ b/ci/internal/bzlmod_modes.bzl @@ -0,0 +1,19 @@ +"""Module for converting bzlmod mode values.""" + +def _to_bool(bzlmod_mode): + if bzlmod_mode == "enabled": + return True + elif bzlmod_mode == "disabled": + return False + fail("Unrecognized bzlmod_mode: {}".format(bzlmod_mode)) + +def _from_bool(enable_bzlmod): + if enable_bzlmod: + return "enabled" + else: + return "disabled" + +bzlmod_modes = struct( + to_bool = _to_bool, + from_bool = _from_bool, +) diff --git a/ci/internal/ci_integration_test_params.bzl b/ci/internal/ci_integration_test_params.bzl new file mode 100644 index 00000000..84647d04 --- /dev/null +++ b/ci/internal/ci_integration_test_params.bzl @@ -0,0 +1,62 @@ +"""Implementation for the `ci_integration_test_params` rule.""" + +load(":ci_test_params.bzl", "ci_test_params") +load(":providers.bzl", "CITestParamsInfo") + +def _ci_integration_test_params_impl(ctx): + workspace_name = ctx.label.workspace_name + package = ctx.label.package + test_names = [ + name.removeprefix(":") + for name in ctx.attr.test_names + ] + test_labels = [ + Label("@{workspace}//{pkg}:{name}".format( + workspace = workspace_name, + pkg = package, + name = name, + )) + for name in test_names + ] + itps = [] + for test_label in test_labels: + for os in ctx.attr.oss: + for bzlmod_mode in ctx.attr.bzlmod_modes: + itp = ci_test_params.new_integration_test_params( + test = test_label, + os = os, + bzlmod_mode = bzlmod_mode, + ) + itps.append(itp) + return [ + CITestParamsInfo( + integration_test_params = depset(itps), + ), + ] + +ci_integration_test_params = rule( + implementation = _ci_integration_test_params_impl, + attrs = { + "bzlmod_modes": attr.string_list( + default = ["enabled"], + doc = "Accepted values: `enabled`, `disabled`.", + ), + "oss": attr.string_list( + default = ["macos", "linux"], + doc = "Accepted values: `macos`, `linux`.", + ), + # This cannot be a label_list, because the labels are tests. It would + # require that this rule and any rules that use this rule would need to + # be testonly = True. The workflow CI mechanism requires that the + # output be "buildable". + "test_names": attr.string_list( + mandatory = True, + doc = """\ +A list of the test names in this package that should use these parameters.\ +""", + ), + }, + doc = """\ +Describe how one or more integration tests should be executed in CI.\ +""", +) diff --git a/ci/internal/ci_test_params.bzl b/ci/internal/ci_test_params.bzl new file mode 100644 index 00000000..b1c150f8 --- /dev/null +++ b/ci/internal/ci_test_params.bzl @@ -0,0 +1,49 @@ +"""Module for creating test parameters.""" + +load(":providers.bzl", "CITestParamsInfo") + +def _label_str(label): + # Because we support running with bzlmod enabled and disabled, we need to + # normalize the target value that is stored. We have chosen to use the + # bzlmod version. + result = str(label) + if result.startswith("@@"): + pass + elif result.startswith("@"): + result = "@{}".format(result) + else: + result = "@@{}".format(result) + return result + +def _new_integration_test_params(test, os, bzlmod_mode): + return struct( + test = _label_str(test), + os = os, + bzlmod_mode = bzlmod_mode, + ) + +def _collect_from_deps(deps): + itp_depsets = [] + for dep in deps: + if CITestParamsInfo in dep: + itp_depsets.append(dep[CITestParamsInfo].integration_test_params) + return CITestParamsInfo( + integration_test_params = depset([], transitive = itp_depsets), + ) + +def _sort_integration_test_params(itps): + return sorted( + itps, + key = lambda itp: "{test}_{os}_{bzlmod_mode}".format( + test = itp.test, + os = itp.os, + bzlmod_mode = itp.bzlmod_mode, + ), + ) + +ci_test_params = struct( + label_str = _label_str, + new_integration_test_params = _new_integration_test_params, + collect_from_deps = _collect_from_deps, + sort_integration_test_params = _sort_integration_test_params, +) diff --git a/ci/internal/ci_test_params_suite.bzl b/ci/internal/ci_test_params_suite.bzl new file mode 100644 index 00000000..efbad786 --- /dev/null +++ b/ci/internal/ci_test_params_suite.bzl @@ -0,0 +1,20 @@ +"""Implementation for `ci_test_params_suite` rule.""" + +load(":ci_test_params.bzl", "ci_test_params") +load(":providers.bzl", "CITestParamsInfo") + +def _ci_test_params_suite_impl(ctx): + tp_info = ci_test_params.collect_from_deps(ctx.attr.test_params) + return [tp_info] + +ci_test_params_suite = rule( + implementation = _ci_test_params_suite_impl, + attrs = { + "test_params": attr.label_list( + mandatory = True, + providers = [[CITestParamsInfo]], + doc = "The test params that should be collected.", + ), + }, + doc = "Collect the test parameters to pass along as a single target.", +) diff --git a/ci/internal/ci_workflow.bzl b/ci/internal/ci_workflow.bzl new file mode 100644 index 00000000..25cd45d7 --- /dev/null +++ b/ci/internal/ci_workflow.bzl @@ -0,0 +1,91 @@ +"""Implementation for the `ci_workflow` rule.""" + +load("@cgrindel_bazel_starlib//updatesrc:defs.bzl", "updatesrc_diff_and_update") +load(":ci_test_params.bzl", "ci_test_params") +load(":providers.bzl", "CITestParamsInfo") + +def _ci_workflow_impl(ctx): + tp_info = ci_test_params.collect_from_deps(ctx.attr.test_params) + itps = ci_test_params.sort_integration_test_params( + tp_info.integration_test_params.to_list(), + ) + + # Generate JSON describing all of the integration tests + json_file = ctx.actions.declare_file("{}_int_test_params.json".format(ctx.label.name)) + json_str = json.encode_indent(itps) + ctx.actions.write(json_file, json_str) + + # Generate the CI workflow + workflow_out = ctx.actions.declare_file("{}.yml".format(ctx.label.name)) + args = ctx.actions.args() + args.add("-template", ctx.file.template) + args.add("-int_test_params_json", json_file) + args.add("-output", workflow_out) + + ctx.actions.run( + outputs = [workflow_out], + inputs = [json_file, ctx.file.template], + executable = ctx.executable._workflow_generator, + arguments = [args], + ) + + return [ + DefaultInfo(files = depset([workflow_out])), + ] + +_ci_workflow = rule( + implementation = _ci_workflow_impl, + attrs = { + "template": attr.label( + allow_single_file = [".yml", ".yaml"], + mandatory = True, + doc = "The current worklfow yaml file.", + ), + "test_params": attr.label_list( + mandatory = True, + providers = [[CITestParamsInfo]], + doc = "The test parameters.", + ), + "_workflow_generator": attr.label( + default = Label("//tools/generate_ci_workflow"), + allow_files = True, + executable = True, + cfg = "exec", + ), + }, + doc = """\ +Generate a GitHub workflow file with jobs for each of the integration test \ +parameter permutations.\ +""", +) + +def ci_workflow(name, workflow_yml, test_params, **kwargs): + """Generates a GitHub workflow file with jobs for each of the listed \ + integration test parameter permutations. + + In addition to building the worklfow YAML file, it also defines a target + that compares the generated file with the version in the source tree. If + they do not match, the test will fail. This macro also provides a runnable + target for updating the source tree with the generated workflow file. + + Args: + name: The name of the build target as a `string`. + workflow_yml: The path to the GitHub workflow file in the source tree. + This can be a `string` or a `Label`. + test_params: A `sequence` of labels that provide + `CITestParamsInfo` (e.g., `ci_integration_test_params`). + **kwargs: Common attributes that are passed to the build target. + + Returns: + """ + _ci_workflow( + name = name, + template = workflow_yml, + test_params = test_params, + **kwargs + ) + updatesrc_diff_and_update( + name = "update_" + name, + srcs = [workflow_yml], + outs = [name], + ) diff --git a/ci/internal/providers.bzl b/ci/internal/providers.bzl new file mode 100644 index 00000000..fd121cee --- /dev/null +++ b/ci/internal/providers.bzl @@ -0,0 +1,10 @@ +"""Provider definitions for the GitHub CI workflow generation.""" + +CITestParamsInfo = provider( + doc = "Collects the test parameters for running CI tests.", + fields = { + "integration_test_params": """\ +A `depset` of `struct` values as created by `ci_test_params.new_integration_test_params`.\ +""", + }, +) diff --git a/ci/tests/BUILD.bazel b/ci/tests/BUILD.bazel new file mode 100644 index 00000000..a8a8c2ec --- /dev/null +++ b/ci/tests/BUILD.bazel @@ -0,0 +1,9 @@ +load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") +load(":bzlmod_modes_tests.bzl", "bzlmod_modes_test_suite") +load(":ci_test_params_tests.bzl", "ci_test_params_test_suite") + +bzlformat_pkg(name = "bzlformat") + +bzlmod_modes_test_suite() + +ci_test_params_test_suite() diff --git a/ci/tests/bzlmod_modes_tests.bzl b/ci/tests/bzlmod_modes_tests.bzl new file mode 100644 index 00000000..af4249f3 --- /dev/null +++ b/ci/tests/bzlmod_modes_tests.bzl @@ -0,0 +1,35 @@ +"""Tests for `bzlmod_modes` module.""" + +load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") +load("//ci/internal:bzlmod_modes.bzl", "bzlmod_modes") + +def _bool_conversion_test(ctx): + env = unittest.begin(ctx) + + tests = [ + struct( + msg = "enabled", + mode = "enabled", + bool = True, + ), + struct( + msg = "disabled", + mode = "disabled", + bool = False, + ), + ] + for t in tests: + actual_bool = bzlmod_modes.to_bool(t.mode) + asserts.equals(env, t.bool, actual_bool, t.msg) + actual_mode = bzlmod_modes.from_bool(t.bool) + asserts.equals(env, t.mode, actual_mode, t.msg) + + return unittest.end(env) + +bool_conversion_test = unittest.make(_bool_conversion_test) + +def bzlmod_modes_test_suite(name = "bzlmod_modes_tests"): + return unittest.suite( + name, + bool_conversion_test, + ) diff --git a/ci/tests/ci_test_params_tests.bzl b/ci/tests/ci_test_params_tests.bzl new file mode 100644 index 00000000..e54bc33d --- /dev/null +++ b/ci/tests/ci_test_params_tests.bzl @@ -0,0 +1,130 @@ +"""Tests for `ci_test_params` module.""" + +load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") +load("//ci/internal:ci_test_params.bzl", "ci_test_params") +load("//ci/internal:providers.bzl", "CITestParamsInfo") + +def _sort_integration_test_params_test(ctx): + env = unittest.begin(ctx) + + itps = [ + ci_test_params.new_integration_test_params( + test = "//:zebra", + os = "macos", + bzlmod_mode = "enabled", + ), + ci_test_params.new_integration_test_params( + test = "//:zebra", + os = "macos", + bzlmod_mode = "disabled", + ), + ci_test_params.new_integration_test_params( + test = "//:apple", + os = "macos", + bzlmod_mode = "enabled", + ), + ] + expected = [ + ci_test_params.new_integration_test_params( + test = "//:apple", + os = "macos", + bzlmod_mode = "enabled", + ), + ci_test_params.new_integration_test_params( + test = "//:zebra", + os = "macos", + bzlmod_mode = "disabled", + ), + ci_test_params.new_integration_test_params( + test = "//:zebra", + os = "macos", + bzlmod_mode = "enabled", + ), + ] + actual = ci_test_params.sort_integration_test_params(itps) + asserts.equals(env, expected, actual) + + return unittest.end(env) + +sort_integration_test_params_test = unittest.make(_sort_integration_test_params_test) + +def _collect_from_deps_test(ctx): + env = unittest.begin(ctx) + + deps = [ + {CITestParamsInfo: CITestParamsInfo( + integration_test_params = depset([ + ci_test_params.new_integration_test_params( + test = "//:zebra", + os = "macos", + bzlmod_mode = "enabled", + ), + ]), + )}, + {CITestParamsInfo: CITestParamsInfo( + integration_test_params = depset([ + ci_test_params.new_integration_test_params( + test = "//:apple", + os = "linux", + bzlmod_mode = "disabled", + ), + ]), + )}, + ] + actual = ci_test_params.collect_from_deps(deps) + actual_itps = ci_test_params.sort_integration_test_params( + actual.integration_test_params.to_list(), + ) + expected_itps = [ + ci_test_params.new_integration_test_params( + test = "//:apple", + os = "linux", + bzlmod_mode = "disabled", + ), + ci_test_params.new_integration_test_params( + test = "//:zebra", + os = "macos", + bzlmod_mode = "enabled", + ), + ] + asserts.equals(env, expected_itps, actual_itps) + + return unittest.end(env) + +collect_from_deps_test = unittest.make(_collect_from_deps_test) + +def _label_str_test(ctx): + env = unittest.begin(ctx) + + tests = [ + struct( + msg = "bzlmod label", + inp = "@@//foo:bar", + exp = "@@//foo:bar", + ), + struct( + msg = "old-style label", + inp = "@//foo:bar", + exp = "@@//foo:bar", + ), + struct( + msg = "no prefix", + inp = "//foo:bar", + exp = "@@//foo:bar", + ), + ] + for t in tests: + actual = ci_test_params.label_str(t.inp) + asserts.equals(env, t.exp, actual, t.msg) + + return unittest.end(env) + +label_str_test = unittest.make(_label_str_test) + +def ci_test_params_test_suite(name = "ci_test_params_tests"): + return unittest.suite( + name, + sort_integration_test_params_test, + collect_from_deps_test, + label_str_test, + ) diff --git a/ci/tools/generate_ci_workflow/BUILD.bazel b/ci/tools/generate_ci_workflow/BUILD.bazel new file mode 100644 index 00000000..1aa7cbd4 --- /dev/null +++ b/ci/tools/generate_ci_workflow/BUILD.bazel @@ -0,0 +1,22 @@ +load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") + +bzlformat_pkg(name = "bzlformat") + +go_library( + name = "generate_ci_workflow_lib", + srcs = ["main.go"], + importpath = "github.com/cgrindel/bazel-starlib/ci/tools/generate_ci_workflow", + visibility = ["//visibility:private"], + deps = [ + "//ci/tools/generate_ci_workflow/internal/github", + "//ci/tools/generate_ci_workflow/internal/testparams", + "@in_gopkg_yaml_v3//:yaml_v3", + ], +) + +go_binary( + name = "generate_ci_workflow", + embed = [":generate_ci_workflow_lib"], + visibility = ["//visibility:public"], +) diff --git a/ci/tools/generate_ci_workflow/internal/github/BUILD.bazel b/ci/tools/generate_ci_workflow/internal/github/BUILD.bazel new file mode 100644 index 00000000..5ef417a4 --- /dev/null +++ b/ci/tools/generate_ci_workflow/internal/github/BUILD.bazel @@ -0,0 +1,25 @@ +load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +go_library( + name = "github", + srcs = ["workflow.go"], + importpath = "github.com/cgrindel/bazel-starlib/ci/tools/generate_ci_workflow/internal/github", + visibility = ["//ci/tools/generate_ci_workflow:__subpackages__"], + deps = [ + "@com_github_creasty_defaults//:defaults", + "@in_gopkg_yaml_v3//:yaml_v3", + ], +) + +go_test( + name = "github_test", + srcs = ["workflow_test.go"], + deps = [ + ":github", + "@com_github_stretchr_testify//assert", + "@in_gopkg_yaml_v3//:yaml_v3", + ], +) + +bzlformat_pkg(name = "bzlformat") diff --git a/ci/tools/generate_ci_workflow/internal/github/workflow.go b/ci/tools/generate_ci_workflow/internal/github/workflow.go new file mode 100644 index 00000000..dfef49a1 --- /dev/null +++ b/ci/tools/generate_ci_workflow/internal/github/workflow.go @@ -0,0 +1,130 @@ +package github + +import ( + "github.com/creasty/defaults" + "gopkg.in/yaml.v3" +) + +// Workflow is a GitHub Actions workflow +type Workflow struct { + Name string `yaml:"name"` + On WorkflowTriggers `yaml:"on"` + Concurrecny Concurrency `yaml:"concurrency"` + Jobs map[string]Job `yaml:"jobs" default:"{}"` +} + +// NewWorkflowFromYAML returns a new workflow from YAML bytes. +func NewWorkflowFromYAML(b []byte) (*Workflow, error) { + var workflow Workflow + if err := defaults.Set(&workflow); err != nil { + return nil, err + } + if err := yaml.Unmarshal(b, &workflow); err != nil { + return nil, err + } + return &workflow, nil +} + +// WorkflowTriggers represents the triggers for a workflow. +type WorkflowTriggers struct { + PullRequest PullRequestEvent `yaml:"pull_request"` + Schedule []Schedule `yaml:"schedule,omitempty"` +} + +// PullRequestEvent is a trigger event. +type PullRequestEvent struct { + Branches []string `yaml:"branches,omitempty"` +} + +// Schedule is the cron schedule for a workflow. +type Schedule struct { + Cron string `yaml:"cron"` +} + +// Concurrency describes how concurrent workflows should be handled. +type Concurrency struct { + Group string `yaml:"group"` + CancelInProgress bool `yaml:"cancel-in-progress"` +} + +// Job describes a GitHub actions workflow job. +type Job struct { + Strategy Strategy `yaml:"strategy,omitempty"` + RunsOn string `yaml:"runs-on"` + Needs []string `yaml:"needs,omitempty"` + If string `yaml:"if,omitempty"` + Env map[string]string `yaml:"env,omitempty"` + Steps []Step `yaml:"steps"` +} + +// UnmarshalYAML applies custom logic for the unmarshalling of a job from YAML. +func (j *Job) UnmarshalYAML(node *yaml.Node) error { + // Need to set defaults on Job, because they are stored in a map. The Strategy defaults will not + // be set unless we do it from here. + if err := defaults.Set(j); err != nil { + return nil + } + // Define a type so that we can unmarshal into the struct without a recursion error. + type fake Job + if err := node.Decode((*fake)(j)); err != nil { + return err + } + return nil +} + +// Step is a step in a job. +type Step struct { + Uses string `yaml:"uses,omitempty"` + If string `yaml:"if,omitempty"` + With map[string]string `yaml:"with,omitempty"` + Name string `yaml:"name,omitempty"` + Shell string `yaml:"shell,omitempty"` + Run string `yaml:"run,omitempty"` +} + +// Strategy describes execution parameter matrix for a job. +type Strategy struct { + FailFast FailFast `yaml:"fail-fast,omitempty" default:"true"` + Matrix SBMatrixStrategy `yaml:"matrix,omitempty"` +} + +// UnmarshalYAML applies custom logic for the unmarshalling of a strategy from YAML. +func (s *Strategy) UnmarshalYAML(node *yaml.Node) error { + // Set defaults on Strategy + if err := defaults.Set(s); err != nil { + return nil + } + // Define a type so that we can unmarshal into the struct without a recursion error. + type fake Strategy + if err := node.Decode((*fake)(s)); err != nil { + return err + } + return nil +} + +// FailFast represents the fail-fast boolean. +type FailFast bool + +// IsZero determines whether the boolean is in a "zero" state. +func (ff FailFast) IsZero() bool { + // The FailFast defaults to true + return bool(ff) +} + +// SBMatrixStrategy is the job execution matrix. +type SBMatrixStrategy struct { + Example []string `yaml:"example,omitempty"` + BazelVersion []string `yaml:"bazel_version,omitempty"` + Runner []string `yaml:"runner,omitempty"` + EnableBzlmod []bool `yaml:"enable_bzlmod,omitempty"` + Include []SBMatrixInclude `yaml:"include,omitempty"` +} + +// SBMatrixInclude is the include for the job execution matrix. +type SBMatrixInclude struct { + Example string `yaml:"example,omitempty"` + BazelVersion string `yaml:"bazel_version,omitempty"` + Test string `yaml:"test"` + Runner string `yaml:"runner"` + EnableBzlmod bool `yaml:"enable_bzlmod"` +} diff --git a/ci/tools/generate_ci_workflow/internal/github/workflow_test.go b/ci/tools/generate_ci_workflow/internal/github/workflow_test.go new file mode 100644 index 00000000..4a584e2d --- /dev/null +++ b/ci/tools/generate_ci_workflow/internal/github/workflow_test.go @@ -0,0 +1,185 @@ +package github_test + +import ( + "testing" + + "github.com/cgrindel/bazel-starlib/ci/tools/generate_ci_workflow/internal/github" + "github.com/stretchr/testify/assert" + "gopkg.in/yaml.v3" +) + +func TestFailFast(t *testing.T) { + t.Run("is zero", func(t *testing.T) { + tests := []struct { + msg string + in github.FailFast + exp bool + }{ + {msg: "true", in: github.FailFast(true), exp: true}, + {msg: "false", in: github.FailFast(false), exp: false}, + } + for _, tt := range tests { + actual := tt.in.IsZero() + assert.Equal(t, tt.exp, actual, tt.msg) + } + }) +} + +func TestStrategy(t *testing.T) { + t.Run("decode YAML", func(t *testing.T) { + tests := []struct { + msg string + in string + exp github.Strategy + }{ + { + msg: "without fail-fast", + in: ` +matrix: +`, + exp: github.Strategy{FailFast: true}, + }, + { + msg: "with fail-fast false", + in: ` +fail-fast: false +matrix: +`, + exp: github.Strategy{FailFast: false}, + }, + { + msg: "with fail-fast true", + in: ` +fail-fast: true +matrix: +`, + exp: github.Strategy{FailFast: true}, + }, + } + for _, tt := range tests { + var actual github.Strategy + err := yaml.Unmarshal([]byte(tt.in), &actual) + assert.NoError(t, err) + assert.Equal(t, tt.exp, actual, tt.msg) + } + }) +} + +func TestNewWorkflowFromYAML(t *testing.T) { + workflow, err := github.NewWorkflowFromYAML([]byte(workflowYAML)) + assert.NoError(t, err) + assert.Equal(t, "Continuous Integration", workflow.Name) + + // Example with strategy + macosIntTestMatrix, ok := workflow.Jobs["macos_int_test_matrix"] + assert.True(t, ok, "`macos_int_test_matrix` job was not found") + assert.True(t, bool(macosIntTestMatrix.Strategy.FailFast), + "expected strategy fail-fast to default to true") + + // Example with no strategy + macosTidyAndTest, ok := workflow.Jobs["macos_tidy_and_test"] + assert.True(t, ok, "`macos_tidy_and_test` job was not found") + assert.True(t, bool(macosTidyAndTest.Strategy.FailFast), + "expected strategy fail-fast to default to true") +} + +const workflowYAML = ` +name: Continuous Integration + +on: + pull_request: + branches: [ main ] + schedule: + # Every day at 11:14 UTC. + - cron: '14 11 * * *' + +jobs: + + macos_tidy_and_test: + runs-on: macos-12 + steps: + - uses: actions/checkout@v3 + - uses: ./.github/actions/set_up_macos + with: + xcode_version: '14.0.1' + repo_name: bazel-starlib + - name: Ensure everything is tidy + shell: bash + run: | + bazelisk run //:tidy_check + - name: Execute Tests + shell: bash + run: | + bazelisk test //... + + macos_int_test_matrix: + strategy: + matrix: + example: [] + bazel_version: [] + include: [] + runs-on: macos-12 + steps: + - uses: actions/checkout@v3 + - uses: ./.github/actions/set_up_macos + with: + xcode_version: '14.0.1' + repo_name: bazel-starlib + - uses: ./.github/actions/test_example + with: + example_name: ${{ matrix.example }} + bazel_version: ${{ matrix.bazel_version }} + + ubuntu_tidy_and_test: + runs-on: ubuntu-22.04 + env: + CC: clang + steps: + - uses: actions/checkout@v3 + - uses: ./.github/actions/set_up_ubuntu + with: + repo_name: bazel-starlib + ubuntu_version: "22.04" + - name: Ensure everything is tidy + shell: bash + run: | + bazelisk run //:tidy_check + - name: Execute Tests + shell: bash + run: | + bazelisk test //... + + ubuntu_int_test_matrix: + strategy: + matrix: + example: [] + bazel_version: [] + include: [] + runs-on: ubuntu-22.04 + env: + CC: clang + steps: + - uses: actions/checkout@v3 + - uses: ./.github/actions/set_up_ubuntu + with: + repo_name: bazel-starlib + ubuntu_version: "22.04" + - uses: ./.github/actions/test_example + with: + example_name: ${{ matrix.example }} + bazel_version: ${{ matrix.bazel_version }} + + all_ci_tests: + runs-on: ubuntu-20.04 + needs: + - macos_tidy_and_test + - macos_int_test_matrix + - ubuntu_tidy_and_test + - ubuntu_int_test_matrix + if: ${{ always() }} + steps: + - uses: cgrindel/gha_join_jobs@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + +` diff --git a/ci/tools/generate_ci_workflow/internal/testparams/BUILD.bazel b/ci/tools/generate_ci_workflow/internal/testparams/BUILD.bazel new file mode 100644 index 00000000..255316cd --- /dev/null +++ b/ci/tools/generate_ci_workflow/internal/testparams/BUILD.bazel @@ -0,0 +1,20 @@ +load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg") +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +bzlformat_pkg(name = "bzlformat") + +go_library( + name = "testparams", + srcs = ["int_test_params.go"], + importpath = "github.com/cgrindel/bazel-starlib/ci/tools/generate_ci_workflow/internal/testparams", + visibility = ["//ci/tools/generate_ci_workflow:__subpackages__"], +) + +go_test( + name = "testparams_test", + srcs = ["int_test_params_test.go"], + deps = [ + ":testparams", + "@com_github_stretchr_testify//assert", + ], +) diff --git a/ci/tools/generate_ci_workflow/internal/testparams/int_test_params.go b/ci/tools/generate_ci_workflow/internal/testparams/int_test_params.go new file mode 100644 index 00000000..82a345c7 --- /dev/null +++ b/ci/tools/generate_ci_workflow/internal/testparams/int_test_params.go @@ -0,0 +1,42 @@ +package testparams + +import "encoding/json" + +const MacOS = "macos" +const LinuxOS = "linux" + +type IntTestParams struct { + Test string `json:"test"` + OS string `json:"os"` + BzlmodMode string `json:"bzlmod_mode"` +} + +func (itp *IntTestParams) EnableBzlmod() bool { + switch itp.BzlmodMode { + case "enabled": + return true + case "disabled": + return false + default: + return false + } +} + +func (itp *IntTestParams) Runner() string { + switch itp.OS { + case MacOS: + return "macos-13" + case LinuxOS: + return "ubuntu-22.04" + default: + return "" + } +} + +func NewIntTestParamsFromJSON(b []byte) ([]IntTestParams, error) { + var intTestParams []IntTestParams + if err := json.Unmarshal(b, &intTestParams); err != nil { + return nil, err + } + return intTestParams, nil +} diff --git a/ci/tools/generate_ci_workflow/internal/testparams/int_test_params_test.go b/ci/tools/generate_ci_workflow/internal/testparams/int_test_params_test.go new file mode 100644 index 00000000..d4c413a8 --- /dev/null +++ b/ci/tools/generate_ci_workflow/internal/testparams/int_test_params_test.go @@ -0,0 +1,26 @@ +package testparams_test + +import ( + "testing" + + "github.com/cgrindel/bazel-starlib/ci/tools/generate_ci_workflow/internal/testparams" + "github.com/stretchr/testify/assert" +) + +func TestNewIntTestParamsFromJSON(t *testing.T) { + actual, err := testparams.NewIntTestParamsFromJSON([]byte(intTestParamsJSON)) + assert.NoError(t, err) + assert.Len(t, actual, 2) + expected := []testparams.IntTestParams{ + {Test: "@@//path:int_test", OS: "macos", BzlmodMode: "enabled"}, + {Test: "@@//path:int_test", OS: "linux", BzlmodMode: "disabled"}, + } + assert.Equal(t, expected, actual) +} + +const intTestParamsJSON = ` +[ + {"test": "@@//path:int_test", "os": "macos", "bzlmod_mode": "enabled"}, + {"test": "@@//path:int_test", "os": "linux", "bzlmod_mode": "disabled"} +] +` diff --git a/ci/tools/generate_ci_workflow/main.go b/ci/tools/generate_ci_workflow/main.go new file mode 100644 index 00000000..06987123 --- /dev/null +++ b/ci/tools/generate_ci_workflow/main.go @@ -0,0 +1,125 @@ +package main + +import ( + "bytes" + "context" + "flag" + "fmt" + "os" + "os/signal" + + "github.com/cgrindel/bazel-starlib/ci/tools/generate_ci_workflow/internal/github" + "github.com/cgrindel/bazel-starlib/ci/tools/generate_ci_workflow/internal/testparams" + "gopkg.in/yaml.v3" +) + +const intTestMatrixKey = "integration_test_matrix" + +func main() { + ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) + defer cancel() + if err := run(ctx, os.Stderr); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +} + +func run(ctx context.Context, stderr *os.File) error { + var ( + templatePath string + intTestParamsJSONPath string + outputPath string + ) + flag.StringVar(&templatePath, "template", "", "path to the template file") + flag.StringVar(&intTestParamsJSONPath, "int_test_params_json", "", "path to the test params JSON file") + flag.StringVar(&outputPath, "output", "", "path to the output file") + flag.Usage = func() { + fmt.Fprint(flag.CommandLine.Output(), `usage: bazel run //tools/generate_ci_workflow -- -template -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/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 a1865bc4..7edf34ea 100644 --- a/go_deps.bzl +++ b/go_deps.bzl @@ -42,6 +42,15 @@ 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", @@ -49,6 +58,7 @@ def bazel_starlib_go_dependencies(): sum = "h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=", version = "v1.1.1", ) + go_repository( name = "com_github_ekalinin_github_markdown_toc_go", build_external = "external", @@ -78,6 +88,13 @@ 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_objx", @@ -125,6 +142,7 @@ def bazel_starlib_go_dependencies(): sum = "h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=", version = "v3.0.1", ) + go_repository( name = "in_gopkg_check_v1", build_external = "external", From 383f36b6205caec2c8a55fb3c10daa7850d337c8 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Fri, 21 Jul 2023 13:50:00 -0600 Subject: [PATCH 04/37] Update with bare bones ci.yml --- .github/workflows/ci.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ffcc2bba..f32117ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,38 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} + integration_test_matrix: + strategy: + fail-fast: false + matrix: + include: [] + runs-on: ${{ matrix.runner }} + env: + CC: clang + steps: + - uses: actions/checkout@v3 + - uses: ./.github/actions/set_up_ubuntu + if: ${{ startsWith(matrix.runner, 'ubuntu') }} + with: + repo_name: bazel-starlib + ubuntu_version: "22.04" + - uses: ./.github/actions/set_up_macos + if: ${{ startsWith(matrix.runner, 'macos') }} + with: + repo_name: rules_swift_package_manager + xcode_version: "14.2" + - uses: ./.github/actions/configure_bzlmod + with: + enabled: ${{ matrix.enable_bzlmod }} + - uses: ./.github/actions/configure_remote_cache_auth + with: + buildbuddy_api_key: ${{ secrets.BUILDBUDDY_API_KEY }} + - uses: ./.github/actions/execute_test + with: + bzlmod_enabled: ${{ matrix.bzlmod_enabled }} + test_target: ${{ matrix.test }} + + integration_test_matrix: strategy: fail-fast: false From 3e348eef4a4f3603e8c73453f947d6195cc60b26 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Fri, 21 Jul 2023 13:53:13 -0600 Subject: [PATCH 05/37] Add concurrency to ci.yml --- .github/workflows/ci.yml | 68 +++++++++------------------------------- 1 file changed, 14 insertions(+), 54 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f32117ca..f47de5e7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,10 @@ on: # Every day at 11:13 UTC. - cron: '13 11 * * *' +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + jobs: tidy_and_test_matrix: @@ -41,16 +45,16 @@ jobs: CC: clang steps: - uses: actions/checkout@v3 - - uses: ./.github/actions/set_up_ubuntu - if: ${{ startsWith(matrix.runner, 'ubuntu') }} - with: - repo_name: bazel-starlib - ubuntu_version: "22.04" - - uses: ./.github/actions/set_up_macos - if: ${{ startsWith(matrix.runner, 'macos') }} - with: - repo_name: rules_swift_package_manager - xcode_version: "14.2" + # - uses: ./.github/actions/set_up_ubuntu + # if: ${{ startsWith(matrix.runner, 'ubuntu') }} + # with: + # repo_name: bazel-starlib + # ubuntu_version: "22.04" + # - uses: ./.github/actions/set_up_macos + # if: ${{ startsWith(matrix.runner, 'macos') }} + # with: + # repo_name: rules_swift_package_manager + # xcode_version: "14.2" - uses: ./.github/actions/configure_bzlmod with: enabled: ${{ matrix.enable_bzlmod }} @@ -63,50 +67,6 @@ jobs: test_target: ${{ matrix.test }} - integration_test_matrix: - strategy: - fail-fast: false - matrix: - runner: [macos-13, ubuntu-22.04] - bazel_version: [.bazelversion] - example_dir: [bzlformat, markdown, updatesrc] - enable_bzlmod: [true, false] - include: - - example_dir: bzlformat - example_name: simple - - example_dir: markdown - example_name: simple - - example_dir: updatesrc - example_name: simple - - runner: macos-13 - example_dir: "" - example_name: bzlmod_e2e - enable_bzlmod: true - bazel_version: .bazelversion - - runner: ubuntu-22.04 - example_dir: "" - example_name: bzlmod_e2e - enable_bzlmod: true - bazel_version: .bazelversion - runs-on: ${{ matrix.runner }} - steps: - - uses: actions/checkout@v3 - - uses: cgrindel/gha_set_up_bazel@v1 - with: - repo_name: bazel-starlib - - uses: ./.github/actions/configure_bzlmod - with: - enabled: ${{ matrix.enable_bzlmod }} - - uses: ./.github/actions/configure_remote_cache_auth - with: - buildbuddy_api_key: ${{ secrets.BUILDBUDDY_API_KEY }} - - uses: ./.github/actions/test_example - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - example_dir: ${{ matrix.example_dir }} - example_name: ${{ matrix.example_name }} - bazel_version: ${{ matrix.bazel_version }} - all_ci_tests: runs-on: ubuntu-22.04 needs: From 9881bad888d0809184185eae0bbfe07b35ab701e Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Fri, 21 Jul 2023 13:54:42 -0600 Subject: [PATCH 06/37] Added examples/bzlformat/simple to ci workflow generation --- .github/workflows/ci.yml | 116 +++++++++++++++++++-------------- BUILD.bazel | 9 +++ ci/internal/ci_workflow.bzl | 2 +- examples/bzlformat/BUILD.bazel | 18 +++++ 4 files changed, 95 insertions(+), 50 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f47de5e7..c3743b5c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,60 +1,65 @@ +# 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. name: Continuous Integration - -on: +"on": pull_request: - branches: [ main, test_main ] + branches: + - main + - test_main schedule: - # Every day at 11:13 UTC. - - cron: '13 11 * * *' - + - cron: 13 11 * * * concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true - jobs: - - tidy_and_test_matrix: - strategy: - fail-fast: false - matrix: - runner: [macos-13, ubuntu-22.04] - enable_bzlmod: [true, false] - runs-on: ${{ matrix.runner }} + all_ci_tests: + runs-on: ubuntu-22.04 + needs: + - tidy_and_test_matrix + - integration_test_matrix + if: ${{ always() }} steps: - - uses: actions/checkout@v3 - - uses: cgrindel/gha_set_up_bazel@v1 - with: - repo_name: bazel-starlib - - uses: ./.github/actions/configure_bzlmod - with: - enabled: ${{ matrix.enable_bzlmod }} - - uses: ./.github/actions/configure_remote_cache_auth - with: - buildbuddy_api_key: ${{ secrets.BUILDBUDDY_API_KEY }} - - uses: ./.github/actions/tidy_and_test - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - + - uses: cgrindel/gha_join_jobs@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} integration_test_matrix: strategy: fail-fast: false matrix: - include: [] + include: + - test: '@@//examples/bzlformat:simple_test_bazel_.bazelversion' + runner: ubuntu-22.04 + enable_bzlmod: false + - test: '@@//examples/bzlformat:simple_test_bazel_.bazelversion' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//examples/bzlformat:simple_test_bazel_.bazelversion' + runner: macos-13 + enable_bzlmod: false + - test: '@@//examples/bzlformat:simple_test_bazel_.bazelversion' + runner: macos-13 + enable_bzlmod: true + - test: '@@//examples/bzlformat:simple_test_bazel_7_0_0-pre_20230215_2' + runner: ubuntu-22.04 + enable_bzlmod: false + - test: '@@//examples/bzlformat:simple_test_bazel_7_0_0-pre_20230215_2' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//examples/bzlformat:simple_test_bazel_7_0_0-pre_20230215_2' + runner: macos-13 + enable_bzlmod: false + - test: '@@//examples/bzlformat:simple_test_bazel_7_0_0-pre_20230215_2' + runner: macos-13 + enable_bzlmod: true runs-on: ${{ matrix.runner }} env: CC: clang steps: - uses: actions/checkout@v3 - # - uses: ./.github/actions/set_up_ubuntu - # if: ${{ startsWith(matrix.runner, 'ubuntu') }} - # with: - # repo_name: bazel-starlib - # ubuntu_version: "22.04" - # - uses: ./.github/actions/set_up_macos - # if: ${{ startsWith(matrix.runner, 'macos') }} - # with: - # repo_name: rules_swift_package_manager - # xcode_version: "14.2" - uses: ./.github/actions/configure_bzlmod with: enabled: ${{ matrix.enable_bzlmod }} @@ -65,15 +70,28 @@ jobs: with: bzlmod_enabled: ${{ matrix.bzlmod_enabled }} test_target: ${{ matrix.test }} - - - all_ci_tests: - runs-on: ubuntu-22.04 - needs: - - tidy_and_test_matrix - - integration_test_matrix - if: ${{ always() }} + tidy_and_test_matrix: + strategy: + fail-fast: false + matrix: + runner: + - macos-13 + - ubuntu-22.04 + enable_bzlmod: + - true + - false + runs-on: ${{ matrix.runner }} steps: - - uses: cgrindel/gha_join_jobs@v1 + - uses: actions/checkout@v3 + - uses: cgrindel/gha_set_up_bazel@v1 + with: + repo_name: bazel-starlib + - uses: ./.github/actions/configure_bzlmod + with: + enabled: ${{ matrix.enable_bzlmod }} + - uses: ./.github/actions/configure_remote_cache_auth + with: + buildbuddy_api_key: ${{ secrets.BUILDBUDDY_API_KEY }} + - uses: ./.github/actions/tidy_and_test with: github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/BUILD.bazel b/BUILD.bazel index 2cbf6e90..07505b0c 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -6,6 +6,7 @@ load( "bzlformat_pkg", ) load("//bzltidy:defs.bzl", "tidy", "tidy_all") +load("//ci:defs.bzl", "ci_workflow") load("//shlib/rules:execute_binary.bzl", "execute_binary") load("//tests:integration_test_common.bzl", "INTEGRATION_TEST_TAGS") load("//updatesrc:defs.bzl", "updatesrc_update_all") @@ -235,6 +236,14 @@ test_suite( visibility = ["//:__subpackages__"], ) +ci_workflow( + name = "ci_workflow", + test_params = [ + "//examples/bzlformat:simple_test_params", + ], + workflow_yml = ".github/workflows/ci.yml", +) + bzl_library( name = "deps", srcs = ["deps.bzl"], diff --git a/ci/internal/ci_workflow.bzl b/ci/internal/ci_workflow.bzl index 25cd45d7..394c4f6f 100644 --- a/ci/internal/ci_workflow.bzl +++ b/ci/internal/ci_workflow.bzl @@ -47,7 +47,7 @@ _ci_workflow = rule( doc = "The test parameters.", ), "_workflow_generator": attr.label( - default = Label("//tools/generate_ci_workflow"), + default = Label("//ci/tools/generate_ci_workflow"), allow_files = True, executable = True, cfg = "exec", diff --git a/examples/bzlformat/BUILD.bazel b/examples/bzlformat/BUILD.bazel index 37a62197..df933aae 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") @@ -74,3 +75,20 @@ 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__"], +) From e045cdbbc926f9a003858cc5ab2d5ec6cd61a1e2 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Fri, 21 Jul 2023 14:26:59 -0600 Subject: [PATCH 07/37] Added examples:all_test_params to ci workflow --- .github/workflows/ci.yml | 12 ++++++++ BUILD.bazel | 1 + examples/BUILD.bazel | 61 +++++++++++++++++++++++++++++++--------- examples/examples.bzl | 25 ++++++++++++++++ 4 files changed, 86 insertions(+), 13 deletions(-) create mode 100644 examples/examples.bzl diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c3743b5c..13f3ef7b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,6 +55,18 @@ jobs: - test: '@@//examples/bzlformat:simple_test_bazel_7_0_0-pre_20230215_2' runner: macos-13 enable_bzlmod: true + - test: '@@//examples:bzlmod_e2e_test_bazel_.bazelversion' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//examples:bzlmod_e2e_test_bazel_.bazelversion' + runner: macos-13 + enable_bzlmod: true + - test: '@@//examples:bzlmod_e2e_test_bazel_7_0_0-pre_20230215_2' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//examples:bzlmod_e2e_test_bazel_7_0_0-pre_20230215_2' + runner: macos-13 + enable_bzlmod: true runs-on: ${{ matrix.runner }} env: CC: clang diff --git a/BUILD.bazel b/BUILD.bazel index 07505b0c..5cdf59c5 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -240,6 +240,7 @@ ci_workflow( name = "ci_workflow", test_params = [ "//examples/bzlformat:simple_test_params", + "//examples:all_test_params", ], workflow_yml = ".github/workflows/ci.yml", ) diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel index dd5f6cca..12cf517a 100644 --- a/examples/BUILD.bazel +++ b/examples/BUILD.bazel @@ -7,6 +7,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,38 +17,71 @@ 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__"], ) @@ -56,10 +91,10 @@ test_suite( 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__"], ) 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, +) From 50e6468b45fd8411cd3b13b42fa83d37ce47bc8e Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Fri, 21 Jul 2023 14:31:41 -0600 Subject: [PATCH 08/37] Add markdown examples --- .github/workflows/ci.yml | 24 ++++++++++++++++++++++++ BUILD.bazel | 1 + examples/markdown/BUILD.bazel | 18 ++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13f3ef7b..b4ae51cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,6 +55,30 @@ jobs: - test: '@@//examples/bzlformat:simple_test_bazel_7_0_0-pre_20230215_2' runner: macos-13 enable_bzlmod: true + - test: '@@//examples/markdown:simple_test_bazel_.bazelversion' + runner: ubuntu-22.04 + enable_bzlmod: false + - test: '@@//examples/markdown:simple_test_bazel_.bazelversion' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//examples/markdown:simple_test_bazel_.bazelversion' + runner: macos-13 + enable_bzlmod: false + - test: '@@//examples/markdown:simple_test_bazel_.bazelversion' + runner: macos-13 + enable_bzlmod: true + - test: '@@//examples/markdown:simple_test_bazel_7_0_0-pre_20230215_2' + runner: ubuntu-22.04 + enable_bzlmod: false + - test: '@@//examples/markdown:simple_test_bazel_7_0_0-pre_20230215_2' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//examples/markdown:simple_test_bazel_7_0_0-pre_20230215_2' + runner: macos-13 + enable_bzlmod: false + - test: '@@//examples/markdown:simple_test_bazel_7_0_0-pre_20230215_2' + runner: macos-13 + enable_bzlmod: true - test: '@@//examples:bzlmod_e2e_test_bazel_.bazelversion' runner: ubuntu-22.04 enable_bzlmod: true diff --git a/BUILD.bazel b/BUILD.bazel index 5cdf59c5..440a6a32 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -240,6 +240,7 @@ ci_workflow( name = "ci_workflow", test_params = [ "//examples/bzlformat:simple_test_params", + "//examples/markdown:simple_test_params", "//examples:all_test_params", ], workflow_yml = ".github/workflows/ci.yml", diff --git a/examples/markdown/BUILD.bazel b/examples/markdown/BUILD.bazel index edb3a210..ae2d8431 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") @@ -98,3 +99,20 @@ 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__"], +) From 6da204dd3aec3f08c57fca6e48ebe19705e5969b Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Fri, 21 Jul 2023 14:37:30 -0600 Subject: [PATCH 09/37] Add updatesrc --- .github/workflows/ci.yml | 24 ++++++++++++++++++++++++ BUILD.bazel | 5 ++++- examples/updatesrc/BUILD.bazel | 18 ++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b4ae51cf..bb2ee217 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,6 +79,30 @@ jobs: - test: '@@//examples/markdown:simple_test_bazel_7_0_0-pre_20230215_2' runner: macos-13 enable_bzlmod: true + - test: '@@//examples/updatesrc:simple_test_bazel_.bazelversion' + runner: ubuntu-22.04 + enable_bzlmod: false + - test: '@@//examples/updatesrc:simple_test_bazel_.bazelversion' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//examples/updatesrc:simple_test_bazel_.bazelversion' + runner: macos-13 + enable_bzlmod: false + - test: '@@//examples/updatesrc:simple_test_bazel_.bazelversion' + runner: macos-13 + enable_bzlmod: true + - test: '@@//examples/updatesrc:simple_test_bazel_7_0_0-pre_20230215_2' + runner: ubuntu-22.04 + enable_bzlmod: false + - test: '@@//examples/updatesrc:simple_test_bazel_7_0_0-pre_20230215_2' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//examples/updatesrc:simple_test_bazel_7_0_0-pre_20230215_2' + runner: macos-13 + enable_bzlmod: false + - test: '@@//examples/updatesrc:simple_test_bazel_7_0_0-pre_20230215_2' + runner: macos-13 + enable_bzlmod: true - test: '@@//examples:bzlmod_e2e_test_bazel_.bazelversion' runner: ubuntu-22.04 enable_bzlmod: true diff --git a/BUILD.bazel b/BUILD.bazel index 440a6a32..c7338fce 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -238,10 +238,13 @@ test_suite( ci_workflow( name = "ci_workflow", + # This list should have a ci_integration_test_params for each of the + # labels in the all_integration_tests list. test_params = [ + "//examples:all_test_params", "//examples/bzlformat:simple_test_params", "//examples/markdown:simple_test_params", - "//examples:all_test_params", + "//examples/updatesrc:simple_test_params", ], workflow_yml = ".github/workflows/ci.yml", ) diff --git a/examples/updatesrc/BUILD.bazel b/examples/updatesrc/BUILD.bazel index 90d92369..064d63ad 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") @@ -67,3 +68,20 @@ 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__"], +) From af466797ced3900df738f32297b9f40105bae1b9 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Fri, 21 Jul 2023 14:41:11 -0600 Subject: [PATCH 10/37] Add missing_pkgs_tests --- .github/workflows/ci.yml | 12 +++++++++++ BUILD.bazel | 1 + .../missing_pkgs_tests/BUILD.bazel | 21 +++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bb2ee217..d7f5e338 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -115,6 +115,18 @@ jobs: - test: '@@//examples:bzlmod_e2e_test_bazel_7_0_0-pre_20230215_2' runner: macos-13 enable_bzlmod: true + - test: '@@//tests/bzlformat_tests/tools_tests/missing_pkgs_tests:missing_pkgs_test_bazel_.bazelversion' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//tests/bzlformat_tests/tools_tests/missing_pkgs_tests:missing_pkgs_test_bazel_.bazelversion' + runner: macos-13 + enable_bzlmod: true + - test: '@@//tests/bzlformat_tests/tools_tests/missing_pkgs_tests:missing_pkgs_test_bazel_7_0_0-pre_20230215_2' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//tests/bzlformat_tests/tools_tests/missing_pkgs_tests:missing_pkgs_test_bazel_7_0_0-pre_20230215_2' + runner: macos-13 + enable_bzlmod: true runs-on: ${{ matrix.runner }} env: CC: clang diff --git a/BUILD.bazel b/BUILD.bazel index c7338fce..3a3cceb7 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -245,6 +245,7 @@ ci_workflow( "//examples/bzlformat:simple_test_params", "//examples/markdown:simple_test_params", "//examples/updatesrc:simple_test_params", + "//tests/bzlformat_tests/tools_tests/missing_pkgs_tests:all_test_params", ], workflow_yml = ".github/workflows/ci.yml", ) 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..7bde5136 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") @@ -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__"], +) From 4ce495fb4c2bca84e085cf88afbf1023d4cd0394 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Fri, 21 Jul 2023 15:30:34 -0600 Subject: [PATCH 11/37] Refactor integration tests to follow naming pattern --- .github/workflows/ci.yml | 66 +++++++++++++++++++ BUILD.bazel | 49 +++++++------- examples/BUILD.bazel | 2 +- examples/bzlformat/BUILD.bazel | 8 ++- examples/markdown/BUILD.bazel | 8 ++- examples/updatesrc/BUILD.bazel | 8 ++- .../missing_pkgs_tests/BUILD.bazel | 2 +- tests/bzlrelease_tests/BUILD.bazel | 16 ----- .../generate_release_notes_tests/BUILD.bazel | 18 ++++- .../BUILD.bazel | 24 ++++++- .../update_readme_tests/BUILD.bazel | 24 ++++++- .../bzlrelease_tests/tools_tests/BUILD.bazel | 23 ++++++- tests/bzltidy_tests/BUILD.bazel | 17 ++++- .../lib_tests/git_tests/BUILD.bazel | 18 ++++- .../lib_tests/github_tests/BUILD.bazel | 21 +++++- tests/updatesrc_tests/BUILD.bazel | 20 +++++- 16 files changed, 268 insertions(+), 56 deletions(-) delete mode 100644 tests/bzlrelease_tests/BUILD.bazel diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d7f5e338..361fe9b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -127,6 +127,72 @@ jobs: - test: '@@//tests/bzlformat_tests/tools_tests/missing_pkgs_tests:missing_pkgs_test_bazel_7_0_0-pre_20230215_2' runner: macos-13 enable_bzlmod: true + - test: '@@//tests/bzlrelease_tests/rules_tests/generate_release_notes_tests:generate_release_notes_test' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//tests/bzlrelease_tests/rules_tests/generate_workspace_snippet_tests:generate_workspace_snippet_test' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//tests/bzlrelease_tests/rules_tests/update_readme_tests:update_readme_test' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//tests/bzlrelease_tests/tools_tests:generate_gh_changelog_test' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//tests/bzlrelease_tests/tools_tests:generate_git_archive_test' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//tests/bzlrelease_tests/tools_tests:generate_release_notes_test' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//tests/bzlrelease_tests/tools_tests:generate_workspace_snippet_test' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//tests/bzltidy_tests:tidy_all_test_bazel_.bazelversion' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//tests/bzltidy_tests:tidy_all_test_bazel_.bazelversion' + runner: macos-13 + enable_bzlmod: true + - test: '@@//tests/bzltidy_tests:tidy_all_test_bazel_7_0_0-pre_20230215_2' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//tests/bzltidy_tests:tidy_all_test_bazel_7_0_0-pre_20230215_2' + runner: macos-13 + enable_bzlmod: true + - test: '@@//tests/shlib_tests/lib_tests/git_tests:git_integration_test' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//tests/shlib_tests/lib_tests/github_tests:get_gh_auth_status_test' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//tests/shlib_tests/lib_tests/github_tests:get_gh_changelog_test' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//tests/updatesrc_tests:updatesrc_test_bazel_.bazelversion' + runner: ubuntu-22.04 + enable_bzlmod: false + - test: '@@//tests/updatesrc_tests:updatesrc_test_bazel_.bazelversion' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//tests/updatesrc_tests:updatesrc_test_bazel_.bazelversion' + runner: macos-13 + enable_bzlmod: false + - test: '@@//tests/updatesrc_tests:updatesrc_test_bazel_.bazelversion' + runner: macos-13 + enable_bzlmod: true + - test: '@@//tests/updatesrc_tests:updatesrc_test_bazel_7_0_0-pre_20230215_2' + runner: ubuntu-22.04 + enable_bzlmod: false + - test: '@@//tests/updatesrc_tests:updatesrc_test_bazel_7_0_0-pre_20230215_2' + runner: ubuntu-22.04 + enable_bzlmod: true + - test: '@@//tests/updatesrc_tests:updatesrc_test_bazel_7_0_0-pre_20230215_2' + runner: macos-13 + enable_bzlmod: false + - test: '@@//tests/updatesrc_tests:updatesrc_test_bazel_7_0_0-pre_20230215_2' + runner: macos-13 + enable_bzlmod: true runs-on: ${{ matrix.runner }} env: CC: clang diff --git a/BUILD.bazel b/BUILD.bazel index 3a3cceb7..aa7602ed 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -200,20 +200,28 @@ filegroup( visibility = [":integration_test_visibility"], ) +_INTEGRATION_TEST_PKGS = [ + "//examples", + "//examples/bzlformat", + "//examples/markdown", + "//examples/updatesrc", + "//tests/bzlformat_tests/tools_tests/missing_pkgs_tests", + "//tests/bzlrelease_tests/rules_tests/generate_release_notes_tests", + "//tests/bzlrelease_tests/rules_tests/generate_workspace_snippet_tests", + "//tests/bzlrelease_tests/rules_tests/update_readme_tests", + "//tests/bzlrelease_tests/tools_tests", + "//tests/bzltidy_tests", + "//tests/shlib_tests/lib_tests/git_tests", + "//tests/shlib_tests/lib_tests/github_tests", + "//tests/updatesrc_tests", +] + test_suite( name = "all_smoke_integration_tests", tags = INTEGRATION_TEST_TAGS, tests = [ - "//examples:smoke_integration_tests", - "//examples/bzlformat:smoke_integration_tests", - "//examples/markdown:smoke_integration_tests", - "//examples/updatesrc:smoke_integration_tests", - "//tests/bzlformat_tests/tools_tests/missing_pkgs_tests:smoke_integration_tests", - "//tests/bzlrelease_tests:all_integration_tests", - "//tests/bzltidy_tests:smoke_integration_tests", - "//tests/shlib_tests/lib_tests/git_tests:integration_tests", - "//tests/shlib_tests/lib_tests/github_tests:integration_tests", - "//tests/updatesrc_tests:smoke_integration_tests", + "{}:smoke_integration_tests".format(pkg) + for pkg in _INTEGRATION_TEST_PKGS ], visibility = ["//:__subpackages__"], ) @@ -222,30 +230,17 @@ test_suite( name = "all_integration_tests", tags = INTEGRATION_TEST_TAGS, tests = [ - "//examples:integration_tests", - "//examples/bzlformat:integration_tests", - "//examples/markdown:integration_tests", - "//examples/updatesrc:integration_tests", - "//tests/bzlformat_tests/tools_tests/missing_pkgs_tests:integration_tests", - "//tests/bzlrelease_tests:all_integration_tests", - "//tests/bzltidy_tests:integration_tests", - "//tests/shlib_tests/lib_tests/git_tests:integration_tests", - "//tests/shlib_tests/lib_tests/github_tests:integration_tests", - "//tests/updatesrc_tests:integration_tests", + "{}:all_integration_tests".format(pkg) + for pkg in _INTEGRATION_TEST_PKGS ], visibility = ["//:__subpackages__"], ) ci_workflow( name = "ci_workflow", - # This list should have a ci_integration_test_params for each of the - # labels in the all_integration_tests list. test_params = [ - "//examples:all_test_params", - "//examples/bzlformat:simple_test_params", - "//examples/markdown:simple_test_params", - "//examples/updatesrc:simple_test_params", - "//tests/bzlformat_tests/tools_tests/missing_pkgs_tests:all_test_params", + "{}:all_test_params".format(pkg) + for pkg in _INTEGRATION_TEST_PKGS ], workflow_yml = ".github/workflows/ci.yml", ) diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel index 12cf517a..70536538 100644 --- a/examples/BUILD.bazel +++ b/examples/BUILD.bazel @@ -87,7 +87,7 @@ test_suite( ) 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( diff --git a/examples/bzlformat/BUILD.bazel b/examples/bzlformat/BUILD.bazel index df933aae..b38c731c 100644 --- a/examples/bzlformat/BUILD.bazel +++ b/examples/bzlformat/BUILD.bazel @@ -67,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", @@ -92,3 +92,9 @@ ci_integration_test_params( ), visibility = ["//:__subpackages__"], ) + +alias( + name = "all_test_params", + actual = ":simple_test_params", + visibility = ["//:__subpackages__"], +) diff --git a/examples/markdown/BUILD.bazel b/examples/markdown/BUILD.bazel index ae2d8431..d0a5c295 100644 --- a/examples/markdown/BUILD.bazel +++ b/examples/markdown/BUILD.bazel @@ -91,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", @@ -116,3 +116,9 @@ ci_integration_test_params( ), visibility = ["//:__subpackages__"], ) + +alias( + name = "all_test_params", + actual = ":simple_test_params", + visibility = ["//:__subpackages__"], +) diff --git a/examples/updatesrc/BUILD.bazel b/examples/updatesrc/BUILD.bazel index 064d63ad..323b0165 100644 --- a/examples/updatesrc/BUILD.bazel +++ b/examples/updatesrc/BUILD.bazel @@ -60,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", @@ -85,3 +85,9 @@ ci_integration_test_params( ), visibility = ["//:__subpackages__"], ) + +alias( + name = "all_test_params", + actual = ":simple_test_params", + visibility = ["//:__subpackages__"], +) 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 7bde5136..322e020d 100644 --- a/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/BUILD.bazel +++ b/tests/bzlformat_tests/tools_tests/missing_pkgs_tests/BUILD.bazel @@ -56,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", 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..5adaabb4 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") @@ -53,10 +54,25 @@ sh_test( ) test_suite( - name = "integration_tests", + name = "all_integration_tests", tags = INTEGRATION_TEST_TAGS, tests = [ ":generate_release_notes_test", ], visibility = ["//:__subpackages__"], ) + +alias( + name = "smoke_integration_tests", + actual = ":all_integration_tests", + visibility = ["//:__subpackages__"], +) + +ci_integration_test_params( + name = "all_test_params", + bzlmod_modes = ["enabled"], + # We only run this on linux. + oss = ["linux"], + test_names = ["generate_release_notes_test"], + 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..ffc740e5 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") @@ -58,10 +59,31 @@ sh_test( ) test_suite( - name = "integration_tests", + name = "all_integration_tests", tags = INTEGRATION_TEST_TAGS, tests = [ ":generate_workspace_snippet_test", ], visibility = ["//:__subpackages__"], ) + +alias( + name = "smoke_integration_tests", + actual = ":all_integration_tests", + 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 = ["generate_workspace_snippet_test"], + 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..3de11e1d 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") @@ -41,10 +42,31 @@ sh_test( ) test_suite( - name = "integration_tests", + name = "all_integration_tests", tags = INTEGRATION_TEST_TAGS, tests = [ ":update_readme_test", ], visibility = ["//:__subpackages__"], ) + +alias( + name = "smoke_integration_tests", + actual = ":all_integration_tests", + visibility = ["//:__subpackages__"], +) + +ci_integration_test_params( + name = "update_readme_test_params", + bzlmod_modes = ["enabled"], + # We only run this on linux. + oss = ["linux"], + test_names = ["update_readme_test"], + visibility = ["//:__subpackages__"], +) + +alias( + name = "all_test_params", + actual = ":update_readme_test_params", + visibility = ["//:__subpackages__"], +) diff --git a/tests/bzlrelease_tests/tools_tests/BUILD.bazel b/tests/bzlrelease_tests/tools_tests/BUILD.bazel index 53100f15..e75c22f0 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") @@ -107,7 +108,7 @@ sh_test( ) test_suite( - name = "integration_tests", + name = "all_integration_tests", tags = INTEGRATION_TEST_TAGS, tests = [ ":generate_gh_changelog_test", @@ -117,3 +118,23 @@ test_suite( ], visibility = ["//:__subpackages__"], ) + +alias( + name = "smoke_integration_tests", + actual = ":all_integration_tests", + visibility = ["//:__subpackages__"], +) + +ci_integration_test_params( + name = "all_test_params", + bzlmod_modes = ["enabled"], + # We only run this on linux. + oss = ["linux"], + test_names = [ + "generate_gh_changelog_test", + "generate_git_archive_test", + "generate_release_notes_test", + "generate_workspace_snippet_test", + ], + visibility = ["//:__subpackages__"], +) diff --git a/tests/bzltidy_tests/BUILD.bazel b/tests/bzltidy_tests/BUILD.bazel index 4212a3d1..0a77e920 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") @@ -54,7 +55,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 +63,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/shlib_tests/lib_tests/git_tests/BUILD.bazel b/tests/shlib_tests/lib_tests/git_tests/BUILD.bazel index 3f13fc4f..df4f6149 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") @@ -21,10 +22,25 @@ sh_test( ) test_suite( - name = "integration_tests", + name = "all_integration_tests", tags = INTEGRATION_TEST_TAGS, tests = [ ":git_integration_test", ], visibility = ["//:__subpackages__"], ) + +alias( + name = "smoke_integration_tests", + actual = ":all_integration_tests", + 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..4325165a 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") @@ -93,7 +94,7 @@ sh_test( ) test_suite( - name = "integration_tests", + name = "all_integration_tests", tags = INTEGRATION_TEST_TAGS, tests = [ ":get_gh_auth_status_test", @@ -101,3 +102,21 @@ test_suite( ], visibility = ["//:__subpackages__"], ) + +alias( + name = "smoke_integration_tests", + actual = ":all_integration_tests", + visibility = ["//:__subpackages__"], +) + +ci_integration_test_params( + name = "all_test_params", + bzlmod_modes = ["enabled"], + # We only run this on linux. + oss = ["linux"], + test_names = [ + "get_gh_auth_status_test", + "get_gh_changelog_test", + ], + 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__"], +) From b80186dda389788be934f21163d29d4059f73f4a Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Fri, 21 Jul 2023 15:32:17 -0600 Subject: [PATCH 12/37] Remove test_example action --- .github/actions/test_example/action.yml | 39 ------------------------- 1 file changed, 39 deletions(-) delete mode 100644 .github/actions/test_example/action.yml diff --git a/.github/actions/test_example/action.yml b/.github/actions/test_example/action.yml deleted file mode 100644 index a41afcfb..00000000 --- a/.github/actions/test_example/action.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: Test Examples -description: Execute an example integration test. - -inputs: - github_token: - description: The Github token to authenticate gh CLI. - required: true - example_dir: - description: The directory under the examples. - rquired: true - example_name: - description: The name of the example. - required: true - bazel_version: - description: The Bazel version suffix (e.g. semver or .bazelversion) - required: true - -runs: - using: composite - steps: - - name: Execute Integration Test in Examples Subdirectory - if: inputs.example_dir != '' - shell: bash - env: - # The integration tests make use of Github-specific functionality - # (e.g. gh). - GITHUB_TOKEN: ${{ inputs.github_token }} - run: | - bazelisk test //examples/${{ inputs.example_dir }}:${{ inputs.example_name }}_test_bazel_${{ inputs.bazel_version }} - - name: Execute Integration Test in Examples Directory - if: inputs.example_dir == '' - shell: bash - env: - # The integration tests make use of Github-specific functionality - # (e.g. gh). - GITHUB_TOKEN: ${{ inputs.github_token }} - run: | - bazelisk test //examples:${{ inputs.example_name }}_test_bazel_${{ inputs.bazel_version }} - From 7d9bd24c6a5827390b16e1d8f5016bc6ad23e277 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Fri, 21 Jul 2023 15:46:01 -0600 Subject: [PATCH 13/37] Change name for root smoke_integration_tests. --- BUILD.bazel | 2 +- go_deps.bzl | 46 +++------------------------------------------- 2 files changed, 4 insertions(+), 44 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index aa7602ed..a4ea6c21 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -217,7 +217,7 @@ _INTEGRATION_TEST_PKGS = [ ] test_suite( - name = "all_smoke_integration_tests", + name = "smoke_integration_tests", tags = INTEGRATION_TEST_TAGS, tests = [ "{}:smoke_integration_tests".format(pkg) diff --git a/go_deps.bzl b/go_deps.bzl index 7edf34ea..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,7 +41,6 @@ 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", @@ -50,7 +48,6 @@ def bazel_starlib_go_dependencies(): sum = "h1:eNdqZvc5B509z18lD8yc212CAqJNvfT1Jq6L8WowdBA=", version = "v1.7.0", ) - go_repository( name = "com_github_davecgh_go_spew", build_external = "external", @@ -58,7 +55,6 @@ def bazel_starlib_go_dependencies(): sum = "h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=", version = "v1.1.1", ) - go_repository( name = "com_github_ekalinin_github_markdown_toc_go", build_external = "external", @@ -80,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", @@ -95,31 +90,13 @@ def bazel_starlib_go_dependencies(): sum = "h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=", version = "v0.5.0", ) - - go_repository( - name = "com_github_stretchr_objx", - build_external = "external", - importpath = "github.com/stretchr/objx", - sum = "h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=", - version = "v0.1.0", - ) - go_repository( name = "com_github_stretchr_testify", build_external = "external", importpath = "github.com/stretchr/testify", - sum = "h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=", - version = "v1.8.2", + sum = "h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=", + version = "v1.8.4", ) - - go_repository( - name = "com_github_xhit_go_str2duration_v2", - build_external = "external", - importpath = "github.com/xhit/go-str2duration/v2", - sum = "h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc=", - version = "v2.1.0", - ) - go_repository( name = "in_gopkg_alecthomas_kingpin_v2", build_external = "external", @@ -134,23 +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", - importpath = "gopkg.in/yaml.v3", - sum = "h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=", - version = "v3.0.1", - ) - - go_repository( - name = "in_gopkg_check_v1", - build_external = "external", - importpath = "gopkg.in/check.v1", - sum = "h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=", - version = "v0.0.0-20161208181325-20d25e280405", - ) - go_repository( name = "in_gopkg_yaml_v3", build_external = "external", From 30f53469993e63972a49b8a531f002e7fbd1ea09 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Fri, 21 Jul 2023 15:54:36 -0600 Subject: [PATCH 14/37] Replaced alias with test_suite --- .../generate_release_notes_tests/BUILD.bazel | 17 ++++++++--- .../BUILD.bazel | 17 ++++++++--- .../update_readme_tests/BUILD.bazel | 25 +++++++++-------- .../bzlrelease_tests/tools_tests/BUILD.bazel | 28 +++++++++++-------- .../lib_tests/git_tests/BUILD.bazel | 15 ++++++++-- .../lib_tests/github_tests/BUILD.bazel | 22 +++++++++------ 6 files changed, 82 insertions(+), 42 deletions(-) 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 5adaabb4..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 @@ -53,18 +53,27 @@ sh_test( ], ) +_TEST_NAMES = [ + "generate_release_notes_test", +] + test_suite( name = "all_integration_tests", tags = INTEGRATION_TEST_TAGS, tests = [ - ":generate_release_notes_test", + ":{}".format(name) + for name in _TEST_NAMES ], visibility = ["//:__subpackages__"], ) -alias( +test_suite( name = "smoke_integration_tests", - actual = ":all_integration_tests", + tags = INTEGRATION_TEST_TAGS, + tests = [ + ":{}".format(name) + for name in _TEST_NAMES + ], visibility = ["//:__subpackages__"], ) @@ -73,6 +82,6 @@ ci_integration_test_params( bzlmod_modes = ["enabled"], # We only run this on linux. oss = ["linux"], - test_names = ["generate_release_notes_test"], + 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 ffc740e5..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 @@ -58,18 +58,27 @@ sh_test( ], ) +_TEST_NAMES = [ + "generate_workspace_snippet_test", +] + test_suite( name = "all_integration_tests", tags = INTEGRATION_TEST_TAGS, tests = [ - ":generate_workspace_snippet_test", + ":{}".format(name) + for name in _TEST_NAMES ], visibility = ["//:__subpackages__"], ) -alias( +test_suite( name = "smoke_integration_tests", - actual = ":all_integration_tests", + tags = INTEGRATION_TEST_TAGS, + tests = [ + ":{}".format(name) + for name in _TEST_NAMES + ], visibility = ["//:__subpackages__"], ) @@ -78,7 +87,7 @@ ci_integration_test_params( bzlmod_modes = ["enabled"], # We only run this on linux. oss = ["linux"], - test_names = ["generate_workspace_snippet_test"], + test_names = _TEST_NAMES, 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 3de11e1d..12945e0d 100644 --- a/tests/bzlrelease_tests/rules_tests/update_readme_tests/BUILD.bazel +++ b/tests/bzlrelease_tests/rules_tests/update_readme_tests/BUILD.bazel @@ -41,32 +41,35 @@ sh_test( ], ) +_TEST_NAMES = [ + "update_readme_test", +] + test_suite( name = "all_integration_tests", tags = INTEGRATION_TEST_TAGS, tests = [ - ":update_readme_test", + ":{}".format(name) + for name in _TEST_NAMES ], visibility = ["//:__subpackages__"], ) -alias( +test_suite( name = "smoke_integration_tests", - actual = ":all_integration_tests", + tags = INTEGRATION_TEST_TAGS, + tests = [ + ":{}".format(name) + for name in _TEST_NAMES + ], visibility = ["//:__subpackages__"], ) ci_integration_test_params( - name = "update_readme_test_params", + name = "all_test_params", bzlmod_modes = ["enabled"], # We only run this on linux. oss = ["linux"], - test_names = ["update_readme_test"], - visibility = ["//:__subpackages__"], -) - -alias( - name = "all_test_params", - actual = ":update_readme_test_params", + 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 e75c22f0..a5d5e38d 100644 --- a/tests/bzlrelease_tests/tools_tests/BUILD.bazel +++ b/tests/bzlrelease_tests/tools_tests/BUILD.bazel @@ -107,21 +107,30 @@ sh_test( ], ) +_TEST_NAMES = [ + "generate_gh_changelog_test", + "generate_git_archive_test", + "generate_release_notes_test", + "generate_workspace_snippet_test", +] + test_suite( 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__"], ) -alias( +test_suite( name = "smoke_integration_tests", - actual = ":all_integration_tests", + tags = INTEGRATION_TEST_TAGS, + tests = [ + ":{}".format(name) + for name in _TEST_NAMES + ], visibility = ["//:__subpackages__"], ) @@ -130,11 +139,6 @@ ci_integration_test_params( bzlmod_modes = ["enabled"], # We only run this on linux. oss = ["linux"], - test_names = [ - "generate_gh_changelog_test", - "generate_git_archive_test", - "generate_release_notes_test", - "generate_workspace_snippet_test", - ], + test_names = _TEST_NAMES, visibility = ["//:__subpackages__"], ) diff --git a/tests/shlib_tests/lib_tests/git_tests/BUILD.bazel b/tests/shlib_tests/lib_tests/git_tests/BUILD.bazel index df4f6149..5b243100 100644 --- a/tests/shlib_tests/lib_tests/git_tests/BUILD.bazel +++ b/tests/shlib_tests/lib_tests/git_tests/BUILD.bazel @@ -21,18 +21,27 @@ sh_test( ], ) +_TEST_NAMES = [ + "git_integration_test", +] + test_suite( name = "all_integration_tests", tags = INTEGRATION_TEST_TAGS, tests = [ - ":git_integration_test", + ":{}".format(name) + for name in _TEST_NAMES ], visibility = ["//:__subpackages__"], ) -alias( +test_suite( name = "smoke_integration_tests", - actual = ":all_integration_tests", + tags = INTEGRATION_TEST_TAGS, + tests = [ + ":{}".format(name) + for name in _TEST_NAMES + ], 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 4325165a..a283c09c 100644 --- a/tests/shlib_tests/lib_tests/github_tests/BUILD.bazel +++ b/tests/shlib_tests/lib_tests/github_tests/BUILD.bazel @@ -93,19 +93,28 @@ sh_test( ], ) +_TEST_NAMES = [ + "get_gh_auth_status_test", + "get_gh_changelog_test", +] + test_suite( 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__"], ) -alias( +test_suite( name = "smoke_integration_tests", - actual = ":all_integration_tests", + tags = INTEGRATION_TEST_TAGS, + tests = [ + ":{}".format(name) + for name in _TEST_NAMES + ], visibility = ["//:__subpackages__"], ) @@ -114,9 +123,6 @@ ci_integration_test_params( bzlmod_modes = ["enabled"], # We only run this on linux. oss = ["linux"], - test_names = [ - "get_gh_auth_status_test", - "get_gh_changelog_test", - ], + test_names = _TEST_NAMES, visibility = ["//:__subpackages__"], ) From b73a09f6e8c6b837a56c617829dec0d0154e9c95 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sat, 22 Jul 2023 08:05:31 -0600 Subject: [PATCH 15/37] Fix missing_pkgs_tests unbound variable error --- .../tools_tests/missing_pkgs_tests/missing_pkgs_test.sh | 1 + 1 file changed, 1 insertion(+) 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" ) From 8d5eca18ccc4004ef505884b4b20c2c5624a9fa2 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sat, 22 Jul 2023 08:06:26 -0600 Subject: [PATCH 16/37] Update to latest 7.0.0-prerelease --- MODULE.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MODULE.bazel b/MODULE.bazel index 3709e597..5c97a550 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -58,5 +58,5 @@ bazel_binaries = use_extension( dev_dependency = True, ) bazel_binaries.download(version_file = "//:.bazelversion") -bazel_binaries.download(version = "7.0.0-pre.20230215.2") +bazel_binaries.download(version = "7.0.0-pre.20230628.2") use_repo(bazel_binaries, "bazel_binaries") From 6acb9c86163fb5b5fd971d6107b98b25cc8d0211 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sat, 22 Jul 2023 08:09:12 -0600 Subject: [PATCH 17/37] Regenerate CI workflow --- .github/workflows/ci.yml | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 361fe9b5..4d41ce16 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,16 +43,16 @@ jobs: - test: '@@//examples/bzlformat:simple_test_bazel_.bazelversion' runner: macos-13 enable_bzlmod: true - - test: '@@//examples/bzlformat:simple_test_bazel_7_0_0-pre_20230215_2' + - test: '@@//examples/bzlformat:simple_test_bazel_7_0_0-pre_20230628_2' runner: ubuntu-22.04 enable_bzlmod: false - - test: '@@//examples/bzlformat:simple_test_bazel_7_0_0-pre_20230215_2' + - test: '@@//examples/bzlformat:simple_test_bazel_7_0_0-pre_20230628_2' runner: ubuntu-22.04 enable_bzlmod: true - - test: '@@//examples/bzlformat:simple_test_bazel_7_0_0-pre_20230215_2' + - test: '@@//examples/bzlformat:simple_test_bazel_7_0_0-pre_20230628_2' runner: macos-13 enable_bzlmod: false - - test: '@@//examples/bzlformat:simple_test_bazel_7_0_0-pre_20230215_2' + - test: '@@//examples/bzlformat:simple_test_bazel_7_0_0-pre_20230628_2' runner: macos-13 enable_bzlmod: true - test: '@@//examples/markdown:simple_test_bazel_.bazelversion' @@ -67,16 +67,16 @@ jobs: - test: '@@//examples/markdown:simple_test_bazel_.bazelversion' runner: macos-13 enable_bzlmod: true - - test: '@@//examples/markdown:simple_test_bazel_7_0_0-pre_20230215_2' + - test: '@@//examples/markdown:simple_test_bazel_7_0_0-pre_20230628_2' runner: ubuntu-22.04 enable_bzlmod: false - - test: '@@//examples/markdown:simple_test_bazel_7_0_0-pre_20230215_2' + - test: '@@//examples/markdown:simple_test_bazel_7_0_0-pre_20230628_2' runner: ubuntu-22.04 enable_bzlmod: true - - test: '@@//examples/markdown:simple_test_bazel_7_0_0-pre_20230215_2' + - test: '@@//examples/markdown:simple_test_bazel_7_0_0-pre_20230628_2' runner: macos-13 enable_bzlmod: false - - test: '@@//examples/markdown:simple_test_bazel_7_0_0-pre_20230215_2' + - test: '@@//examples/markdown:simple_test_bazel_7_0_0-pre_20230628_2' runner: macos-13 enable_bzlmod: true - test: '@@//examples/updatesrc:simple_test_bazel_.bazelversion' @@ -91,16 +91,16 @@ jobs: - test: '@@//examples/updatesrc:simple_test_bazel_.bazelversion' runner: macos-13 enable_bzlmod: true - - test: '@@//examples/updatesrc:simple_test_bazel_7_0_0-pre_20230215_2' + - test: '@@//examples/updatesrc:simple_test_bazel_7_0_0-pre_20230628_2' runner: ubuntu-22.04 enable_bzlmod: false - - test: '@@//examples/updatesrc:simple_test_bazel_7_0_0-pre_20230215_2' + - test: '@@//examples/updatesrc:simple_test_bazel_7_0_0-pre_20230628_2' runner: ubuntu-22.04 enable_bzlmod: true - - test: '@@//examples/updatesrc:simple_test_bazel_7_0_0-pre_20230215_2' + - test: '@@//examples/updatesrc:simple_test_bazel_7_0_0-pre_20230628_2' runner: macos-13 enable_bzlmod: false - - test: '@@//examples/updatesrc:simple_test_bazel_7_0_0-pre_20230215_2' + - test: '@@//examples/updatesrc:simple_test_bazel_7_0_0-pre_20230628_2' runner: macos-13 enable_bzlmod: true - test: '@@//examples:bzlmod_e2e_test_bazel_.bazelversion' @@ -109,10 +109,10 @@ jobs: - test: '@@//examples:bzlmod_e2e_test_bazel_.bazelversion' runner: macos-13 enable_bzlmod: true - - test: '@@//examples:bzlmod_e2e_test_bazel_7_0_0-pre_20230215_2' + - test: '@@//examples:bzlmod_e2e_test_bazel_7_0_0-pre_20230628_2' runner: ubuntu-22.04 enable_bzlmod: true - - test: '@@//examples:bzlmod_e2e_test_bazel_7_0_0-pre_20230215_2' + - test: '@@//examples:bzlmod_e2e_test_bazel_7_0_0-pre_20230628_2' runner: macos-13 enable_bzlmod: true - test: '@@//tests/bzlformat_tests/tools_tests/missing_pkgs_tests:missing_pkgs_test_bazel_.bazelversion' @@ -121,10 +121,10 @@ jobs: - test: '@@//tests/bzlformat_tests/tools_tests/missing_pkgs_tests:missing_pkgs_test_bazel_.bazelversion' runner: macos-13 enable_bzlmod: true - - test: '@@//tests/bzlformat_tests/tools_tests/missing_pkgs_tests:missing_pkgs_test_bazel_7_0_0-pre_20230215_2' + - test: '@@//tests/bzlformat_tests/tools_tests/missing_pkgs_tests:missing_pkgs_test_bazel_7_0_0-pre_20230628_2' runner: ubuntu-22.04 enable_bzlmod: true - - test: '@@//tests/bzlformat_tests/tools_tests/missing_pkgs_tests:missing_pkgs_test_bazel_7_0_0-pre_20230215_2' + - test: '@@//tests/bzlformat_tests/tools_tests/missing_pkgs_tests:missing_pkgs_test_bazel_7_0_0-pre_20230628_2' runner: macos-13 enable_bzlmod: true - test: '@@//tests/bzlrelease_tests/rules_tests/generate_release_notes_tests:generate_release_notes_test' @@ -154,10 +154,10 @@ jobs: - test: '@@//tests/bzltidy_tests:tidy_all_test_bazel_.bazelversion' runner: macos-13 enable_bzlmod: true - - test: '@@//tests/bzltidy_tests:tidy_all_test_bazel_7_0_0-pre_20230215_2' + - test: '@@//tests/bzltidy_tests:tidy_all_test_bazel_7_0_0-pre_20230628_2' runner: ubuntu-22.04 enable_bzlmod: true - - test: '@@//tests/bzltidy_tests:tidy_all_test_bazel_7_0_0-pre_20230215_2' + - test: '@@//tests/bzltidy_tests:tidy_all_test_bazel_7_0_0-pre_20230628_2' runner: macos-13 enable_bzlmod: true - test: '@@//tests/shlib_tests/lib_tests/git_tests:git_integration_test' @@ -181,16 +181,16 @@ jobs: - test: '@@//tests/updatesrc_tests:updatesrc_test_bazel_.bazelversion' runner: macos-13 enable_bzlmod: true - - test: '@@//tests/updatesrc_tests:updatesrc_test_bazel_7_0_0-pre_20230215_2' + - test: '@@//tests/updatesrc_tests:updatesrc_test_bazel_7_0_0-pre_20230628_2' runner: ubuntu-22.04 enable_bzlmod: false - - test: '@@//tests/updatesrc_tests:updatesrc_test_bazel_7_0_0-pre_20230215_2' + - test: '@@//tests/updatesrc_tests:updatesrc_test_bazel_7_0_0-pre_20230628_2' runner: ubuntu-22.04 enable_bzlmod: true - - test: '@@//tests/updatesrc_tests:updatesrc_test_bazel_7_0_0-pre_20230215_2' + - test: '@@//tests/updatesrc_tests:updatesrc_test_bazel_7_0_0-pre_20230628_2' runner: macos-13 enable_bzlmod: false - - test: '@@//tests/updatesrc_tests:updatesrc_test_bazel_7_0_0-pre_20230215_2' + - test: '@@//tests/updatesrc_tests:updatesrc_test_bazel_7_0_0-pre_20230628_2' runner: macos-13 enable_bzlmod: true runs-on: ${{ matrix.runner }} From 3e9606b1de7f2b791b9a549c750947af68cecbe4 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sat, 22 Jul 2023 08:57:00 -0600 Subject: [PATCH 18/37] Add set_up_bazel to integration tests. --- .github/workflows/ci.yml | 3 +++ ci.bazelrc | 9 +++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4d41ce16..da5c8301 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -198,6 +198,9 @@ jobs: CC: clang steps: - uses: actions/checkout@v3 + - uses: cgrindel/gha_set_up_bazel@v1 + with: + repo_name: bazel-starlib - uses: ./.github/actions/configure_bzlmod with: enabled: ${{ matrix.enable_bzlmod }} diff --git a/ci.bazelrc b/ci.bazelrc index 5eea8c2d..517c612f 100644 --- a/ci.bazelrc +++ b/ci.bazelrc @@ -6,12 +6,9 @@ common:ci --announce_rc # Disable color common:ci --color=no -# Information about Github Action hosted runners -# https://docs.github.com/en/free-pro-team@latest/actions/reference/specifications-for-github-hosted-runners#supported-runners-and-hardware-resources -build:ci --local_cpu_resources=2 +# # Information about Github Action hosted runners +# # https://docs.github.com/en/free-pro-team@latest/actions/reference/specifications-for-github-hosted-runners#supported-runners-and-hardware-resources +# build:ci --local_cpu_resources=2 # Test output information test:ci --test_output=errors --test_summary=detailed - -# Repository Cache -build:ci --repository_cache=~/.cache/bazel_repo From e52f4d44d92425c398cd727a9f85d786f0105874 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sat, 22 Jul 2023 09:03:19 -0600 Subject: [PATCH 19/37] Add debug to integration tests --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index da5c8301..ff67a9d8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -207,6 +207,10 @@ jobs: - uses: ./.github/actions/configure_remote_cache_auth with: buildbuddy_api_key: ${{ secrets.BUILDBUDDY_API_KEY }} + - name: CHUCK DEBUG + shell: bash + run: | + bazel query //... - uses: ./.github/actions/execute_test with: bzlmod_enabled: ${{ matrix.bzlmod_enabled }} From 77caba7e62a57ea505adaa4971f56ffb9c9b5da3 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sat, 22 Jul 2023 13:42:14 -0600 Subject: [PATCH 20/37] Remove commented code --- .github/actions/tidy_and_test/action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/actions/tidy_and_test/action.yml b/.github/actions/tidy_and_test/action.yml index 93fba117..9772dd0b 100644 --- a/.github/actions/tidy_and_test/action.yml +++ b/.github/actions/tidy_and_test/action.yml @@ -1,5 +1,4 @@ name: Tidy and Test -# inputs: [] runs: using: composite From f9f0fce9e0a0950f0e83b1959a6782370e5162b6 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sat, 22 Jul 2023 13:42:23 -0600 Subject: [PATCH 21/37] Remove unused input --- .github/workflows/ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ff67a9d8..5f725226 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -224,7 +224,6 @@ jobs: - ubuntu-22.04 enable_bzlmod: - true - - false runs-on: ${{ matrix.runner }} steps: - uses: actions/checkout@v3 @@ -238,5 +237,3 @@ jobs: with: buildbuddy_api_key: ${{ secrets.BUILDBUDDY_API_KEY }} - uses: ./.github/actions/tidy_and_test - with: - github_token: ${{ secrets.GITHUB_TOKEN }} From fec9d42ae3d59a7d0ef9184db00355d43b5107c0 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sat, 22 Jul 2023 13:42:33 -0600 Subject: [PATCH 22/37] Remove legacy WORKSPACE --- WORKSPACE | 72 ------------------------------------------------ WORKSPACE.bzlmod | 2 -- 2 files changed, 74 deletions(-) delete mode 100644 WORKSPACE.bzlmod diff --git a/WORKSPACE b/WORKSPACE index f18bd495..9526376d 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,74 +1,2 @@ # This file marks the root of the Bazel workspace. # See MODULE.bazel for dependencies and setup. - -workspace(name = "cgrindel_bazel_starlib") - -load("//:deps.bzl", "bazel_starlib_dependencies") - -bazel_starlib_dependencies() - -# gazelle:repo bazel_gazelle -load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") -load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") -load("//:go_deps.bzl", "bazel_starlib_go_dependencies") - -# gazelle:repository_macro go_deps.bzl%bazel_starlib_go_dependencies -bazel_starlib_go_dependencies() - -# MARK: - Skylib Gazelle Extension - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -http_archive( - name = "bazel_skylib_gazelle_plugin", - sha256 = "3327005dbc9e49cc39602fb46572525984f7119a9c6ffe5ed69fbe23db7c1560", - urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-gazelle-plugin-1.4.2.tar.gz", - "https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-gazelle-plugin-1.4.2.tar.gz", - ], -) - -load("@bazel_skylib_gazelle_plugin//:workspace.bzl", "bazel_skylib_gazelle_plugin_workspace") - -bazel_skylib_gazelle_plugin_workspace() - -go_rules_dependencies() - -go_register_toolchains(version = "1.19.5") - -gazelle_dependencies() - -load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") - -bazel_skylib_workspace() - -load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories") - -stardoc_repositories() - -# MARK: - Prebuilt Buildtools Deps - -load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps") - -buildifier_prebuilt_deps() - -load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains") - -buildifier_prebuilt_register_toolchains() - -# MARK: - Integration Testing - -http_archive( - name = "rules_bazel_integration_test", - sha256 = "bfba659b9e29fc4cbeb2410e20f0270c54da3886bbe69aa8b0378701dca06a8d", - urls = [ - "https://github.com/bazel-contrib/rules_bazel_integration_test/releases/download/v0.14.1/rules_bazel_integration_test.v0.14.1.tar.gz", - ], -) - -load("@rules_bazel_integration_test//bazel_integration_test:repo_defs.bzl", "bazel_binaries") - -bazel_binaries(versions = [ - "//:.bazelversion", - "7.0.0-pre.20230215.2", -]) diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod deleted file mode 100644 index 8cf89c33..00000000 --- a/WORKSPACE.bzlmod +++ /dev/null @@ -1,2 +0,0 @@ -# Intentionally blank -# This exists to force Bazel in bzlmod mode to be strict. From 066324b028a8cd6faaeeb0d2f0d95e0f94acc768 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sat, 22 Jul 2023 13:57:13 -0600 Subject: [PATCH 23/37] Ignore child_workspace.bazelrc files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index ab0ecdf4..6a3512c3 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,8 @@ node_modules # Ignore the local.bazelrc local.bazelrc +# Ignore configuration files that are used for chidl workspaces +child_workspace.bazelrc + # Some bzltidy tests write files with the extension .tidy_out *.tidy_out From 817151b8613652712262ec6df08dd015a8bd974b Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sat, 22 Jul 2023 14:05:19 -0600 Subject: [PATCH 24/37] Only configure bzlmod for child workspaces. --- .github/actions/configure_bzlmod/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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" < Date: Sat, 22 Jul 2023 14:08:23 -0600 Subject: [PATCH 25/37] Add try-import child_workspace.bazelrc to select child workspaces. --- examples/bzlformat/simple/.bazelrc | 3 +++ examples/markdown/simple/.bazelrc | 4 ++++ examples/updatesrc/simple/.bazelrc | 4 ++++ tests/updatesrc_tests/workspace/.bazelrc | 4 +++- 4 files changed, 14 insertions(+), 1 deletion(-) 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/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/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/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 From 3bdea522a1febcfbc5e9f128c9172df160b1b6e4 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sat, 22 Jul 2023 14:15:21 -0600 Subject: [PATCH 26/37] Update the other child workspaces with try-import of child_workspace.bazelrc. --- .../tools_tests/missing_pkgs_tests/workspace/.bazelrc | 4 ++++ tests/bzltidy_tests/workspace/.bazelrc | 4 ++++ 2 files changed, 8 insertions(+) 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/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 From c609b4cc8d18ea92ecb269c4ce136fb2ad89efdf Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sat, 22 Jul 2023 14:20:24 -0600 Subject: [PATCH 27/37] Enable bzlmod for the parent workspace. --- .bazelrc | 4 ++++ 1 file changed, 4 insertions(+) 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 From 893b63d8b6186d429b95f0e23dbe04ec30f83bf7 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sat, 22 Jul 2023 14:20:37 -0600 Subject: [PATCH 28/37] Remove configure_bzlmod from tidy_and_test. The parent always runs with bzlmod enabled now. --- .github/workflows/ci.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5f725226..af574f13 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -207,10 +207,6 @@ jobs: - uses: ./.github/actions/configure_remote_cache_auth with: buildbuddy_api_key: ${{ secrets.BUILDBUDDY_API_KEY }} - - name: CHUCK DEBUG - shell: bash - run: | - bazel query //... - uses: ./.github/actions/execute_test with: bzlmod_enabled: ${{ matrix.bzlmod_enabled }} @@ -222,17 +218,12 @@ jobs: runner: - macos-13 - ubuntu-22.04 - enable_bzlmod: - - true runs-on: ${{ matrix.runner }} steps: - uses: actions/checkout@v3 - uses: cgrindel/gha_set_up_bazel@v1 with: repo_name: bazel-starlib - - uses: ./.github/actions/configure_bzlmod - with: - enabled: ${{ matrix.enable_bzlmod }} - uses: ./.github/actions/configure_remote_cache_auth with: buildbuddy_api_key: ${{ secrets.BUILDBUDDY_API_KEY }} From b5c5361a85709e20ffebd465506cfc885508192d Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sat, 22 Jul 2023 14:32:24 -0600 Subject: [PATCH 29/37] Be sure to expose GitHub required environment variables. --- .bazelrc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.bazelrc b/.bazelrc index 15df5cb2..839511a5 100644 --- a/.bazelrc +++ b/.bazelrc @@ -21,6 +21,13 @@ build:ci --//build:execution_env=ci common --enable_bzlmod build --@cgrindel_bazel_starlib//bzlmod:enabled +# Keep this in sync with GH_ENV_INHERIT in +# tests/integration_test_common.bzl. +build --action_env=GITHUB_TOKEN +build --action_env=GH_TOKEN +build --action_env=HOME + + # Try to import a local.rc file; typically, written by CI try-import %workspace%/local.bazelrc From 11edbd0e58b0f31ca58a7435cf73570192aff3c5 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sat, 22 Jul 2023 14:39:02 -0600 Subject: [PATCH 30/37] Pass the GH token to the tests and set the env variable. --- .github/actions/execute_test/action.yml | 5 +++++ .github/actions/tidy_and_test/action.yml | 11 +++++++++++ .github/workflows/ci.yml | 3 +++ 3 files changed, 19 insertions(+) diff --git a/.github/actions/execute_test/action.yml b/.github/actions/execute_test/action.yml index 0ab3822d..27c1e8ef 100644 --- a/.github/actions/execute_test/action.yml +++ b/.github/actions/execute_test/action.yml @@ -7,6 +7,9 @@ inputs: bzlmod_enabled: description: Boolean value that specifies whether bzlmod should be enabled. required: true + github_token: + description: The Github token to authenticate gh CLI. + required: true runs: using: composite @@ -16,6 +19,8 @@ runs: env: TEST_TARGET: ${{ inputs.test_target }} BZLMOD_ENABLED: ${{ inputs.bzlmod_enabled }} + # The tests make use of Github-specific functionality (e.g. gh). + GITHUB_TOKEN: ${{ inputs.github_token }} run: | if [[ "${BZLMOD_ENABLED}" == "false" ]] && [[ "${TEST_TARGET}" =~ ^@@ ]]; then # Strip the first @ from test target diff --git a/.github/actions/tidy_and_test/action.yml b/.github/actions/tidy_and_test/action.yml index 9772dd0b..0e7d5cc0 100644 --- a/.github/actions/tidy_and_test/action.yml +++ b/.github/actions/tidy_and_test/action.yml @@ -1,14 +1,25 @@ name: Tidy and Test +inputs: + github_token: + description: The Github token to authenticate gh CLI. + required: true + runs: using: composite steps: - name: Ensure everything is tidy shell: bash + env: + # The tests make use of Github-specific functionality (e.g. gh). + GITHUB_TOKEN: ${{ inputs.github_token }} run: | bazelisk run //:tidy_check - name: Execute Tests shell: bash + env: + # The tests make use of Github-specific functionality (e.g. gh). + GITHUB_TOKEN: ${{ inputs.github_token }} run: | bazelisk test //... diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index af574f13..e28a9042 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -211,6 +211,7 @@ jobs: with: bzlmod_enabled: ${{ matrix.bzlmod_enabled }} test_target: ${{ matrix.test }} + github_token: ${{ secrets.GITHUB_TOKEN }} tidy_and_test_matrix: strategy: fail-fast: false @@ -228,3 +229,5 @@ jobs: with: buildbuddy_api_key: ${{ secrets.BUILDBUDDY_API_KEY }} - uses: ./.github/actions/tidy_and_test + with: + github_token: ${{ secrets.GITHUB_TOKEN }} From 19cdf6cf9565b1774b9e7a9110cbbfa6f8d3c811 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sun, 23 Jul 2023 08:02:11 -0600 Subject: [PATCH 31/37] Remove action_env for GH env vars --- .bazelrc | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.bazelrc b/.bazelrc index 839511a5..15df5cb2 100644 --- a/.bazelrc +++ b/.bazelrc @@ -21,13 +21,6 @@ build:ci --//build:execution_env=ci common --enable_bzlmod build --@cgrindel_bazel_starlib//bzlmod:enabled -# Keep this in sync with GH_ENV_INHERIT in -# tests/integration_test_common.bzl. -build --action_env=GITHUB_TOKEN -build --action_env=GH_TOKEN -build --action_env=HOME - - # Try to import a local.rc file; typically, written by CI try-import %workspace%/local.bazelrc From 583b651c7321156f76ffd96539ea0727b83e8ecc Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sun, 23 Jul 2023 09:48:28 -0600 Subject: [PATCH 32/37] Delete commented code --- tests/bzltidy_tests/BUILD.bazel | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/bzltidy_tests/BUILD.bazel b/tests/bzltidy_tests/BUILD.bazel index 0a77e920..e47d84fd 100644 --- a/tests/bzltidy_tests/BUILD.bazel +++ b/tests/bzltidy_tests/BUILD.bazel @@ -16,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 = [ From cc22c76baef4c4fe37460426144aff5370bfdeae Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sun, 23 Jul 2023 09:58:14 -0600 Subject: [PATCH 33/37] Use the specified Bazel binary in tidy_all_test. --- tests/bzltidy_tests/tidy_all_test.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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}" From af2b999cfb93bd38e91b5d3a2fda592148e5a38a Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sun, 23 Jul 2023 10:07:34 -0600 Subject: [PATCH 34/37] Remove bazelrc imports from child workspaces in tidy_all_test. --- .../workspace/child_workspaces/bar/.bazelrc | 12 ++++++------ .../workspace/child_workspaces/foo/.bazelrc | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/bzltidy_tests/workspace/child_workspaces/bar/.bazelrc b/tests/bzltidy_tests/workspace/child_workspaces/bar/.bazelrc index 005fb31a..19a1cbb4 100644 --- a/tests/bzltidy_tests/workspace/child_workspaces/bar/.bazelrc +++ b/tests/bzltidy_tests/workspace/child_workspaces/bar/.bazelrc @@ -1,11 +1,11 @@ -# Import shared settings -import %workspace%/../../../../../shared.bazelrc +# # Import shared settings +# import %workspace%/../../../../../shared.bazelrc -# Import CI settings. -import %workspace%/../../../../../ci.bazelrc +# # Import CI settings. +# import %workspace%/../../../../../ci.bazelrc -# Try to import a local.rc file; typically, written by CI -try-import %workspace%/../../../../../local.bazelrc +# # Try to import a local.rc file; typically, written by CI +# try-import %workspace%/../../../../../local.bazelrc # 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..19a1cbb4 100644 --- a/tests/bzltidy_tests/workspace/child_workspaces/foo/.bazelrc +++ b/tests/bzltidy_tests/workspace/child_workspaces/foo/.bazelrc @@ -1,11 +1,11 @@ -# Import shared settings -import %workspace%/../../../../../shared.bazelrc +# # Import shared settings +# import %workspace%/../../../../../shared.bazelrc -# Import CI settings. -import %workspace%/../../../../../ci.bazelrc +# # Import CI settings. +# import %workspace%/../../../../../ci.bazelrc -# Try to import a local.rc file; typically, written by CI -try-import %workspace%/../../../../../local.bazelrc +# # Try to import a local.rc file; typically, written by CI +# try-import %workspace%/../../../../../local.bazelrc # Explicitly enable bzlmod common --enable_bzlmod From 5196959691303bcd4b533b4b72bca6de494c46de Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sun, 23 Jul 2023 10:14:24 -0600 Subject: [PATCH 35/37] Ran tidy --- .github/workflows/ci.yml | 2 +- WORKSPACE | 5 +++++ examples/BUILD.bazel | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e28a9042..304b9419 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -210,8 +210,8 @@ jobs: - uses: ./.github/actions/execute_test with: bzlmod_enabled: ${{ matrix.bzlmod_enabled }} - test_target: ${{ matrix.test }} github_token: ${{ secrets.GITHUB_TOKEN }} + test_target: ${{ matrix.test }} tidy_and_test_matrix: strategy: fail-fast: false diff --git a/WORKSPACE b/WORKSPACE index 9526376d..2c77a21d 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,2 +1,7 @@ # This file marks the root of the Bazel workspace. # See MODULE.bazel for dependencies and setup. + +load("//:go_deps.bzl", "bazel_starlib_go_dependencies") + +# gazelle:repository_macro go_deps.bzl%bazel_starlib_go_dependencies +bazel_starlib_go_dependencies() diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel index 70536538..e158be93 100644 --- a/examples/BUILD.bazel +++ b/examples/BUILD.bazel @@ -1,3 +1,4 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_binaries//:defs.bzl", "bazel_binaries") load( "@rules_bazel_integration_test//bazel_integration_test:defs.bzl", @@ -106,3 +107,9 @@ filegroup( srcs = glob(["bzlmod_e2e/**"]), visibility = ["//:__subpackages__"], ) + +bzl_library( + name = "examples", + srcs = ["examples.bzl"], + visibility = ["//visibility:public"], +) From f6af22efd6fe13fa27c31f9a85bdf33b40df53e5 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sun, 23 Jul 2023 10:17:38 -0600 Subject: [PATCH 36/37] Add comment to tidy_all_test child workspace bazelrc files. --- .../workspace/child_workspaces/bar/.bazelrc | 10 ++-------- .../workspace/child_workspaces/foo/.bazelrc | 10 ++-------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/tests/bzltidy_tests/workspace/child_workspaces/bar/.bazelrc b/tests/bzltidy_tests/workspace/child_workspaces/bar/.bazelrc index 19a1cbb4..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 19a1cbb4..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 From 5326502798014d329927d3d5fa81b215d81644e7 Mon Sep 17 00:00:00 2001 From: Chuck Grindel Date: Sun, 23 Jul 2023 10:36:10 -0600 Subject: [PATCH 37/37] Fix formatting --- examples/BUILD.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel index e158be93..3798637a 100644 --- a/examples/BUILD.bazel +++ b/examples/BUILD.bazel @@ -1,5 +1,5 @@ -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") 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",