From e2bea6da9e74cd569fa24e0707955c178f5b6e2f Mon Sep 17 00:00:00 2001 From: kim viggedal Date: Mon, 29 Jun 2026 15:34:04 +0200 Subject: [PATCH 1/4] Add license target to project This makes the license observable through Bazel and facilitates for consumers of this project the automated building of an SBOM. --- BUILD | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/BUILD b/BUILD index 41671011..85b7e19a 100644 --- a/BUILD +++ b/BUILD @@ -1,4 +1,5 @@ load("@rules_kotlin//kotlin:core.bzl", "define_kt_toolchain") +load("@rules_license//rules:license.bzl", "license") alias( name = "bazel-diff", @@ -10,6 +11,21 @@ alias( actual = "//cli/format:format", ) +package( + default_applicable_licenses = [":license"], + default_visibility = ["//visibility:public"], +) + +license( + name = "license", + package_name = "bazel-diff", + copyright_notice = "Copyright (c) 2020, Match Group, LLC", + license_kind = "@@//support/licenses:BSD-3-Clause", + license_text = "LICENSE", + package_url = "https://github.com/Tinder/bazel-diff", + package_version = "29.0.0", +) + define_kt_toolchain( name = "kotlin_toolchain", jvm_target = "11", From d835053ce7c355ce86ca82cc2d36b158e4df8e75 Mon Sep 17 00:00:00 2001 From: kim viggedal Date: Tue, 30 Jun 2026 08:28:39 +0200 Subject: [PATCH 2/4] Add steps to make sure license target is valid Adding a CI step to build the license target to ensure it's kept intact. Modifying generate-readme tool to keep the package_version of the license target in sync with the current version of the project. --- .github/workflows/ci.yaml | 4 ++++ tools/generate_readme.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bb4c0c2f..f1b50f48 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -35,6 +35,10 @@ jobs: - name: Setup Bazelisk run: go install github.com/bazelbuild/bazelisk@latest && export PATH=$PATH:$(go env GOPATH)/bin - uses: actions/checkout@v4 + - name: Build license target + env: + USE_BAZEL_VERSION: ${{ matrix.bazel }} + run: ~/go/bin/bazelisk build //:license --enable_bzlmod=true --enable_workspace=false - name: Run bazel-diff tests env: USE_BAZEL_VERSION: ${{ matrix.bazel }} diff --git a/tools/generate_readme.py b/tools/generate_readme.py index 2a7077c4..091bd08a 100644 --- a/tools/generate_readme.py +++ b/tools/generate_readme.py @@ -250,6 +250,21 @@ def read_module_version(workspace_dir: Path) -> str: return match.group(1) +def sync_build_version(workspace_dir: Path, version: str) -> None: + """Keep the license() package_version in the root BUILD file in sync.""" + build_file = workspace_dir / "BUILD" + text = build_file.read_text() + new_text, count = re.subn( + r'(package_version\s*=\s*")[^"]+(")', + rf"\g<1>{version}\g<2>", + text, + ) + if count == 0: + raise ValueError("Could not find package_version in BUILD") + if new_text != text: + build_file.write_text(new_text) + + def main() -> None: workspace_dir = Path(os.environ["BUILD_WORKSPACE_DIRECTORY"]) output_path = workspace_dir / "README.md" @@ -262,6 +277,7 @@ def main() -> None: version = read_module_version(workspace_dir) template = template.replace("{{BAZEL_DIFF_VERSION}}", version) + sync_build_version(workspace_dir, version) print("Fetching GitHub user data...") email_map = fetch_github_email_map(REPO) From 3ec3658aa6e7f586273596dff9a8bab60d2ca577 Mon Sep 17 00:00:00 2001 From: kim viggedal Date: Wed, 1 Jul 2026 08:12:23 +0200 Subject: [PATCH 3/4] Fix license kind There was copy paste mistake in specifying the license kind. --- BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BUILD b/BUILD index 85b7e19a..9ee007cb 100644 --- a/BUILD +++ b/BUILD @@ -20,7 +20,7 @@ license( name = "license", package_name = "bazel-diff", copyright_notice = "Copyright (c) 2020, Match Group, LLC", - license_kind = "@@//support/licenses:BSD-3-Clause", + license_kind = "@rules_license//licenses/spdx:BSD-3-Clause", license_text = "LICENSE", package_url = "https://github.com/Tinder/bazel-diff", package_version = "29.0.0", From 9f053ea328af20da156b88c7e5ac15bdb275f63e Mon Sep 17 00:00:00 2001 From: kim viggedal Date: Wed, 1 Jul 2026 09:21:33 +0200 Subject: [PATCH 4/4] Add rules_license bazel_dep in MODULE.bazel --- MODULE.bazel | 1 + 1 file changed, 1 insertion(+) diff --git a/MODULE.bazel b/MODULE.bazel index f66882bc..dc0f339b 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -13,6 +13,7 @@ bazel_dep(name = "bazel_skylib", version = "1.9.0") bazel_dep(name = "rules_proto", version = "7.1.0") bazel_dep(name = "rules_java", version = "9.3.0") bazel_dep(name = "rules_kotlin", version = "2.3.0") +bazel_dep(name = "rules_license", version = "1.0.0") bazel_dep(name = "rules_jvm_external", version = "6.10") # Add protobuf and grpc for Bazel 9 compatibility