Skip to content

Commit

Permalink
chore: bzlmod (#72)
Browse files Browse the repository at this point in the history
* chore: bzlmod

* Update WORKSPACE.bzlmod

* fix e2e
  • Loading branch information
alexeagle authored May 9, 2023
1 parent 2ed0ed0 commit 0c21ad9
Show file tree
Hide file tree
Showing 17 changed files with 144 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .bcr/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fixedReleaser:
login: gregmagolan
email: greg@aspect.dev
13 changes: 13 additions & 0 deletions .bcr/metadata.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"homepage": "https://docs.aspect.build/rules/aspect_rules_rollup",
"maintainers": [
{
"email": "hello@aspect.dev",
"github": "aspect-build",
"name": "Aspect team"
}
],
"repository": ["github:aspect-build/rules_rollup"],
"versions": [],
"yanked_versions": {}
}
10 changes: 10 additions & 0 deletions .bcr/presubmit.yml
Original file line number Diff line number Diff line change
@@ -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:
- '//...'
5 changes: 5 additions & 0 deletions .bcr/source.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"integrity": "**leave this alone**",
"strip_prefix": "{REPO}-{VERSION}",
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/rules_rollup-{TAG}.tar.gz"
}
15 changes: 13 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,18 @@ jobs:
matrix:
os: ${{ fromJSON(needs.matrix-prep-os.outputs.os) }}
bazelversion: ${{ fromJSON(needs.matrix-prep-bazelversion.outputs.bazelversions) }}
bzlmodEnabled: [true, false]
folder:
- '.'
- 'e2e/workspace'
- '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

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand Down Expand Up @@ -101,9 +105,16 @@ 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 }} //...
2 changes: 1 addition & 1 deletion .github/workflows/release_prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "\`\`\`"
20 changes: 20 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"aspect-build/rules_rollup"

module(
name = "aspect_rules_rollup",
compatibility_level = 1,
version = "0.0.0",
)

# Lower-bound (minimum) versions of direct dependencies
bazel_dep(name = "bazel_skylib", version = "1.3.0")
# Need #397 to skip stardoc targets
bazel_dep(name = "aspect_bazel_lib", version = "1.30.2")
# Need attribute 'dev' in 'npm_package_store_internal' rule
bazel_dep(name = "aspect_rules_js", version = "1.19.0")
bazel_dep(name = "rules_nodejs", version = "5.5.3")
bazel_dep(name = "platforms", version = "0.0.5")

rollup = use_extension("@aspect_rules_rollup//rollup:extensions.bzl", "rollup")
rollup.toolchain(name = "rollup", rollup_version = "v2.70.2")
use_repo(rollup, "rollup")
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ copy the WORKSPACE snippet into your `WORKSPACE` file.

## Usage

See the API documentation in the [docs](docs/) folder and the example usage in the [example](example/) folder.
See the [API documentation](./docs/rollup) and the example usage in the [example](example/) folder.
Note that the example also relies on code in the `/WORKSPACE` file in the root of this repo.
File renamed without changes.
16 changes: 16 additions & 0 deletions e2e/smoke/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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"],
)
18 changes: 18 additions & 0 deletions e2e/smoke/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"Bazel dependencies"
bazel_dep(name = "aspect_rules_rollup", dev_dependency = True, version = "0.0.0")
bazel_dep(name = "bazel_skylib", dev_dependency = True, version = "1.3.0")
bazel_dep(name = "aspect_rules_js", dev_dependency = True, version = "1.24.1")

local_path_override(
module_name = "aspect_rules_rollup",
path = "../..",
)

npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm")

npm.npm_translate_lock(
name = "npm",
pnpm_lock = "@aspect_rules_rollup//:pnpm-lock.yaml",
)

use_repo(npm, "npm")
4 changes: 4 additions & 0 deletions e2e/smoke/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# smoke test

This e2e exercises the repo from an end-users perpective.
It catches mistakes in our install instructions, or usages that fail when called from an "external" repository to rules_rollup.
4 changes: 1 addition & 3 deletions e2e/workspace/WORKSPACE → e2e/smoke/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ 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",
pnpm_lock = "@aspect_rules_rollup//:pnpm-lock.yaml",
)

load("@npm//:repositories.bzl", "npm_repositories")
Expand Down
2 changes: 2 additions & 0 deletions e2e/smoke/WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Marker file that this is the root of a Bazel workspace
# This file shadows WORKSPACE.bazel when --enable_bzlmod is true
File renamed without changes.
File renamed without changes.
37 changes: 37 additions & 0 deletions rollup/extensions.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"extensions for bzlmod"

load(":repositories.bzl", "rollup_repositories")

rollup_toolchain = tag_class(attrs = {
"name": attr.string(doc = "Base name for generated repositories"),
"rollup_version": attr.string(doc = "Explicit version of rollup."),
# TODO: support this variant
# "rollup_version_from": attr.string(doc = "Location of package.json which may have a version for @rollup/core."),
})

def _toolchain_extension(module_ctx):
registrations = {}
for mod in module_ctx.modules:
for toolchain in mod.tags.toolchain:
if toolchain.name in registrations.keys():
if toolchain.rollup_version == registrations[toolchain.name]:
# No problem to register a matching toolchain twice
continue
fail("Multiple conflicting toolchains declared for name {} ({} and {}".format(
toolchain.name,
toolchain.rollup_version,
registrations[toolchain.name],
))
else:
registrations[toolchain.name] = toolchain.rollup_version
for name, rollup_version in registrations.items():
rollup_repositories(
name = name,
rollup_version = rollup_version,
register = False,
)

rollup = module_extension(
implementation = _toolchain_extension,
tag_classes = {"toolchain": rollup_toolchain},
)

0 comments on commit 0c21ad9

Please sign in to comment.