Skip to content

Commit 0e375a3

Browse files
committed
Enable Bzlmod
All but finishes bazel-contrib#1482, save for publication of the first `rules_scala` release to the Bazel Central Registry. Closes bazel-contrib#1625. The module extensions and underlying helper macros comprise the most significant part of the change. The extensions provide a thin layer over the existing `WORKSPACE` API. The `scala/private/macros/bzlmod.bzl` docstring explains the common pattern employed throughout. - `scala/extensions/config.bzl`: invokes `scala_config()` - `scala/extensions/deps.bzl`: invokes `scala_toolchains()` - `scala/extensions/protoc.bzl`: invokes `scala_protoc_toolchains()` - `scala/private/extensions/dev_deps.bzl`: internal testing dependencies - `scala/private/macros/bzlmod.bzl`: module extension helper macros Existing tests thoroughly validate `config.bzl`, `deps.bzl`, `dev_deps.bzl`, and `protoc.bzl`. `test/shell/test_bzlmod_macros.sh` tests the helpers from `scala/private/macros/bzlmod.bzl` using the new test files from `scala/private/macros/test/...`. Most of the new files are essentially boilerplate: - Adds `MODULE.bazel` files mirroring existing `WORKSPACE` configurations and copies of the `protobuf` toolchainization patch to the main repo and every nested repo. - Adds empty `WORKSPACE.bzlmod` files to ensure that Bzlmod won't evaluate the `WORKSPACE` files. These changes update CI and the release workflow: - Sets `--noenable_workspace` in `.bazelrc` and `tools/bazel.rc.buildkite`. - Reenables the `last_green` Bazel build in `.bazelci/presubmit.yml`. - Adds `.github/workflows/publish-to-bcr.yml` and `.bcr/*` for publishing to the Bazel Central Registry. `.github/workflows/release.yml` invokes this new workflow after publishing a successful release to GitHub. Based on aspect-build/rules_lint#498 and aspect-build/rules_lint#501. All other changes: - Adds `.bazelignore` to work around bazelbuild/bazel#22208. - Adds `assert_matches` to `test/shell/test_helper.sh` for use in `test/shell/test_bzlmod_macros.sh`. - `test/shell/test_bzlmod_macros.sh` introduces a mechanism for automatically finding and skipping tests, documented in the comment at the bottom of the file. - Adds `bazel mod tidy` checks to `test_lint.sh` and `test_version.sh`. - Adds `bazel clean --expunge_async` to tests that create temporary repos. - Adds the `test_cleanup.sh` script to reclaim disk space. --- This change enables Bazel 7 and 8 users to migrate their `rules_scala` dependency from `WORKSPACE` to `MODULE.bazel` whenever they're ready. It also ensures that new changes are compatible with the `last_green` build of Bazel, and enables publishing releases to the Bazel Central Registry. Per the (prereleased) "Publish to BCR" workflow setup instructions linked from `.bcr/README.md`, we need to create: - a fork of `bazelbuild/bazel-central-registry` (which I've proactively referred to as `simuons/bazel-central-registry`) - a personal access token with "workflow" and "repo" permissions, saved as `PUBLISH_TOKEN` in the BCR fork (under "Settings > Secrets and variables > Actions") Once these items are ready, we can push a release tag to publish the first `rules_scala` Bazel module to https://registry.bazel.build/. At that point, we can close bazel-contrib#1482.
1 parent 0ba9ab7 commit 0e375a3

File tree

85 files changed

+3875
-42
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+3875
-42
lines changed

.bazelci/presubmit.yml

+4-6
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,15 @@ tasks:
2929
# Install xmllint
3030
- sudo apt update && sudo apt install --reinstall libxml2-utils -y
3131
- "./test_rules_scala.sh"
32-
# Switch `last_rc` to `last_green` once Bzlmod lands.
33-
# https://github.com/bazelbuild/rules_scala/issues/1482
34-
test_rules_scala_linux_last_rc:
35-
name: "./test_rules_scala (last_rc Bazel)"
32+
test_rules_scala_linux_last_green:
33+
name: "./test_rules_scala (last_green Bazel)"
3634
platform: ubuntu2004
37-
bazel: last_rc
35+
bazel: last_green
3836
shell_commands:
3937
# Install xmllint
4038
- sudo apt update && sudo apt install --reinstall libxml2-utils -y
4139
- echo "build --enable_workspace" >> .bazelrc
42-
- "./test_rules_scala.sh || buildkite-agent annotate --style 'warning' \"Optional build with last_rc Bazel version failed, [see here](${BUILDKITE_BUILD_URL}#${BUILDKITE_JOB_ID}) (It is not mandatory but worth checking)\""
40+
- "./test_rules_scala.sh || buildkite-agent annotate --style 'warning' \"Optional build with last_green Bazel version failed, [see here](${BUILDKITE_BUILD_URL}#${BUILDKITE_JOB_ID}) (It is not mandatory but worth checking)\""
4341
test_rules_scala_macos:
4442
name: "./test_rules_scala"
4543
platform: macos

.bazelignore

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Remove once the following is fixed:
2+
# - bazelbuild/bazel: Loading top-level targets in local_path_override modules
3+
# in child directory breaks the build #22208
4+
# https://github.com/bazelbuild/bazel/issues/22208
5+
dt_patches/compiler_sources
6+
dt_patches/test_dt_patches
7+
dt_patches/test_dt_patches_user_srcjar
8+
examples/crossbuild
9+
examples/overridden_artifacts
10+
examples/scala3
11+
examples/semanticdb
12+
examples/testing/multi_frameworks_toolchain
13+
examples/testing/scalatest_repositories
14+
examples/testing/specs2_junit_repositories
15+
test/proto_cross_repo_boundary/repo
16+
test_cross_build
17+
third_party/test/example_external_workspace
18+
third_party/test/new_local_repo
19+
third_party/test/proto

.bazelrc

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# Switch to --noenable_workspace when Bzlmod lands.
2-
# https://github.com/bazelbuild/rules_scala/issues/1482
3-
common --enable_workspace --noenable_bzlmod
1+
# Remove once Bazel 8 becomes the minimum supported version.
2+
common --noenable_workspace --incompatible_use_plus_in_repo_names
43

5-
# Remove once proto toolchainization becomes the default
4+
# Remove if protocol compiler toolchainization ever becomes the default.
65
# - https://bazel.build/reference/command-line-reference#flag--incompatible_enable_proto_toolchain_resolution
76
# - https://docs.google.com/document/d/1CE6wJHNfKbUPBr7-mmk_0Yo3a4TaqcTPE0OWNuQkhPs/edit
87
common --incompatible_enable_proto_toolchain_resolution

.bcr/README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Bazel Central Registry publication
2+
3+
The [.github/workflows/publish-to-bcr.yml](
4+
../.github/workflows/publish-to-bcr.yml) reusable GitHub workflow uses these
5+
configuration files for publishing Bazel modules to the [Bazel Central Registry
6+
(BCR)](https://registry.bazel.build/). This workflow also produces attestations
7+
required by the [Supply chain Levels for Software Artifacts
8+
(SLSA)](https://slsa.dev/) framework for secure supply chain provenance.
9+
10+
[bazel-contrib/publish-to-bcr](https://github.com/bazel-contrib/publish-to-bcr)
11+
documentation:
12+
13+
- [Publish to BCR workflow setup (from bazel-contrib/publish-to-bcr@fb1dc68)](
14+
https://github.com/bazel-contrib/publish-to-bcr/blob/fb1dc6802c3c999e17ad7afce9474a90bd89e132/README.md#setup)
15+
- [.bcr/ templates](
16+
https://github.com/bazel-contrib/publish-to-bcr/tree/main/templates)
17+
- [.github/workflows/publish.yaml reusable workflow](
18+
https://github.com/bazel-contrib/publish-to-bcr/blob/main/.github/workflows/publish.yaml)
19+
20+
Related documentation:
21+
22+
- [bazelbuild/bazel-central-registry](
23+
https://github.com/bazelbuild/bazel-central-registry)
24+
- [GitHub Actions](https://docs.github.com/actions)
25+
- [slsa-framework/slsa-verifier](
26+
https://github.com/slsa-framework/slsa-verifier)
27+
- [Security for GitHub Actions](
28+
https://docs.github.com/en/actions/security-for-github-actions)
29+
- [Security for GitHub Actions: Using artifact attestations](
30+
https://docs.github.com/en/actions/security-for-github-actions/using-artifact-attestations)
31+
32+
---
33+
34+
Originally based on the examples from aspect-build/rules_lint#498 and
35+
aspect-build/rules_lint#501. See also:
36+
37+
- bazelbuild/bazel-central-registry#4060
38+
- slsa-framework/slsa-verifier#840

.bcr/metadata.template.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"homepage": "https://github.com/bazelbuild/rules_scala",
3+
"maintainers": [
4+
{
5+
"name": "Simonas Pinevičius",
6+
"email": "simonas.pinevicius@gmail.com",
7+
"github": "simuons"
8+
},
9+
{
10+
"name": "Vaidas Pilkauskas",
11+
"email": "vaidas.pilkauskas@gmail.com",
12+
"github": "liucijus"
13+
}
14+
],
15+
"repository": [
16+
"github:bazelbuild/rules_scala"
17+
],
18+
"versions": [],
19+
"yanked_versions": {}
20+
}

.bcr/presubmit.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
bcr_test_module:
2+
module_path: "examples/crossbuild"
3+
matrix:
4+
platform: ["debian10", "macos", "ubuntu2004", "windows"]
5+
bazel: [7.x, 8.x, rolling, last_green]
6+
tasks:
7+
run_tests:
8+
name: "Build and test the example module"
9+
platform: ${{ platform }}
10+
bazel: ${{ bazel }}
11+
build_targets:
12+
- "//..."
13+
test_targets:
14+
- "//..."

.bcr/source.template.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"integrity": "",
3+
"strip_prefix": "{REPO}-{VERSION}",
4+
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{REPO}-{TAG}.tar.gz"
5+
}

.github/workflows/publish-to-bcr.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Publishes to the Bazel Central Registry. See .bcr/README.md.
2+
name: Publish to the Bazel Central Registry
3+
4+
on:
5+
# Run from release.yml.
6+
workflow_call:
7+
inputs:
8+
tag_name:
9+
required: true
10+
type: string
11+
# In case of problems, enable manual dispatch from the GitHub UI.
12+
workflow_dispatch:
13+
inputs:
14+
tag_name:
15+
required: true
16+
type: string
17+
18+
jobs:
19+
publish-to-bcr:
20+
uses: bazel-contrib/publish-to-bcr/.github/workflows/publish.yaml@v0.0.1
21+
with:
22+
tag_name: ${{ inputs.tag_name }}
23+
# bazelbuild/bazel-central-registry fork used to open a pull request.
24+
registry_fork: simuons/bazel-central-registry
25+
permissions:
26+
attestations: write
27+
contents: write
28+
id-token: write
29+
secrets:
30+
# Necessary to push to the BCR fork and open a pull request.
31+
publish_token: ${{ secrets.PUBLISH_TOKEN }}

.github/workflows/release.yml

+10-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ on:
88
- 'v*.*.*'
99

1010
jobs:
11-
build:
11+
release:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v3
1616

1717
- name: Prepare workspace snippet
18-
run: .github/workflows/workspace_snippet.sh ${{ env.GITHUB_REF_NAME }} > release_notes.txt
18+
run: .github/workflows/workspace_snippet.sh ${{ github.ref_name }} > release_notes.txt
1919

2020
- name: Release
2121
uses: softprops/action-gh-release@v1
@@ -25,3 +25,11 @@ jobs:
2525
body_path: release_notes.txt
2626
fail_on_unmatched_files: true
2727
files: rules_scala-*.tar.gz
28+
29+
publish-to-bcr:
30+
needs: release
31+
uses: ./.github/workflows/publish-to-bcr.yml
32+
with:
33+
tag_name: ${{ github.ref_name }}
34+
permissions:
35+
contents: write # allow appending new attestation files to the release

.github/workflows/workspace_snippet.sh

+12-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@ set -o errexit -o nounset -o pipefail
44

55
# Set by GH actions, see
66
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
7-
TAG=${GITHUB_REF_NAME}
8-
PREFIX="rules_scala-${TAG:1}"
7+
TAG="${GITHUB_REF_NAME}"
8+
VERSION="${TAG:1}"
9+
PREFIX="rules_scala-${VERSION}"
910
ARCHIVE="rules_scala-$TAG.tar.gz"
1011
git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip > $ARCHIVE
1112
SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}')
1213

1314
cat << EOF
15+
## Using Bzlmod
16+
17+
Paste this snippet into your \`MODULE.bazel\` file:
18+
19+
\`\`\`starlark
20+
# Set \`repo_name = "io_bazel_rules_scala"\` if you still need it.
21+
bazel_dep(name = "rules_scala", version = "${VERSION}")
22+
\`\`\`
23+
1424
## Using WORKSPACE
1525
1626
Paste this snippet into your \`WORKSPACE\` file:

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ test/semanticdb/tempsrc
1616

1717
# From scripts/create_repository.py
1818
repository-artifacts.json
19+
20+
# Until it settles down
21+
**/MODULE.bazel.lock
22+
23+
# Used by some tests, but can also be used for local experimentation.
24+
tmp/

0 commit comments

Comments
 (0)