Skip to content

Commit

Permalink
chore: add an e2e to test copy actions (#665)
Browse files Browse the repository at this point in the history
  • Loading branch information
kormide authored Nov 19, 2023
1 parent c3a8cb0 commit 2433bae
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ jobs:
bzlmodEnabled: [true, false]
folder:
- "."
- "e2e/coreutils"
- "e2e/copy_action"
- "e2e/copy_to_directory"
- "e2e/coreutils"
- "e2e/external_copy_to_directory"
- "e2e/smoke"
- "e2e/write_source_files"
exclude:
# Don't test MacOS with RBE to minimize MacOS minutes (billed at 10X)
- config: rbe
Expand Down
1 change: 1 addition & 0 deletions e2e/copy_action/.bazeliskrc
Empty file added e2e/copy_action/.bazelrc
Empty file.
1 change: 1 addition & 0 deletions e2e/copy_action/.bazelversion
13 changes: 13 additions & 0 deletions e2e/copy_action/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load(":copy.bzl", "simple_copy_file")

simple_copy_file(
name = "copy",
src = "foo.txt",
out = "bar.txt",
)

build_test(
name = "test",
targets = [":copy"],
)
11 changes: 11 additions & 0 deletions e2e/copy_action/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module(
version = "0.0.0",
compatibility_level = 1,
)

bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "aspect_bazel_lib", version = "0.0.0")
local_path_override(
module_name = "aspect_bazel_lib",
path = "../..",
)
27 changes: 27 additions & 0 deletions e2e/copy_action/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazel_skylib",
sha256 = "cd55a062e763b9349921f0f5db8c3933288dc8ba4f76dd9416aac68acee3cb94",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-1.5.0.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-1.5.0.tar.gz",
],
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

local_repository(
name = "aspect_bazel_lib",
path = "../..",
)

load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "register_coreutils_toolchains")

aspect_bazel_lib_dependencies()

# Registering coreutils is required under WORKSPACE for the copy action to work
# Under bzlmod, this is done automatically by just depending on the bazel-lib module.
register_coreutils_toolchains()
Empty file.
26 changes: 26 additions & 0 deletions e2e/copy_action/copy.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Rule that uses copy actions"""

load("@aspect_bazel_lib//lib:copy_file.bzl", "COPY_FILE_TOOLCHAINS", "copy_file_action")

def _simple_copy_file_impl(ctx):
if len(ctx.files.src) != 1:
fail("src must be a single file")
if ctx.files.src[0].is_directory:
fail("cannot use copy_file on a directory; try copy_directory instead")

copy_file_action(ctx, ctx.files.src[0], ctx.outputs.out)

files = depset(direct = [ctx.outputs.out])
runfiles = ctx.runfiles(files = [ctx.outputs.out])

return [DefaultInfo(files = files, runfiles = runfiles)]

simple_copy_file = rule(
implementation = _simple_copy_file_impl,
provides = [DefaultInfo],
attrs = {
"src": attr.label(mandatory = True, allow_files = True),
"out": attr.output(mandatory = True),
},
toolchains = COPY_FILE_TOOLCHAINS,
)
1 change: 1 addition & 0 deletions e2e/copy_action/foo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bar

0 comments on commit 2433bae

Please sign in to comment.