diff --git a/.bazelrc b/.bazelrc index 86581a6..392f098 100644 --- a/.bazelrc +++ b/.bazelrc @@ -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 diff --git a/.bazelversion b/.bazelversion index 6c7efdc..69f2020 100644 --- a/.bazelversion +++ b/.bazelversion @@ -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. diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 47a9f7f..4f889c1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 ["", "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} + ] diff --git a/.gitignore b/.gitignore index 4351251..374e714 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/MODULE.bazel b/MODULE.bazel index 8bb7370..5ce5228 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -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") @@ -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"], +) diff --git a/WORKSPACE b/WORKSPACE deleted file mode 100644 index cbb451f..0000000 --- a/WORKSPACE +++ /dev/null @@ -1,58 +0,0 @@ -# Declare the local Bazel workspace. -workspace(name = "aspect_rules_rollup") - -# Fetch deps needed only locally for development -load(":internal_deps.bzl", "rules_rollup_internal_deps") - -rules_rollup_internal_deps() - -load("//rollup:dependencies.bzl", "rules_rollup_dependencies") - -# Fetch dependencies which users need as well -rules_rollup_dependencies() - -load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies") - -rules_js_dependencies() - -load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains") - -nodejs_register_toolchains( - name = "nodejs", - node_version = "16.9.0", -) - -load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock") - -npm_translate_lock( - name = "npm", - npmrc = "//:.npmrc", - pnpm_lock = "//:pnpm-lock.yaml", - verify_node_modules_ignored = "//:.bazelignore", -) - -load("@npm//:repositories.bzl", "npm_repositories") - -npm_repositories() - -load("@aspect_bazel_lib//lib:repositories.bzl", "DEFAULT_YQ_VERSION", "aspect_bazel_lib_dependencies", "register_yq_toolchains") - -aspect_bazel_lib_dependencies() - -register_yq_toolchains( - version = DEFAULT_YQ_VERSION, -) - -# For running our own unit tests -load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") - -bazel_skylib_workspace() - -# Buildifier -load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps") - -buildifier_prebuilt_deps() - -load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains") - -buildifier_prebuilt_register_toolchains() diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel new file mode 100644 index 0000000..64d7fc0 --- /dev/null +++ b/WORKSPACE.bazel @@ -0,0 +1 @@ +# Marker file: this is the root of a Bazel workspace diff --git a/e2e/workspace/.bazelignore b/e2e/workspace/.bazelignore deleted file mode 100644 index 3c3629e..0000000 --- a/e2e/workspace/.bazelignore +++ /dev/null @@ -1 +0,0 @@ -node_modules diff --git a/e2e/workspace/.npmrc b/e2e/workspace/.npmrc deleted file mode 100644 index 5de6efa..0000000 --- a/e2e/workspace/.npmrc +++ /dev/null @@ -1,4 +0,0 @@ -# Disabling pnpm [hoisting](https://pnpm.io/npmrc#hoist) by setting `hoist=false` is recommended on -# projects using rules_js so that pnpm outside of Bazel lays out a node_modules tree similar to what -# rules_js lays out under Bazel (without a hidden node_modules/.pnpm/node_modules) -hoist=false diff --git a/e2e/workspace/BUILD.bazel b/e2e/workspace/BUILD.bazel deleted file mode 100644 index 5298ad1..0000000 --- a/e2e/workspace/BUILD.bazel +++ /dev/null @@ -1,16 +0,0 @@ -load("@aspect_rules_rollup//rollup:defs.bzl", "rollup") -load("@bazel_skylib//rules:build_test.bzl", "build_test") -load("@npm//:defs.bzl", "npm_link_all_packages") - -npm_link_all_packages(name = "node_modules") - -rollup( - name = "bundle", - entry_point = "main.js", - node_modules = "//:node_modules", -) - -build_test( - name = "test", - targets = [":bundle"], -) diff --git a/e2e/workspace/package.json b/e2e/workspace/package.json deleted file mode 100644 index a45d6c1..0000000 --- a/e2e/workspace/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "private": true, - "devDependencies": { - "rollup": "3.20.0" - } -} diff --git a/e2e/workspace/pnpm-lock.yaml b/e2e/workspace/pnpm-lock.yaml deleted file mode 100644 index 0576178..0000000 --- a/e2e/workspace/pnpm-lock.yaml +++ /dev/null @@ -1,25 +0,0 @@ -lockfileVersion: 5.4 - -specifiers: - rollup: 3.20.0 - -devDependencies: - rollup: 3.20.0 - -packages: - - /fsevents/2.3.2: - resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==} - engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} - os: [darwin] - requiresBuild: true - dev: true - optional: true - - /rollup/3.20.0: - resolution: {integrity: sha512-YsIfrk80NqUDrxrjWPXUa7PWvAfegZEXHuPsEZg58fGCdjL1I9C1i/NaG+L+27kxxwkrG/QEDEQc8s/ynXWWGQ==} - engines: {node: '>=14.18.0', npm: '>=8.0.0'} - hasBin: true - optionalDependencies: - fsevents: 2.3.2 - dev: true diff --git a/e2e/workspace/pnpm-workspace.yaml b/e2e/workspace/pnpm-workspace.yaml deleted file mode 100644 index 2cce0eb..0000000 --- a/e2e/workspace/pnpm-workspace.yaml +++ /dev/null @@ -1,2 +0,0 @@ -packages: - - '.'