Skip to content

Commit

Permalink
chore: upgrade to Bazel 7.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan committed Feb 5, 2024
1 parent 110ce47 commit 11cc5e0
Show file tree
Hide file tree
Showing 22 changed files with 269 additions and 67 deletions.
16 changes: 7 additions & 9 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
# Take care to document any settings that you expect users to apply.
# Settings that apply only to CI are in .github/workflows/ci.bazelrc

# Bazel picks up host-OS-specific config lines from bazelrc files. For example, if the host OS is
# Linux and you run bazel build, Bazel picks up lines starting with build:linux. Supported OS
# identifiers are `linux`, `macos`, `windows`, `freebsd`, and `openbsd`. Enabling this flag is
# equivalent to using `--config=linux` on Linux, `--config=windows` on Windows, etc.
# Docs: https://bazel.build/reference/command-line-reference#flag--enable_platform_specific_config
common --enable_platform_specific_config

# Required by rules_js
build --enable_runfiles

# Filter out tests depending on platform
test:windows --test_tag_filters=-no-windows
# Disable lockfile for now. It is unstable.
# https://github.com/bazelbuild/bazel/issues/19026
# https://github.com/bazelbuild/bazel/issues/19621
# https://github.com/bazelbuild/bazel/issues/19971
# https://github.com/bazelbuild/bazel/issues/20272
# https://github.com/bazelbuild/bazel/issues/20369
common --lockfile_mode=off

# Load any settings specific to the current user.
# .bazelrc.user should appear in .gitignore so that settings are not shared with team members
Expand Down
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
6.4.0
7.0.2
# The first line of this file is used by Bazelisk and Bazel to be sure
# the right version of Bazel is used to build and test this repo.
# This also defines which version is used on CI.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/aspect-workflows-warming.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
steps:
- name: Configure environment
run: ${ASPECT_WORKFLOWS_BIN_DIR}/configure_workflows_env
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Agent health checks
run: ${ASPECT_WORKFLOWS_BIN_DIR}/agent_health_check
- name: Create warming archive
Expand Down
17 changes: 10 additions & 7 deletions .github/workflows/ci.bazelrc
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# This file contains Bazel settings to apply on CI only.
# It is referenced with a --bazelrc option in the call to bazel in ci.yaml
# Directories caches by GitHub actions
common --disk_cache=~/.cache/bazel-disk-cache
common --repository_cache=~/.cache/bazel-repository-cache

# Bazel version specific settings
common:bazel6 --build_tag_filters=-skip-on-bazel6
common:bazel6 --test_tag_filters=-skip-on-bazel6
common:bazel7 --build_tag_filters=-skip-on-bazel7
common:bazel7 --test_tag_filters=-skip-on-bazel7

# Debug where options came from
build --announce_rc
# This directory is configured in GitHub actions to be persisted between runs.
build --disk_cache=~/.cache/bazel
build --repository_cache=~/.cache/bazel-repo
# Don't rely on test logs being easily accessible from the test runner,
# though it makes the log noisier.
test --test_output=errors
# Allows tests to run bazelisk-in-bazel, since this is the cache folder used
test --test_env=XDG_CACHE_HOME

# Required by rules_js
build --enable_runfiles
build --enable_runfiles
101 changes: 98 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,102 @@ concurrency:
cancel-in-progress: true

jobs:
# Prepares dynamic test matrix values
matrix-prep:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: bazel-version
name: Prepare 'bazel-version' matrix axis
run: |
v=$(head -n 1 .bazelversion)
m=${v::1}
a=(
"major:$m, version:\"$v\""
"major:6, version:\"6.5.0\""
)
printf -v j '{%s},' "${a[@]}"
echo "res=[${j%,}]" | tee -a $GITHUB_OUTPUT
- id: os
name: Prepare 'os' matrix axis
# Only run MacOS and Windows on main branch (not PRs) to minimize minutes (billed at 10X and 2X respectively)
# https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions#included-storage-and-minutes
run: |
a=( ubuntu )
if [[ "${{ github.ref_name }}" == "main" ]] || [[ "${{ github.head_ref }}" == *"macos"* ]]; then
a+=( macos )
fi
if [[ "${{ github.ref_name }}" == "main" ]] || [[ "${{ github.head_ref }}" == *"windows"* ]]; then
a+=( windows )
fi
printf -v j '"%s",' "${a[@]}"
echo "res=[${j%,}]" | tee -a $GITHUB_OUTPUT
outputs:
bazel-version: ${{ steps.bazel-version.outputs.res }}
os: ${{ steps.os.outputs.res }}

test:
uses: bazel-contrib/.github/.github/workflows/bazel.yaml@v2
with:
folders: '[".", "e2e/jasmine_test", "e2e/smoke"]'
runs-on: ${{ matrix.os }}-latest
needs:
- matrix-prep
strategy:
fail-fast: false
matrix:
bazel-version: ${{ fromJSON(needs.matrix-prep.outputs.bazel-version) }}
bzlmod: [1, 0]
os: ${{ fromJSON(needs.matrix-prep.outputs.os) }}
folder:
- '.'
- 'e2e/jasmine_test'
- 'e2e/smoke'
exclude:
# Don't test MacOS and Windows against secondary bazel version to minimize minutes (billed at 10X and 2X respectively)
# https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions#included-storage-and-minutes
- os: macos
bazel-version:
major: 6
- os: windows
bazel-version:
major: 6

steps:
- uses: actions/checkout@v4

- name: Mount bazel caches
uses: actions/cache@v3
with:
path: |
~/.cache/bazel-disk-cache
~/.cache/bazel-repository-cache
~/.cache/xdg-cache
key: bazel-cache-${{ matrix.bazelversion.version }}-${{ matrix.bzlmod }}-${{ matrix.os }}-${{ matrix.folder }}-${{ hashFiles('.bazelrc', '.bazelversion', '.bazeliskrc', '**/BUILD', '**/BUILD.bazel', '**/*.bzl', 'WORKSPACE', 'WORKSPACE.bazel', 'WORKSPACE.bzlmod', 'MODULE.bazel', 'MODULE.bazel.lock') }}
restore-keys: bazel-cache-${{ matrix.bazelversion.version }}-${{ matrix.bzlmod }}-${{ matrix.os }}-${{ matrix.folder }}-

- name: Configure Bazel version
working-directory: ${{ matrix.folder }}
shell: bash
run: |
# Overwrite the .bazelversion instead of using USE_BAZEL_VERSION so that Bazelisk
# still bootstraps Aspect CLI from configuration in .bazeliskrc. Aspect CLI will
# then use .bazelversion to determine which Bazel version to use.
echo "${{ matrix.bazel-version.version }}" > .bazelversion
# TODO: remove this block once we have Aspect CLI Windows releases
- name: Don't use Aspect CLI on Windows
if: matrix.os == 'windows'
working-directory: ${{ matrix.folder }}
shell: bash
run: rm -f .bazeliskrc

- name: bazel test //...
working-directory: ${{ matrix.folder }}
shell: bash
run: |
bazel \
--bazelrc=${GITHUB_WORKSPACE//\\/\/}/.github/workflows/ci.bazelrc \
test \
--config=bazel${{ matrix.bazel-version.major }} \
--enable_bzlmod=${{ matrix.bzlmod }} \
//...
env:
XDG_CACHE_HOME: ~/.cache/xdg-cache # bazelisk will download bazel to here
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ default_stages: [commit]
repos:
# Check formatting and lint for starlark code
- repo: https://github.com/keith/pre-commit-buildifier
rev: 4.0.1.1
rev: 6.4.0
hooks:
- id: buildifier
- id: buildifier-lint
Expand Down
15 changes: 9 additions & 6 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ module(
compatibility_level = 1,
)

bazel_dep(name = "aspect_bazel_lib", version = "1.32.0")
bazel_dep(name = "aspect_rules_js", version = "1.29.2")
bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "rules_nodejs", version = "5.8.2")
bazel_dep(name = "aspect_bazel_lib", version = "1.40.0")
bazel_dep(name = "aspect_rules_js", version = "1.37.1")
bazel_dep(name = "bazel_features", version = "1.4.1")
bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "rules_nodejs", version = "5.8.3")

bazel_dep(name = "gazelle", version = "0.29.0", dev_dependency = True, repo_name = "bazel_gazelle")
bazel_dep(name = "buildifier_prebuilt", version = "6.0.0.1", dev_dependency = True)
bazel_dep(name = "aspect_rules_lint", version = "0.11.0", dev_dependency = True)
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.4.1", dev_dependency = True)
bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True)
bazel_dep(name = "gazelle", version = "0.35.0", dev_dependency = True, repo_name = "bazel_gazelle")
bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True, repo_name = "io_bazel_stardoc")
23 changes: 22 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,31 @@ load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
############################################
# Stardoc
load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")

stardoc_repositories()

load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")

rules_jvm_external_deps()

load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")

rules_jvm_external_setup()

load("@io_bazel_stardoc//:deps.bzl", "stardoc_external_deps")

stardoc_external_deps()

load("@stardoc_maven//:defs.bzl", stardoc_pinned_maven_install = "pinned_maven_install")

stardoc_pinned_maven_install()

############################################
# Gazelle, for generating bzl_library targets
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()
Expand Down
11 changes: 9 additions & 2 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
# This load statement must be in the docs/ package rather than anything users depend on
# so that the dependency on stardoc doesn't leak to them.
load("@aspect_bazel_lib//lib:docs.bzl", "stardoc_with_diff_test", "update_docs")
load("@aspect_bazel_lib//lib:docs.bzl", "update_docs")
load(":stardoc_with_diff_test.bzl", "stardoc_with_diff_test")

stardoc_with_diff_test(
name = "jasmine_test",
bzl_library_target = "//jasmine:defs",
symbol_names = ["jasmine_test"],
tags = ["skip-on-bazel6"],
)

update_docs(name = "update")
update_docs(
name = "update",
# Failure on Bazel 6.5.0 with bzlmod enabled with unknown root cause not worth investigating:
# "Stardoc documentation generation failed: File /home/runner/.cache/bazel/_bazel_runner/49ae4abee64f46f5e03b51e3020410d1/sandbox/linux-sandbox/168/execroot/_main/bazel-out/k8-opt-exec-2B5CBBC6/bin/docs/jasmine_test_stardoc.runfiles/_main/jasmine/private/jasmine_test.bzl imported '@aspect_rules_js//js:libs.bzl', yet /home/runner/.cache/bazel/_bazel_runner/49ae4abee64f46f5e03b51e3020410d1/sandbox/linux-sandbox/168/execroot/_main/bazel-out/k8-opt-exec-2B5CBBC6/bin/docs/jasmine_test_stardoc.runfiles/aspect_rules_js/js/libs.bzl was not found."
tags = ["skip-on-bazel6"],
)

# Demonstration delivery target for Aspect Workflows.
# In the future this could be wired up to push to a demonstration S3 bucket.
Expand Down
14 changes: 7 additions & 7 deletions docs/jasmine_test.md

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

37 changes: 37 additions & 0 deletions docs/stardoc_with_diff_test.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"Fork of aspect_bazel_lib stardoc_with_diff_test"

load("@io_bazel_stardoc//stardoc:stardoc.bzl", _stardoc = "stardoc")

# Fork of stardoc_with_diff_test that allows for additional tags
# TODO: upstream this to aspect_bazel_lib
def stardoc_with_diff_test(
name,
bzl_library_target,
**kwargs):
"""Creates a stardoc target that can be auto-detected by update_docs to write the generated doc to the source tree and test that it's up to date.
This is helpful for minimizing boilerplate in repos wih lots of stardoc targets.
Args:
name: the name of the stardoc file to be written to the current source directory (.md will be appended to the name). Call bazel run on this target to update the file.
bzl_library_target: the label of the `bzl_library` target to generate documentation for
**kwargs: additional attributes passed to the stardoc() rule, such as for overriding the templates
"""

target_compatible_with = kwargs.pop("target_compatible_with", select({
# stardoc produces different line endings on Windows
# which makes the diff_test fail
"@platforms//os:windows": ["@platforms//:incompatible"],
"//conditions:default": [],
}))

# Generate MD from .bzl
_stardoc(
name = name,
out = name + "-docgen.md",
input = bzl_library_target + ".bzl",
deps = [bzl_library_target],
tags = kwargs.pop("tags", []) + ["package:" + native.package_name()], # Tag the package name which will help us reconstruct the write_source_files label in update_docs
target_compatible_with = target_compatible_with,
**kwargs
)
7 changes: 7 additions & 0 deletions e2e/jasmine_test/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Disable lockfile for now. It is unstable.
# https://github.com/bazelbuild/bazel/issues/19026
# https://github.com/bazelbuild/bazel/issues/19621
# https://github.com/bazelbuild/bazel/issues/19971
# https://github.com/bazelbuild/bazel/issues/20272
# https://github.com/bazelbuild/bazel/issues/20369
common --lockfile_mode=off
1 change: 1 addition & 0 deletions e2e/jasmine_test/.bazelversion
8 changes: 8 additions & 0 deletions e2e/smoke/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@
# 2. The system version is Windows 10 Creators Update (1703) or later
# and developer mode is enabled.
build --enable_runfiles

# Disable lockfile for now. It is unstable.
# https://github.com/bazelbuild/bazel/issues/19026
# https://github.com/bazelbuild/bazel/issues/19621
# https://github.com/bazelbuild/bazel/issues/19971
# https://github.com/bazelbuild/bazel/issues/20272
# https://github.com/bazelbuild/bazel/issues/20369
common --lockfile_mode=off
1 change: 1 addition & 0 deletions e2e/smoke/.bazelversion
2 changes: 1 addition & 1 deletion e2e/smoke/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local_path_override(
path = "../..",
)

bazel_dep(name = "aspect_rules_js", version = "1.29.2")
bazel_dep(name = "aspect_rules_js", version = "1.37.1")

bazel_dep(name = "aspect_rules_jasmine", version = "0.0.0", dev_dependency = True)

Expand Down
Loading

0 comments on commit 11cc5e0

Please sign in to comment.