Skip to content

Commit

Permalink
Add gazelle plugin to CI and distribution mechanism (#424)
Browse files Browse the repository at this point in the history
After #400, the gazelle plugin has been cleanly separated out into its own bazel workspace, which will soon finally allow us to mark it stable. But this means:

* we need to change our bazelci config to explicitly build and test it, since `bazel build //...` no longer includes the plugin;
* we need to add proper distribution rules for it;
* we need to update release instructions, since now we will have two distribution tarballs
  • Loading branch information
tetromino committed Jan 20, 2023
1 parent 5bfcb1a commit 99a6bcb
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 93 deletions.
57 changes: 19 additions & 38 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
@@ -1,109 +1,90 @@
---
.reusable_config: &reusable_config
build_targets:
- "--"
- "//..."
- "@bazel_skylib_gazelle_plugin//..."
test_targets:
- "--"
- "//..."
- "@bazel_skylib_gazelle_plugin//..."

tasks:
ubuntu1804_latest:
<<: *reusable_config
name: "Latest Bazel"
platform: ubuntu1804
bazel: latest
build_targets:
- "//..."
test_targets:
- "//..."
test_flags:
- "--test_env=PATH"

ubuntu1604_latest:
<<: *reusable_config
name: "Latest Bazel"
platform: ubuntu1604
bazel: latest
build_targets:
- "//..."
test_targets:
- "//..."
test_flags:
- "--test_env=PATH"

macos_latest:
<<: *reusable_config
name: "Latest Bazel"
platform: macos
bazel: latest
build_targets:
- "//..."
test_targets:
- "//..."
test_flags:
- "--test_env=PATH"

windows_latest:
<<: *reusable_config
name: "Latest Bazel"
platform: windows
bazel: latest
build_targets:
- "//..."
test_targets:
- "--"
- "//..."
test_flags:
# TODO(laszlocsomor): remove "--test_env=LOCALAPPDATA" after
# https://github.com/bazelbuild/bazel/issues/7761 is fixed
- "--test_env=LOCALAPPDATA"
- "--test_tag_filters=-no_windows"

ubuntu1804_last_green:
<<: *reusable_config
name: "Last Green Bazel"
platform: ubuntu1804
bazel: last_green
build_targets:
- "//..."
test_targets:
- "//..."
test_flags:
- "--test_env=PATH"

ubuntu1604_last_green:
<<: *reusable_config
name: "Last Green Bazel"
platform: ubuntu1604
bazel: last_green
build_targets:
- "//..."
test_targets:
- "//..."
test_flags:
- "--test_env=PATH"

macos_last_green:
<<: *reusable_config
name: "Last Green Bazel"
platform: macos
bazel: last_green
build_targets:
- "//..."
test_targets:
- "//..."
test_flags:
- "--test_env=PATH"

windows_last_green:
<<: *reusable_config
name: "Last Green Bazel"
platform: windows
bazel: last_green
build_targets:
- "//..."
test_targets:
- "--"
- "//..."
test_flags:
# TODO(laszlocsomor): remove "--test_env=LOCALAPPDATA" after
# https://github.com/bazelbuild/bazel/issues/7761 is fixed
- "--test_env=LOCALAPPDATA"
- "--test_tag_filters=-no_windows"

ubuntu1804_last_green_bzlmod:
<<: *reusable_config
name: "Last Green Bazel (with bzlmod)"
platform: ubuntu1804
bazel: last_green
build_targets:
- "//..."
test_targets:
- "//..."
build_flags:
- "--experimental_enable_bzlmod"
test_flags:
Expand Down
19 changes: 14 additions & 5 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module(
name = "bazel_skylib",
compatibility_level = 1,
# If you change this, please also update @bazel_skylib_gazelle_plugin//:MODULE.bazel
# Keep in sync with version.bzl and @bazel_skylib_gazelle_plugin//:MODULE.bazel
version = "1.3.0",
compatibility_level = 1,
)

register_toolchains(
Expand All @@ -15,6 +15,15 @@ bazel_dep(name = "platforms", version = "0.0.4")
### INTERNAL ONLY - lines after this are not included in the release packaging.

# Build-only / test-only dependencies
bazel_dep(name = "stardoc", dev_dependency = True, repo_name = "io_bazel_stardoc", version = "0.5.3")
bazel_dep(name = "rules_pkg", dev_dependency = True, version = "0.5.1")
bazel_dep(name = "rules_cc", dev_dependency = True, version = "0.0.2")
bazel_dep(name = "stardoc", version = "0.5.3", dev_dependency = True, repo_name = "io_bazel_stardoc")
bazel_dep(name = "rules_pkg", version = "0.7.0", dev_dependency = True)
bazel_dep(name = "rules_cc", version = "0.0.2", dev_dependency = True)

# Needed for bazelci and for building distribution tarballs.
# If using an unreleased version of bazel_skylib via git_override, apply
# MODULE.bazel-remove-override.patch to remove the following lines:
bazel_dep(name = "bazel_skylib_gazelle_plugin", dev_dependency = True)
local_path_override(
module_name = "bazel_skylib_gazelle_plugin",
path = "gazelle",
)
16 changes: 16 additions & 0 deletions MODULE.bazel-remove-override.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--- MODULE.bazel
+++ MODULE.bazel
@@ -22,8 +22,8 @@
# Needed for bazelci and for building distribution tarballs.
# If using an unreleased version of bazel_skylib via git_override, apply
# MODULE.bazel-remove-override.patch to remove the following lines:
-bazel_dep(name = "bazel_skylib_gazelle_plugin", dev_dependency = True)
-local_path_override(
- module_name = "bazel_skylib_gazelle_plugin",
- path = "gazelle",
-)
+# bazel_dep(name = "bazel_skylib_gazelle_plugin", dev_dependency = True)
+# local_path_override(
+# module_name = "bazel_skylib_gazelle_plugin",
+# path = "gazelle",
+# )
6 changes: 3 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ stardoc_repositories()
maybe(
http_archive,
name = "rules_pkg",
sha256 = "a89e203d3cf264e564fcb96b6e06dd70bc0557356eb48400ce4b5d97c2c3720d",
sha256 = "8a298e832762eda1830597d64fe7db58178aa84cd5926d76d5b744d6558941c2",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.5.1/rules_pkg-0.5.1.tar.gz",
"https://github.com/bazelbuild/rules_pkg/releases/download/0.5.1/rules_pkg-0.5.1.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.7.0/rules_pkg-0.7.0.tar.gz",
"https://github.com/bazelbuild/rules_pkg/releases/download/0.7.0/rules_pkg-0.7.0.tar.gz",
],
)

Expand Down
44 changes: 33 additions & 11 deletions distribution/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("@bazel_skylib//:version.bzl", "version")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@rules_pkg//releasing:defs.bzl", "print_rel_notes")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")

package(
default_visibility = ["//visibility:private"],
Expand All @@ -13,25 +13,47 @@ genrule(
cmd = "sed -e '/### INTERNAL ONLY/,$$d' $(location //:MODULE.bazel) >$@",
)

# Build the artifact to put on the github release page.
# Build the artifacts to put on the github release page.
pkg_tar(
name = "bazel-skylib-%s" % version,
name = "bazel-skylib",
srcs = [
"distro_module_bazel",
"//:distribution",
],
out = "bazel-skylib-%s.tar.gz" % version,
extension = "tar.gz",
mode = "0644",
# Make it owned by root so it does not have the uid of the CI robot.
owner = "0.0",
strip_prefix = ".",
strip_prefix = strip_prefix.from_root(),
)

print_rel_notes(
name = "relnotes",
outs = ["relnotes.txt"],
deps_method = "bazel_skylib_workspace",
repo = "bazel-skylib",
setup_file = ":workspace.bzl",
version = version,
pkg_files(
name = "bazel-skylib-gazelle-plugin-without-external-prefix",
srcs = [
"@bazel_skylib_gazelle_plugin//:distribution",
"@bazel_skylib_gazelle_plugin//bzl:distribution",
],
strip_prefix = strip_prefix.from_root(),
)

pkg_tar(
name = "bazel-skylib-gazelle-plugin",
srcs = [
":bazel-skylib-gazelle-plugin-without-external-prefix",
"//:LICENSE",
],
out = "bazel-skylib-gazelle-plugin-%s.tar.gz" % version,
extension = "tar.gz",
mode = "0644",
# Make it owned by root so it does not have the uid of the CI robot.
owner = "0.0",
)

filegroup(
name = "distribution",
srcs = [
"bazel-skylib",
"bazel-skylib-gazelle-plugin",
],
)
36 changes: 22 additions & 14 deletions docs/maintainers_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,33 @@ Name 1, Name 2, Name 3 (alphabetically from `git log`)

--------------------------------------------------------------------------------

2. Bump `version` in version.bzl *and* MODULE.bazel to the new version.
TODO(#386): add a test to make sure the two versions are in sync.
2. Bump `version` in version.bzl, MODULE.bazel, *and* gazelle/MODULE.bazel to
the new version.
TODO(#386): add a test to make sure all the versions are in sync.
3. Ensure that the commits for steps 1 and 2 have been merged. All further
steps must be performed on a single, known-good git commit.
4. `bazel build //distribution:bazel-skylib-$VERSION.tar.gz`
5. Copy the `bazel-skylib-$VERSION.tar.gz` tarball to the mirror (you'll need
Bazel developer gcloud credentials; assuming you are a Bazel developer, you
can obtain them via `gcloud init`):

```
gsutil cp bazel-bin/distribution/bazel-skylib-$VERSION.tar.gz gs://bazel-mirror/github.com/bazelbuild/bazel-skylib/releases/download/$VERSION/bazel-skylib-$VERSION.tar.gz
gsutil setmeta -h "Cache-Control: public, max-age=31536000" "gs://bazel-mirror/github.com/bazelbuild/bazel-skylib/releases/download/$VERSION/bazel-skylib-$VERSION.tar.gz"
4. `bazel build //distribution`
5. Copy the `bazel-skylib-$VERSION.tar.gz` and
`bazel-skylib-gazelle-plugin-$VERSION.tar.gz` tarballs to the mirror (you'll
need Bazel developer gcloud credentials; assuming you are a Bazel developer,
you can obtain them via `gcloud init`):

```bash
gsutil cp bazel-bin/distribution/bazel-skylib{,-gazelle-plugin}-$VERSION.tar.gz gs://bazel-mirror/github.com/bazelbuild/bazel-skylib/releases/download/$VERSION/
gsutil setmeta -h "Cache-Control: public, max-age=31536000" gs://bazel-mirror/github.com/bazelbuild/bazel-skylib/releases/download/$VERSION/bazel-skylib{,-gazelle-plugin}-$VERSION.tar.gz
```

6. Run `sha256sum bazel-bin/distro/bazel-skylib-$VERSION.tar.gz`; you'll need
the checksum for the release notes.
6. Obtain checksums for release notes:

```bash
sha256sum bazel-bin/distro/bazel-skylib-$VERSION.tar.gz
sha256sum bazel-bin/distro/bazel-skylib-gazelle-plugin-$VERSION.tar.gz
````

7. Draft a new release with a new tag named $VERSION in github. Attach
`bazel-skylib-$VERSION.tar.gz` to the release. For the release notes, use
the CHANGELOG.md entry plus the following template:
`bazel-skylib-$VERSION.tar.gz` and
`bazel-skylib-gazelle-plugin-$VERSION.tar.gz` to the release. For the
release notes, use the CHANGELOG.md entry plus the following template:

--------------------------------------------------------------------------------

Expand Down
22 changes: 10 additions & 12 deletions gazelle/BUILD
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

# The files needed for distribution
filegroup(
name = "distribution",
srcs = glob(
["*"],
allow_empty = True,
),
visibility = [
"//:__pkg__",
],
)

bzl_library(
name = "setup",
srcs = ["setup.bzl"],
Expand All @@ -32,3 +20,13 @@ bzl_library(
"@bazel_tools//tools/build_defs/repo:utils.bzl",
],
)

# TODO(arostovtsev): exclude everything below from distro tarball
filegroup(
name = "distribution",
srcs = glob(
["*"],
allow_empty = True,
),
visibility = ["//visibility:public"],
)
11 changes: 5 additions & 6 deletions gazelle/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
module(
name = "bazel_skylib_gazelle_plugin",
compatibility_level = 1,
# If you change this, please also update @bazel_gazelle//:MODULE.bazel
# Keep in sync with @bazel_skylib//:MODULE.bazel and @bazel_skylib//:version.bzl
version = "1.3.0",
compatibility_level = 1,
)

# Keep in sync with @bazel_skylib//:MODULE.bazel and @bazel_skylib//:version.bzl
bazel_dep(name = "bazel_skylib", version = "1.3.0")
bazel_dep(name = "gazelle", repo_name = "bazel_gazelle", version = "0.28.0")
bazel_dep(name = "rules_go", repo_name = "io_bazel_rules_go", version = "0.35.0")
bazel_dep(name = "gazelle", version = "0.28.0", repo_name = "bazel_gazelle")
bazel_dep(name = "rules_go", version = "0.35.0", repo_name = "io_bazel_rules_go")

# `rules_go` will register a toolchain for us if the user doesn't do so

go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps")

go_deps.module(
path = "github.com/bazelbuild/buildtools",
sum = "h1:fmdo+fvvWlhldUcqkhAMpKndSxMN3vH5l7yow5cEaiQ=",
version = "v0.0.0-20220531122519-a43aed7014c8",
)

use_repo(go_deps, "com_github_bazelbuild_buildtools")
7 changes: 3 additions & 4 deletions gazelle/bzl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ gazelle(
gazelle = ":gazelle-skylib",
)

# TODO(arostovtsev): exclude everything below from distro tarball

# The files needed for distribution
# A fake testdata directory is created so that
# the build file has nothing missing, but we
Expand All @@ -62,10 +64,7 @@ filegroup(
"BUILD",
":fake-testdata",
],
visibility = [
"//:__pkg__",
"//distribution:__pkg__",
],
visibility = ["//visibility:public"],
)

genrule(
Expand Down
1 change: 1 addition & 0 deletions version.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
# limitations under the License.
"""The version of bazel-skylib."""

# Keep in sync with MODULE.bazel and @bazel_skylib_gazelle_plugin//:MODULE.bazel
version = "1.3.0"

0 comments on commit 99a6bcb

Please sign in to comment.