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/BUILD b/BUILD index 41671011..9ee007cb 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 = "@rules_license//licenses/spdx: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", 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 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)