Skip to content

Commit

Permalink
Separate out test dependencies from the core bzlmod extensions (#105)
Browse files Browse the repository at this point in the history
closes #104
  • Loading branch information
abrisco authored Oct 14, 2024
1 parent 282d4ec commit 4118652
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 65 deletions.
14 changes: 8 additions & 6 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ use_repo(
"helm_windows_amd64_toolchain",
)
use_repo(helm, "go_yaml_yaml")
use_repo(
helm,
"helm_test_deps__with_chart_deps_postgresql",
"helm_test_deps__with_chart_deps_redis",
"rules_helm_test_container_base",
)

register_toolchains(
"@helm_darwin_amd64_toolchain//:toolchain",
Expand All @@ -45,3 +39,11 @@ register_toolchains(
"@helm_linux_arm64_toolchain//:toolchain",
"@helm_windows_amd64_toolchain//:toolchain",
)

helm_test = use_extension("@rules_helm//tests:test_extensions.bzl", "helm_test")
use_repo(
helm_test,
"helm_test_deps__with_chart_deps_postgresql",
"helm_test_deps__with_chart_deps_redis",
"rules_helm_test_container_base",
)
126 changes: 79 additions & 47 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 35 additions & 12 deletions helm/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,32 @@

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//helm:repositories.bzl", "helm_host_alias_repository", "helm_toolchain_repository")
load("//helm/private:versions.bzl", "CONSTRAINTS", "DEFAULT_HELM_URL_TEMPLATES", "DEFAULT_HELM_VERSION", "HELM_VERSIONS")
load("//tests:test_deps.bzl", "helm_test_deps")
load(
"//helm:repositories.bzl",
"helm_host_alias_repository",
"helm_toolchain_repository",
)
load(
"//helm/private:versions.bzl",
"CONSTRAINTS",
"DEFAULT_HELM_URL_TEMPLATES",
"DEFAULT_HELM_VERSION",
"HELM_VERSIONS",
)

_HELM_TAR_BUILD_CONTENT = """\
package(default_visibility = ["//visibility:public"])
exports_files(glob(["**"]))
"""

def _impl(ctx):
def _helm_impl(ctx):
module = ctx.modules[0]
options = module.tags.options
version = options[0].version
helm_url_templates = options[0].helm_url_templates

_register_toolchains(version, helm_url_templates)
_register_go_yaml()
helm_test_deps()

def _register_toolchains(version, helm_url_templates):
if not version in HELM_VERSIONS:
Expand All @@ -45,10 +53,15 @@ def _register_toolchains(version, helm_url_templates):
http_archive,
name = name,
urls = [
template.format(
version = version,
platform = url_platform,
compression = compression,
template.replace(
"{version}",
version,
).replace(
"{platform}",
url_platform,
).replace(
"{compression}",
compression,
)
for template in helm_url_templates
],
Expand Down Expand Up @@ -79,11 +92,21 @@ def _register_go_yaml():
)

options = tag_class(attrs = {
"helm_url_templates": attr.string_list(default = DEFAULT_HELM_URL_TEMPLATES),
"version": attr.string(default = DEFAULT_HELM_VERSION),
"helm_url_templates": attr.string_list(
doc = (
"A url template used to download helm. The template can contain the following " +
"format strings `{platform}` for the helm platform, `{version}` for the helm " +
"version, and `{compression}` for the archive type containing the helm binary."
),
default = DEFAULT_HELM_URL_TEMPLATES,
),
"version": attr.string(
doc = "The version of helm to download for the toolchain.",
default = DEFAULT_HELM_VERSION,
),
})

helm = module_extension(
implementation = _impl,
implementation = _helm_impl,
tag_classes = {"options": options},
)
10 changes: 10 additions & 0 deletions tests/test_extensions.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Bzlmod test extensions"""

load("//tests:test_deps.bzl", "helm_test_deps")

def _helm_test_impl(_ctx):
helm_test_deps()

helm_test = module_extension(
implementation = _helm_test_impl,
)

0 comments on commit 4118652

Please sign in to comment.