Skip to content

Commit

Permalink
test(rules_release): Bazel integration test for setting up using a WO…
Browse files Browse the repository at this point in the history
…RKSPACE file (#612)
  • Loading branch information
mvgijssel authored Dec 5, 2023
1 parent 0adc127 commit 3f6eca4
Show file tree
Hide file tree
Showing 71 changed files with 2,021 additions and 294 deletions.
6 changes: 6 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Ignore the convenience symlink due to VSCode issue

# fix described here https://github.com/bazelbuild/bazel/issues/10653

bazel-setup
Expand All @@ -12,3 +13,8 @@ node_modules

rules/rules_task
rules/rules_release

bazel-bin
bazel-out
bazel-testlogs
bazel-setup
4 changes: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ build --java_runtime_version=remotejdk_11
build:quiet --ui_event_filters=-info --noshow_progress
query:quiet --ui_event_filters=-info --noshow_progress

# Move the bazel symlinks outside of the project root to avoid the symlinks appearing in the volume mount
build --symlink_prefix=/tmp/bazel-setup-
# Disable the bazel symlinks
common --experimental_convenience_symlinks=ignore

# Print warning messages about test suite being configured as too small/big
test --test_verbose_timeout_warnings
Expand Down
5 changes: 5 additions & 0 deletions .changeset/rules_release-quick-cheetahs-thank-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rules_release": major
---

BREAKING CHANGE: Extracted bazel-diff from release manager and introduced `bazel_diff_release` rule.
5 changes: 5 additions & 0 deletions .changeset/rules_release-quick-cheetahs-thank-3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rules_release": patch
---

build: Updated release template to include WORKSPACE setup
5 changes: 5 additions & 0 deletions .changeset/rules_release-quick-cheetahs-thank-4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rules_release": major
---

BREAKING CHANGE: Move `bazel_diff_release` and `publish_github_release` from release/defs.bzl to tools/defs.bzl.
5 changes: 5 additions & 0 deletions .changeset/rules_release-quick-cheetahs-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rules_release": patch
---

test: Add integration test for a WORKSPACE setup
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ infrastructure/kubernetes_config.yaml
infrastructure/stacks/provisioner/Pulumi.dev.yaml

# For Bazel
bazel-bin
bazel-out
bazel-setup
bazel-testlogs
bazel-*
cache

# Entries below this point are managed by Please (DO NOT EDIT)
Expand Down
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@
},
"python.formatting.provider": "none",
"devbox.autoShellOnTerminal": true,
"nix.enableLanguageServer": false
"nix.enableLanguageServer": false,
"files.exclude": {
"**/bazel-*": true
}
}
1 change: 0 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ task(

release_manager(
name = "release_manager",
bazel_diff_args = "--fineGrainedHashExternalRepos=rules_release,rules_task",
publish_cmds = [
":push_git_changes",
],
Expand Down
2 changes: 1 addition & 1 deletion buildbuddy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ actions:
- "*"
bazel_commands:
- bazel run //:setup_ci
- bazel test --keep_going //... @rules_task//... --config buildbuddy --config buildbuddy_rbe
- bazel test --keep_going //... @rules_task//... @rules_release//... --config buildbuddy --config buildbuddy_rbe

- name: "Release all targets"
user: buildbuddy
Expand Down
3 changes: 2 additions & 1 deletion rules/rules_release/.bazelignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
examples/workspace
5 changes: 4 additions & 1 deletion rules/rules_release/.bazelrc
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
common --enable_bzlmod=true
common --enable_bzlmod=true

# Disable the bazel symlinks
common --experimental_convenience_symlinks=ignore
1 change: 1 addition & 0 deletions rules/rules_release/.bazelversion
60 changes: 13 additions & 47 deletions rules/rules_release/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@aspect_rules_js//js:defs.bzl", "js_binary")
load("@rules_java//java:defs.bzl", "java_binary")
load("@rules_task//task:defs.bzl", "cmd")
load("//release:defs.bzl", "publish_github_release", "release")
load("//tools:defs.bzl", "publish_github_release", release = "bazel_diff_release")
load("@aspect_bazel_lib//lib:tar.bzl", "mtree_spec", "tar")
load("@npm//:defs.bzl", "npm_link_all_packages")

npm_link_all_packages()

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -37,54 +37,13 @@ config_setting(
constraint_values = _darwin_arm64,
)

npm_link_all_packages()

java_binary(
name = "bazel-diff",
main_class = "com.bazel_diff.Main",
runtime_deps = ["@bazel_diff//jar"],
)

js_binary(
name = "cli",
data = [
"lib/actions/GenerateAction.mjs",
"lib/actions/PublishAction.mjs",
"lib/actions/VersionAction.mjs",
"lib/repositories/ChangelogRepository.mjs",
"lib/repositories/ChangesetRepository.mjs",
"lib/repositories/ConfigRepository.mjs",
"lib/repositories/PackageRepository.mjs",
"lib/repositories/PublishRepository.mjs",
"lib/repositories/ReleaseRepository.mjs",
"lib/repositories/TargetRepository.mjs",
"lib/repositories/VersionRepository.mjs",
"lib/utils.mjs",
"//:node_modules/@changesets/write",
"//:node_modules/commander",
"//:node_modules/zx",
],
entry_point = "cli.mjs",
env = {
"WORKSPACE_NAME": repository_name().removeprefix("@"),
},
)

js_binary(
name = "changesets_cli",
data = [
"//:node_modules/@changesets/changelog-github",
"//:node_modules/@changesets/cli",
"//:node_modules/zx",
],
entry_point = "changesets_cli.mjs",
)

filegroup(
name = "all_files",
srcs = glob(["**/*"]) + [
"//release:all_files",
"//release/private:all_files",
"//tools:all_files",
"//tools/private:all_files",
],
)

Expand Down Expand Up @@ -126,6 +85,7 @@ genrule(
":release.version_changelog",
":release.version",
":release_archive",
"@examples_workspace//:WORKSPACE",
],
outs = [
"github_release_template.txt",
Expand All @@ -135,6 +95,9 @@ export VERSION="v$$(cat $(location :release.version))"
export SHA=$$(shasum -a 256 $(location :release_archive) | awk '{print $$1}')
export PREFIX="rules_release-$${VERSION}"
export ARCHIVE="rules_release.tar.gz"
export WORKSPACE_CONTENT=$$(cat $(location @examples_workspace//:WORKSPACE))
export SEARCH_TARGET_LINE="#### Generic for each workspace file"
export FILTERED_WORKSPACE_CONTENT=$$(echo "$$WORKSPACE_CONTENT" | sed "1,/$$SEARCH_TARGET_LINE/d")
cat <<EOF > $(OUTS)
## Using WORKSPACE:
Expand All @@ -147,6 +110,8 @@ http_archive(
sha256 = "$${SHA}",
url = "https://github.com/vgijssel/setup/releases/download/$${PREFIX}/$${ARCHIVE}",
)
$$FILTERED_WORKSPACE_CONTENT
\\`\\`\\`
EOF
Expand All @@ -173,6 +138,7 @@ publish_github_release(
release(
name = "release",
changelog_file = "CHANGELOG.md",
generate_hashes_extra_args = ["--fineGrainedHashExternalRepos=rules_release"],
publish_cmds = [
":publish_github_release",
],
Expand Down
24 changes: 23 additions & 1 deletion rules/rules_release/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module(
version = "0.0.0",
)

non_module_dependencies = use_extension(":extensions.bzl", "non_module_dependencies")
non_module_dependencies = use_extension("//release:extensions.bzl", "non_module_dependencies")

# ------------------------------------ platforms ------------------------------------ #
bazel_dep(name = "platforms", version = "0.0.8")
Expand Down Expand Up @@ -42,6 +42,9 @@ use_repo(non_module_dependencies, "onepassword_linux_amd64")

use_repo(non_module_dependencies, "onepassword_darwin_arm64")

# ------------------------------------ examples ------------------------------------ #
use_repo(non_module_dependencies, "examples_workspace")

# ------------------------------------ rules_js ------------------------------------ #
bazel_dep(
name = "aspect_rules_js",
Expand Down Expand Up @@ -81,3 +84,22 @@ local_path_override(
module_name = "rules_task",
path = "../rules_task",
)

# ------------------------------------ rules_bazel_integration_test ------------------------------------ #
bazel_dep(
name = "rules_bazel_integration_test",
version = "0.20.0",
)

bazel_binaries = use_extension(
"@rules_bazel_integration_test//:extensions.bzl",
"bazel_binaries",
)

bazel_binaries.download(version_file = "//:.bazelversion")

use_repo(bazel_binaries, "bazel_binaries")

use_repo(bazel_binaries, "bazel_binaries_bazelisk")

use_repo(bazel_binaries, "build_bazel_bazel_.bazelversion")
36 changes: 36 additions & 0 deletions rules/rules_release/examples/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
load("@bazel_binaries//:defs.bzl", "bazel_binaries")
load(
"@rules_bazel_integration_test//bazel_integration_test:defs.bzl",
"bazel_integration_test",
"default_test_runner",
"integration_test_utils",
)

# if the tests are executed from setup repository then the path is ../../../rules_release~override
# if it's executed from the rules_release repository then the path is ../../
rules_release_repository_path = "../../" if repository_name() == "@" else "../rules_release~override"

rules_task_repository_path = "../rules_task~override"

default_test_runner(
name = "workspace_test_runner",
bazel_cmds = [
"info --override_repository=rules_release={} --override_repository=rules_task={}".format(rules_release_repository_path, rules_task_repository_path),
"test --override_repository=rules_release={} --override_repository=rules_task={} //...".format(rules_release_repository_path, rules_task_repository_path),
],
)

integration_test_tags = [tag for tag in integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS if tag != "manual"]

bazel_integration_test(
name = "workspace_test",
bazel_version = bazel_binaries.versions.current,
tags = integration_test_tags,
test_runner = ":workspace_test_runner",
workspace_files = [
"@examples_workspace//:all_files",
"//:all_files",
"@rules_task//:all_files",
],
workspace_path = "workspace",
)
4 changes: 4 additions & 0 deletions rules/rules_release/examples/workspace/.bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bazel-bin/
bazel-out/
bazel-testlogs/
bazel-workspace/
5 changes: 5 additions & 0 deletions rules/rules_release/examples/workspace/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# To ensure a hermetic environment for Java
build --java_runtime_version=remotejdk_11

# Disable the bazel symlinks
common --experimental_convenience_symlinks=ignore
15 changes: 15 additions & 0 deletions rules/rules_release/examples/workspace/.changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": ["@changesets/changelog-github", { "repo": "vgijssel/setup" }],
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "master",
"updateInternalDependencies": "patch",
"ignore": [],
"privatePackages": {
"version": true,
"tag": true
}
}
Loading

0 comments on commit 3f6eca4

Please sign in to comment.