Skip to content

Commit

Permalink
feat: use rules_bazel_integration_test to join a standard
Browse files Browse the repository at this point in the history
  • Loading branch information
chickenandpork committed Dec 10, 2024
1 parent e5d1fa5 commit 4fed056
Show file tree
Hide file tree
Showing 19 changed files with 253 additions and 718 deletions.
3 changes: 2 additions & 1 deletion .bazelignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ignore the examples which are used to document suggested usage, validate this project, and -- in future -- repro issues
examples
#examples/**
#examples/*/*/external

6 changes: 6 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Needed for rules_bazel_integration_test is `bazel test //examples:all_integration_tests
#
# To update these lines, execute
# `bazel run @rules_bazel_integration_test//tools:update_deleted_packages`
build --deleted_packages=examples/cross-helloworld,examples/cross-helloworld-no-go,examples/cross-helloworld-no-go/bzl/patches,examples/cross-helloworld/bzl/patches,examples/example-docker-project,examples/example-docker-project/maintainers,examples/example-docker-project/spk/nginx,examples/example-docker-project/tests,examples/example-kernelmod-spk,examples/example-kernelmod-spk/maintainers,examples/example-kernelmod-spk/spk/netfilter-mods,examples/example-kernelmod-spk/tests,examples/example-server,examples/example-server/api,examples/example-server/maintainers,examples/example-server/server,examples/example-server/spk/exampleserver,examples/example-server/tests,patches
query --deleted_packages=examples/cross-helloworld,examples/cross-helloworld-no-go,examples/cross-helloworld-no-go/bzl/patches,examples/cross-helloworld/bzl/patches,examples/example-docker-project,examples/example-docker-project/maintainers,examples/example-docker-project/spk/nginx,examples/example-docker-project/tests,examples/example-kernelmod-spk,examples/example-kernelmod-spk/maintainers,examples/example-kernelmod-spk/spk/netfilter-mods,examples/example-kernelmod-spk/tests,examples/example-server,examples/example-server/api,examples/example-server/maintainers,examples/example-server/server,examples/example-server/spk/exampleserver,examples/example-server/tests,patches
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.4.1
5 changes: 4 additions & 1 deletion .github/workflows/bazel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ jobs:
-
run: bazel build //...
-
run: bazel test //... --test_output=errors --test_summary=detailed --sandbox_debug
run: bazel test //... --test_output=errors --test_summary=detailed
-
name: Integration Tests (ie Examples)
run: bazel test //examples:all_integration_tests
-
name: Build / Test examples to ensure functionality
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bazel-*
MODULE.bazel.lock

# Needed for ibazel
WORKSPACE
Expand Down
21 changes: 21 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,24 @@ stardoc(
visibility = ["//visibility:public"],
deps = ["//synology:docs"],
)

# This target collects all of the parent workspace files needed by the child workspaces.
filegroup(
name = "local_repository_files",
# Include every package that is required by the child workspaces.
srcs = [
"BUILD.bazel",
"MODULE.bazel",
"defs.bzl",
"//arch:all_files",
"//config:all_files",
"//dsm:all_files",
"//models:all_files",
"//platform:all_files",
"//synology:all_files",
"//toolchains:all_files",
"//tools:all_files",
"//unittests:all_files",
],
visibility = ["//:__subpackages__"],
)
14 changes: 14 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ bazel_dep(name = "rules_shellcheck", version = "0.3.3", repo_name = "com_github_
bazel_dep(name = "stardoc", version = "0.7.2") # remove redundant rules_jvm_external when 0.7.2 or greater

bazel_dep(name = "buildifier_prebuilt", version = "7.3.1", dev_dependency = True)
bazel_dep(name = "rules_bazel_integration_test", version = "0.26.1", dev_dependency = True)
local_path_override(
module_name = "rules_bazel_integration_test",
path = "../rules_bazel_integration_test",
)

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")

Expand Down Expand Up @@ -44,3 +49,12 @@ use_repo(
"bazelisk_darwin_amd64",
"bazelisk_darwin_arm64",
)

#
# Integration tests
#

bazel_binaries = use_extension("@rules_bazel_integration_test//:extensions.bzl", "bazel_binaries", dev_dependency = True)
bazel_binaries.download(version_file = "//:.bazelversion")
bazel_binaries.download(version = "6.0.0")
use_repo(bazel_binaries, "bazel_binaries", "bazel_binaries_bazelisk", "build_bazel_bazel_.bazelversion", "build_bazel_bazel_6_0_0")
17 changes: 17 additions & 0 deletions arch/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,20 @@ filegroup(
name = "all_arch",
srcs = [":{}".format(a) for a in TOOLCHAINS],
)

# TL;DR: needed for `bazel test //examples:all_integration_tests`
#
# For Integration Tests -- rules_bazel_integration_test -- every child workspace (ie every example
# that exercises the rules) needs to refer to all the files of the ruleset. For this reason, we
# have this rule collecting all the files in this "package" for collection at Workspace in
# //:local_repository_files to be passed to the workspace of the child workspace (test example) in
# //examples:BUILD.bazel,
#
# ```
# bazel_integration_test( workspace_files = ... "//:local_repository_files", ], ... )
# ````
filegroup(
name = "all_files",
srcs = glob(["*"]), # TODO: *.bzl BUILD.bazel
visibility = ["//:__subpackages__"],
)
Empty file removed config/BUILD
Empty file.
18 changes: 18 additions & 0 deletions config/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# The only build target here is used only in integration-testing

# TL;DR: needed for `bazel test //examples:all_integration_tests`
#
# For Integration Tests -- rules_bazel_integration_test -- every child workspace (ie every example
# that exercises the rules) needs to refer to all the files of the ruleset. For this reason, we
# have this rule collecting all the files in this "package" for collection at Workspace in
# //:local_repository_files to be passed to the workspace of the child workspace (test example) in
# //examples:BUILD.bazel,
#
# ```
# bazel_integration_test( workspace_files = ... "//:local_repository_files", ], ... )
# ````
filegroup(
name = "all_files",
srcs = glob(["*"]), # TODO: *.bzl BUILD.bazel
visibility = ["//:__subpackages__"],
)
17 changes: 17 additions & 0 deletions dsm/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,20 @@ filegroup(
name = "all_dsm",
srcs = [":{}".format(v) for v in VERSIONS],
)

# TL;DR: needed for `bazel test //examples:all_integration_tests`
#
# For Integration Tests -- rules_bazel_integration_test -- every child workspace (ie every example
# that exercises the rules) needs to refer to all the files of the ruleset. For this reason, we
# have this rule collecting all the files in this "package" for collection at Workspace in
# //:local_repository_files to be passed to the workspace of the child workspace (test example) in
# //examples:BUILD.bazel,
#
# ```
# bazel_integration_test( workspace_files = ... "//:local_repository_files", ], ... )
# ````
filegroup(
name = "all_files",
srcs = glob(["*"]), # TODO: *.bzl BUILD.bazel
visibility = ["//:__subpackages__"],
)
40 changes: 40 additions & 0 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,47 @@
load("@bazel_binaries//:defs.bzl", "bazel_binaries")
load(
"@rules_bazel_integration_test//bazel_integration_test:defs.bzl",
"bazel_integration_test",
"bazel_integration_tests",
"default_test_runner",
"integration_test_utils",
)
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files", "pkg_mkdirs", "strip_prefix")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
load("@rules_synology//:defs.bzl", "images", "info_file", "maintainer", "protocol_file", "resource_config", "service_config")

#examples = [ "cross-helloworld"]

# Declare a test runner to drive the integration tests.
default_test_runner(
name = "default_runner", # unsure where this constant means anything
)

# If you only want to execute against a single version of Bazel, use
# bazel_integration_test.
bazel_integration_test(
name = "cross_helloworld",
bazel_version = bazel_binaries.versions.current,
test_runner = ":default_runner",
workspace_files = integration_test_utils.glob_workspace_files("cross-helloworld") + [
"//:local_repository_files",
],
workspace_path = "cross-helloworld",
)

# By default, the integration test targets are tagged as `manual`. This
# prevents the targets from being found from most target expansion (e.g.
# `//...`, `:all`). To easily execute a group of integration tests, you may
# want to define a test suite which includes the desired test targets.
test_suite(
name = "all_integration_tests",
# If you don't apply the test tags to the test suite, the test suite will
# be found when `bazel test //...` is executed.
tags = integration_test_utils.DEFAULT_INTEGRATION_TEST_TAGS,
tests = [":cross_helloworld"], #+ integration_test_utils.bazel_integration_test_names( "cross_helloworld", bazel_binaries.versions.other),
visibility = ["//:__subpackages__"],
)

info_file(
name = "info",
package_name = "xx",
Expand Down
Loading

0 comments on commit 4fed056

Please sign in to comment.