From b5e8cd426e5a2b9f7472e78ebca0403912aa79df Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Fri, 18 Aug 2023 12:25:03 -0700 Subject: [PATCH] chore: bzlmod (#113) * chore: bzlmod * chore: bump minimum rules_js to pick up windows fix * format * green up root bzlmod * exclude buildifier on windows --- .bazelrc | 2 ++ .bcr/README.md | 9 ++++++ .bcr/config.yml | 4 +++ .bcr/metadata.template.json | 13 +++++++++ .bcr/presubmit.yml | 10 +++++++ .bcr/source.template.json | 5 ++++ .github/workflows/ci.yaml | 28 +++++++++++++++++-- .github/workflows/release_prep.sh | 2 +- BUILD.bazel | 1 + MODULE.bazel | 15 ++++++++++ e2e/loaders/.bazelrc | 2 ++ e2e/{workspace => smoke}/.bazelignore | 0 e2e/smoke/.bazelrc | 2 ++ e2e/{workspace => smoke}/.npmrc | 0 e2e/{workspace => smoke}/BUILD.bazel | 0 e2e/smoke/MODULE.bazel | 17 +++++++++++ .../WORKSPACE => smoke/WORKSPACE.bazel} | 0 e2e/smoke/WORKSPACE.bzlmod | 2 ++ e2e/{workspace => smoke}/package.json | 0 e2e/{workspace => smoke}/pnpm-lock.yaml | 0 e2e/{workspace => smoke}/pnpm-workspace.yaml | 0 e2e/{workspace => smoke}/src/BUILD.bazel | 0 e2e/smoke/src/index.js | 3 ++ e2e/smoke/src/module.js | 1 + e2e/worker/.bazelrc | 2 ++ e2e/workspace/.bazelrc | 0 e2e/workspace/src/index.js | 3 -- e2e/workspace/src/module.js | 1 - 28 files changed, 114 insertions(+), 8 deletions(-) create mode 100644 .bcr/README.md create mode 100644 .bcr/config.yml create mode 100644 .bcr/metadata.template.json create mode 100644 .bcr/presubmit.yml create mode 100644 .bcr/source.template.json create mode 100644 MODULE.bazel rename e2e/{workspace => smoke}/.bazelignore (100%) create mode 100644 e2e/smoke/.bazelrc rename e2e/{workspace => smoke}/.npmrc (100%) rename e2e/{workspace => smoke}/BUILD.bazel (100%) create mode 100644 e2e/smoke/MODULE.bazel rename e2e/{workspace/WORKSPACE => smoke/WORKSPACE.bazel} (100%) create mode 100644 e2e/smoke/WORKSPACE.bzlmod rename e2e/{workspace => smoke}/package.json (100%) rename e2e/{workspace => smoke}/pnpm-lock.yaml (100%) rename e2e/{workspace => smoke}/pnpm-workspace.yaml (100%) rename e2e/{workspace => smoke}/src/BUILD.bazel (100%) create mode 100644 e2e/smoke/src/index.js create mode 100644 e2e/smoke/src/module.js delete mode 100644 e2e/workspace/.bazelrc delete mode 100644 e2e/workspace/src/index.js delete mode 100644 e2e/workspace/src/module.js diff --git a/.bazelrc b/.bazelrc index be2739d..edbb86b 100644 --- a/.bazelrc +++ b/.bazelrc @@ -2,6 +2,8 @@ # Take care to document any settings that you expect users to apply. # Settings that apply only to CI are in .github/workflows/ci.bazelrc +# for rules_js +build --enable_runfiles # 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/.bcr/README.md b/.bcr/README.md new file mode 100644 index 0000000..44ae7fe --- /dev/null +++ b/.bcr/README.md @@ -0,0 +1,9 @@ +# Bazel Central Registry + +When the ruleset is released, we want it to be published to the +Bazel Central Registry automatically: + + +This folder contains configuration files to automate the publish step. +See +for authoritative documentation about these files. diff --git a/.bcr/config.yml b/.bcr/config.yml new file mode 100644 index 0000000..5d17a59 --- /dev/null +++ b/.bcr/config.yml @@ -0,0 +1,4 @@ +# See https://github.com/bazel-contrib/publish-to-bcr#a-note-on-release-automation +fixedReleaser: + login: gregmagolan + email: greg@aspect.dev diff --git a/.bcr/metadata.template.json b/.bcr/metadata.template.json new file mode 100644 index 0000000..7249bff --- /dev/null +++ b/.bcr/metadata.template.json @@ -0,0 +1,13 @@ +{ + "homepage": "https://docs.aspect.build/rules/aspect_rules_webpack", + "maintainers": [ + { + "email": "hello@aspect.dev", + "github": "aspect-build", + "name": "Aspect team" + } + ], + "repository": ["github:aspect-build/rules_webpack"], + "versions": [], + "yanked_versions": {} +} diff --git a/.bcr/presubmit.yml b/.bcr/presubmit.yml new file mode 100644 index 0000000..e76a8bb --- /dev/null +++ b/.bcr/presubmit.yml @@ -0,0 +1,10 @@ +bcr_test_module: + module_path: 'e2e/smoke' + matrix: + platform: ['debian10', 'macos', 'ubuntu2004', 'windows'] + tasks: + run_tests: + name: 'Run test module' + platform: ${{ platform }} + test_targets: + - '//...' diff --git a/.bcr/source.template.json b/.bcr/source.template.json new file mode 100644 index 0000000..214f029 --- /dev/null +++ b/.bcr/source.template.json @@ -0,0 +1,5 @@ +{ + "integrity": "**leave this alone**", + "strip_prefix": "{REPO}-{VERSION}", + "url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/rules_webpack-{TAG}.tar.gz" +} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 125ab16..1e9e36a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -42,7 +42,12 @@ jobs: 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' }} + if: github.ref == 'refs/heads/main' + - id: windows + run: echo "os=windows-latest" >> $GITHUB_OUTPUT + # Only run on main branch (or PR branches that contain 'windows') to minimize Windows minutes (billed at 2X) + # 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' || contains(github.head_ref, 'windows') || github.head_ref == 'bzlmod' outputs: # Will look like ["ubuntu-latest", "macos-latest"] os: ${{ toJSON(steps.*.outputs.os) }} @@ -59,17 +64,27 @@ jobs: fail-fast: false matrix: os: ${{ fromJSON(needs.matrix-prep-os.outputs.os) }} + bzlmodEnabled: [true, false] bazelversion: ${{ fromJSON(needs.matrix-prep-bazelversion.outputs.bazelversions) }} folder: - '.' - 'e2e/loaders' - - 'e2e/workspace' + - 'e2e/smoke' - 'e2e/worker' 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 + # TODO + - folder: e2e/loaders + bzlmodEnabled: true + # TODO + - folder: e2e/worker + bzlmodEnabled: true # Steps represent a sequence of tasks that will be executed as part of the job steps: @@ -103,12 +118,19 @@ jobs: # 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 //... + run: bazel --bazelrc=${{ github.workspace }}/.github/workflows/ci.bazelrc --bazelrc=.bazelrc test ${{ steps.set_bzlmod_flag.outputs.bzlmod_flag }} //... - name: run ./test.sh working-directory: ${{ matrix.folder }} diff --git a/.github/workflows/release_prep.sh b/.github/workflows/release_prep.sh index 1c13c8f..645774d 100755 --- a/.github/workflows/release_prep.sh +++ b/.github/workflows/release_prep.sh @@ -23,5 +23,5 @@ http_archive( ) EOF -awk 'f;/--SNIP--/{f=1}' e2e/workspace/WORKSPACE +awk 'f;/--SNIP--/{f=1}' e2e/smoke/WORKSPACE.bazel echo "\`\`\`" \ No newline at end of file diff --git a/BUILD.bazel b/BUILD.bazel index 3387f4b..9005145 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -23,6 +23,7 @@ buildifier( ], lint_mode = "warn", mode = "diff", + tags = ["manual"], # tag as manual so windows ci does not build it by default ) bzl_library( diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 0000000..250a653 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,15 @@ +"aspect-build/rules_webpack" + +module( + name = "aspect_rules_webpack", + version = "0.0.0", + 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 = "gazelle", version = "0.29.0", dev_dependency = True, repo_name = "bazel_gazelle") +bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.4.1", dev_dependency = True) +bazel_dep(name = "buildifier_prebuilt", version = "6.1.2.1", dev_dependency = True) diff --git a/e2e/loaders/.bazelrc b/e2e/loaders/.bazelrc index e69de29..bb7e894 100644 --- a/e2e/loaders/.bazelrc +++ b/e2e/loaders/.bazelrc @@ -0,0 +1,2 @@ +# for rules_js +build --enable_runfiles diff --git a/e2e/workspace/.bazelignore b/e2e/smoke/.bazelignore similarity index 100% rename from e2e/workspace/.bazelignore rename to e2e/smoke/.bazelignore diff --git a/e2e/smoke/.bazelrc b/e2e/smoke/.bazelrc new file mode 100644 index 0000000..bb7e894 --- /dev/null +++ b/e2e/smoke/.bazelrc @@ -0,0 +1,2 @@ +# for rules_js +build --enable_runfiles diff --git a/e2e/workspace/.npmrc b/e2e/smoke/.npmrc similarity index 100% rename from e2e/workspace/.npmrc rename to e2e/smoke/.npmrc diff --git a/e2e/workspace/BUILD.bazel b/e2e/smoke/BUILD.bazel similarity index 100% rename from e2e/workspace/BUILD.bazel rename to e2e/smoke/BUILD.bazel diff --git a/e2e/smoke/MODULE.bazel b/e2e/smoke/MODULE.bazel new file mode 100644 index 0000000..27bf325 --- /dev/null +++ b/e2e/smoke/MODULE.bazel @@ -0,0 +1,17 @@ +"Bazel dependencies" + +bazel_dep(name = "aspect_rules_js", version = "1.29.2") +bazel_dep(name = "bazel_skylib", version = "1.4.1") + +bazel_dep(name = "aspect_rules_webpack", version = "0.0.0", dev_dependency = True) +local_path_override( + module_name = "aspect_rules_webpack", + path = "../..", +) + +npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm") +npm.npm_translate_lock( + name = "npm", + pnpm_lock = "//:pnpm-lock.yaml", +) +use_repo(npm, "npm") diff --git a/e2e/workspace/WORKSPACE b/e2e/smoke/WORKSPACE.bazel similarity index 100% rename from e2e/workspace/WORKSPACE rename to e2e/smoke/WORKSPACE.bazel diff --git a/e2e/smoke/WORKSPACE.bzlmod b/e2e/smoke/WORKSPACE.bzlmod new file mode 100644 index 0000000..fb54e76 --- /dev/null +++ b/e2e/smoke/WORKSPACE.bzlmod @@ -0,0 +1,2 @@ +# Marker file that this is the root of a Bazel workspace. +# This file replaces WORKSPACE.bazel under --enable_bzlmod. diff --git a/e2e/workspace/package.json b/e2e/smoke/package.json similarity index 100% rename from e2e/workspace/package.json rename to e2e/smoke/package.json diff --git a/e2e/workspace/pnpm-lock.yaml b/e2e/smoke/pnpm-lock.yaml similarity index 100% rename from e2e/workspace/pnpm-lock.yaml rename to e2e/smoke/pnpm-lock.yaml diff --git a/e2e/workspace/pnpm-workspace.yaml b/e2e/smoke/pnpm-workspace.yaml similarity index 100% rename from e2e/workspace/pnpm-workspace.yaml rename to e2e/smoke/pnpm-workspace.yaml diff --git a/e2e/workspace/src/BUILD.bazel b/e2e/smoke/src/BUILD.bazel similarity index 100% rename from e2e/workspace/src/BUILD.bazel rename to e2e/smoke/src/BUILD.bazel diff --git a/e2e/smoke/src/index.js b/e2e/smoke/src/index.js new file mode 100644 index 0000000..da7c8f1 --- /dev/null +++ b/e2e/smoke/src/index.js @@ -0,0 +1,3 @@ +import { version } from './module' + +console.log(version) diff --git a/e2e/smoke/src/module.js b/e2e/smoke/src/module.js new file mode 100644 index 0000000..d5a5614 --- /dev/null +++ b/e2e/smoke/src/module.js @@ -0,0 +1 @@ +export const version = '0.0.0' diff --git a/e2e/worker/.bazelrc b/e2e/worker/.bazelrc index e69de29..bb7e894 100644 --- a/e2e/worker/.bazelrc +++ b/e2e/worker/.bazelrc @@ -0,0 +1,2 @@ +# for rules_js +build --enable_runfiles diff --git a/e2e/workspace/.bazelrc b/e2e/workspace/.bazelrc deleted file mode 100644 index e69de29..0000000 diff --git a/e2e/workspace/src/index.js b/e2e/workspace/src/index.js deleted file mode 100644 index e5f8f9a..0000000 --- a/e2e/workspace/src/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import {version} from "./module"; - -console.log(version); \ No newline at end of file diff --git a/e2e/workspace/src/module.js b/e2e/workspace/src/module.js deleted file mode 100644 index e146bd6..0000000 --- a/e2e/workspace/src/module.js +++ /dev/null @@ -1 +0,0 @@ -export const version = "0.0.0" \ No newline at end of file