Skip to content

Commit

Permalink
chore: upgrade to Bazel 7 (#94)
Browse files Browse the repository at this point in the history
* chore: upgrade to Bazel 7

* chore: cleanup seemingly dead code
  • Loading branch information
alexeagle authored Mar 2, 2024
1 parent df6294d commit a3d9a46
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 227 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Take care to document any settings that you expect users to apply.
# Settings that apply only to CI are in .github/workflows/ci.bazelrc

startup --host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1

# 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.3.2
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
123 changes: 13 additions & 110 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,116 +13,19 @@ on:

concurrency:
# Cancel previous actions from the same PR: https://stackoverflow.com/a/72408109
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
group: concurrency-group::${{ github.workflow }}::${{ github.event.pull_request.number > 0 && format('pr-{0}', github.event.pull_request.number) || github.ref_name }}
cancel-in-progress: ${{ github.ref_name != 'main' }}

jobs:
# matrix-prep-* steps dynamically generate a bit of JSON depending on whether our action has
# access to repository secrets. When running on a pull_request from a fork, the author is
# untrusted so the secret will be absent. Insanely complex for how simple this requirement is...
# inspired from
# https://stackoverflow.com/questions/65384420/how-to-make-a-github-action-matrix-element-conditional

matrix-prep-bazelversion:
# Prepares the 'bazelversion' axis of the test matrix
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: bazel_6
run: echo "bazelversion=$(head -n 1 .bazelversion)" >> $GITHUB_OUTPUT
- id: bazel_5
run: echo "bazelversion=5.3.2" >> $GITHUB_OUTPUT
outputs:
# Will look like ["<version from .bazelversion>", "5.3.2"]
bazelversions: ${{ toJSON(steps.*.outputs.bazelversion) }}

matrix-prep-os:
# Prepares the 'os' axis of the test matrix
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: linux
run: echo "os=ubuntu-latest" >> $GITHUB_OUTPUT
- id: macos
run: echo "os=macos-latest" >> $GITHUB_OUTPUT
# Only run on main branch (not PRs) to minimize macOS minutes (billed at 10X)
# https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions#included-storage-and-minutes
if: ${{ github.ref == 'refs/heads/main' }}
outputs:
# Will look like ["ubuntu-latest", "macos-latest"]
os: ${{ toJSON(steps.*.outputs.os) }}

test:
# The type of runner that the job will run on
runs-on: ${{ matrix.os }}

needs:
- matrix-prep-bazelversion
- matrix-prep-os

strategy:
fail-fast: false
matrix:
os: ${{ fromJSON(needs.matrix-prep-os.outputs.os) }}
bazelversion: ${{ fromJSON(needs.matrix-prep-bazelversion.outputs.bazelversions) }}
bzlmodEnabled: [true, false]
folder:
- '.'
- 'e2e/smoke'
exclude:
# Don't test macos with Bazel 5 to minimize macOS minutes (billed at 10X)
# https://docs.github.com/en/billing/managing-billing-for-github-actions/about-billing-for-github-actions#included-storage-and-minutes
- os: macos-latest
bazelversion: 5.3.2
# Don't test bzlmod with Bazel 5 (not supported)
- bazelversion: 5.3.2
bzlmodEnabled: true
# Broken as Bazel 5 doesn't have @local_config_platform//:constraints.bzl
- bazelversion: 5.3.2
folder: .

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4

# Cache build and external artifacts so that the next ci build is incremental.
# Because github action caches cannot be updated after a build, we need to
# store the contents of each build in a unique cache key, then fall back to loading
# it on the next ci run. We use hashFiles(...) in the key and restore-keys- with
# the prefix to load the most recent cache for the branch on a cache miss. You
# should customize the contents of hashFiles to capture any bazel input sources,
# although this doesn't need to be perfect. If none of the input sources change
# then a cache hit will load an existing cache and bazel won't have to do any work.
# In the case of a cache miss, you want the fallback cache to contain most of the
# previously built artifacts to minimize build time. The more precise you are with
# hashFiles sources the less work bazel will have to do.
- name: Mount bazel caches
uses: actions/cache@v3
with:
path: |
"~/.cache/bazel"
"~/.cache/bazel-repo"
key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE') }}
restore-keys: bazel-cache-

- name: Configure Bazel version
working-directory: ${{ matrix.folder }}
# 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
run: echo "${{ matrix.bazelversion }}" > .bazelversion

- name: Set bzlmod flag
# Store the --enable_bzlmod flag that we add to the test command below
# only when we're running bzlmod in our test matrix.
id: set_bzlmod_flag
if: matrix.bzlmodEnabled
run: echo "bzlmod_flag=--enable_bzlmod" >> $GITHUB_OUTPUT

- name: bazel test //...
env:
# Bazelisk will download bazel to here, ensure it is cached between runs.
XDG_CACHE_HOME: ~/.cache/bazel-repo
working-directory: ${{ matrix.folder }}
run: bazel --bazelrc=$GITHUB_WORKSPACE/.github/workflows/ci.bazelrc --bazelrc=.bazelrc test ${{ steps.set_bzlmod_flag.outputs.bzlmod_flag }} //...
uses: bazel-contrib/.github/.github/workflows/bazel.yaml@v6
with:
folders: |
[
".",
"e2e/smoke"
]
exclude: |
[
{"folder": ".", "bzlmodEnabled": false}
]
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
bazel-*
.bazelrc.user
node_modules

# Don't share 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
MODULE.bazel.lock
30 changes: 26 additions & 4 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ bazel_dep(name = "bazel_skylib", version = "1.3.0")
# Need feat: backport 2.x features for interoperability by @kormide in #657
bazel_dep(name = "aspect_bazel_lib", version = "1.38.0")

# 1.19.0: Need attribute 'dev' in 'npm_package_store_internal' rule
# 1.29.2: Need Windows fix to disable fs patches
# 1.31.1: fix: allow for Bazel 7 flag rename (#1178)
bazel_dep(name = "aspect_rules_js", version = "1.31.0")
# Need feat: import toolchains to use for copy actions by @kormide in #1355
bazel_dep(name = "aspect_rules_js", version = "1.34.0")
bazel_dep(name = "rules_nodejs", version = "5.5.3")
bazel_dep(name = "platforms", version = "0.0.5")

Expand All @@ -25,3 +23,27 @@ rollup.toolchain(
rollup_version = "v2.70.2",
)
use_repo(rollup, "rollup")

bazel_dep(name = "buildifier_prebuilt", version = "6.1.2", dev_dependency = True)

npm = use_extension(
"@aspect_rules_js//npm:extensions.bzl",
"npm",
dev_dependency = True,
)
npm.npm_translate_lock(
name = "npm",
npmrc = "//:.npmrc",
pnpm_lock = "//:pnpm-lock.yaml",
verify_node_modules_ignored = "//:.bazelignore",
)
use_repo(npm, "npm")

# We want the stardoc handling from bazel-lib 2.x for dev use here,
# but not force users to upgrade yet.
archive_override(
module_name = "aspect_bazel_lib",
integrity = "sha256-9ep2aCsgnMC9kND1o7JtL3pqKIXwxfYV5ykT9IBduw0=",
strip_prefix = "bazel-lib-2.5.0",
urls = ["https://github.com/aspect-build/bazel-lib/releases/download/v2.5.0/bazel-lib-v2.5.0.tar.gz"],
)
58 changes: 0 additions & 58 deletions WORKSPACE

This file was deleted.

1 change: 1 addition & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Marker file: this is the root of a Bazel workspace
1 change: 0 additions & 1 deletion e2e/workspace/.bazelignore

This file was deleted.

4 changes: 0 additions & 4 deletions e2e/workspace/.npmrc

This file was deleted.

16 changes: 0 additions & 16 deletions e2e/workspace/BUILD.bazel

This file was deleted.

6 changes: 0 additions & 6 deletions e2e/workspace/package.json

This file was deleted.

25 changes: 0 additions & 25 deletions e2e/workspace/pnpm-lock.yaml

This file was deleted.

2 changes: 0 additions & 2 deletions e2e/workspace/pnpm-workspace.yaml

This file was deleted.

0 comments on commit a3d9a46

Please sign in to comment.