Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bcr/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ bcr_test_module:
name: "Build module"
platform: ${{ platform }}
bazel: ${{ bazel }}
build_targets:
test_targets:
- "//..."
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
disk-cache: true
# Share repository cache between workflows.
repository-cache: true
- name: bazel build
- name: bazel test
run: >-
bazelisk
--bazelrc=.github/workflows/ci.bazelrc
--bazelrc=.bazelrc
build
...
test
//...
4 changes: 2 additions & 2 deletions .github/workflows/release_ruleset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
# Fetch built artifacts (if any) from earlier jobs, which the release script may want to read.
# Extract into ${GITHUB_WORKSPACE}/artifacts/*
- uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1

- name: Build release artifacts and prepare release notes
run: |
if [ ! -f ".github/workflows/release_prep.sh" ]; then
Expand Down Expand Up @@ -205,4 +205,4 @@ jobs:
tag_name: ${{ inputs.tag_name }}
files: |
release_files/**/*
attestations/*
attestations/*
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module(

bazel_dep(name = "aspect_rules_js", version = "2.6.0")
bazel_dep(name = "aspect_rules_ts", version = "3.7.0")
bazel_dep(name = "bazel_skylib", version = "1.8.1")
bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "rules_nodejs", version = "6.5.0")

# --------------------------------------------------------------------------------
Expand Down
13 changes: 7 additions & 6 deletions examples/helloworld/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
load("//rules:defs.bzl", "closure_ts_compile")
load("//rules:testing.bzl", "golden_file_test")

closure_ts_compile(
name = "lib",
srcs = ["index.ts"],
)

# bazel run //examples/helloworld:files.update
# bazel test //examples/helloworld:files.test
# golden_filegroup(
# name = "files",
# srcs = [":index.ts"],
# )
# bazel test //examples/helloworld:golden_test
# bazel run //examples/helloworld:golden_test.update
golden_file_test(
name = "golden_test",
srcs = [":lib"],
)
15 changes: 15 additions & 0 deletions examples/helloworld/index.js.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @fileoverview added by tsickle
* Generated from: examples/helloworld/index.ts
*/
goog.module('examples.helloworld.index');
var module = module || { id: 'examples/helloworld/index.ts' };
goog.require('tslib');
/**
* @param {string} name
* @return {string}
*/
function sayHello(name) {
return `hello, ${name}!`;
}
exports.sayHello = sayHello;
102 changes: 102 additions & 0 deletions rules/testing.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
def _golden_file_test_impl(ctx):
outputs = [ctx.outputs.executable]

content = "\n".join([
"""
if diff -u {dst} {src}; then
echo "files contents are identical"
else
echo "files differ"
exit 1
fi
""".format(
src = src.short_path,
dst = src.short_path + ".golden",
)
for src in ctx.files.srcs
])

ctx.actions.write(
ctx.outputs.executable,
"set -x\n\n" + content,
is_executable = True,
)
return [
DefaultInfo(
files = depset(outputs),
runfiles = ctx.runfiles(files = ctx.files.srcs + ctx.files.goldens),
),
]

_golden_file_test = rule(
doc = "Asserts the two files are equal",
implementation = _golden_file_test_impl,
attrs = {
"srcs": attr.label_list(
doc = "the source files under test",
allow_files = True,
mandatory = True,
),
"goldens": attr.label_list(
doc = "the expected golden files",
allow_files = True,
mandatory = True,
),
},
executable = True,
test = True,
)

def _golden_file_update_impl(ctx):
outputs = [ctx.outputs.executable]

content = "\n".join([
"""
cp -f {src} {dst}
echo "Updated golden file: {dst}"
""".format(
src = src.short_path,
dst = "$BUILD_WORKING_DIRECTORY/%s/%s.golden" % (ctx.label.package, src.basename),
)
for src in ctx.files.srcs
])

ctx.actions.write(
ctx.outputs.executable,
"set -x\n\n" + content,
is_executable = True,
)
return [
DefaultInfo(
files = depset(outputs),
runfiles = ctx.runfiles(files = ctx.files.srcs),
),
]

_golden_file_update = rule(
doc = "Asserts the two files are equal",
implementation = _golden_file_update_impl,
attrs = {
"srcs": attr.label_list(
doc = "the source files to update",
allow_files = True,
mandatory = True,
),
},
executable = True,
)

def golden_file_test(name, srcs, **kwargs):
tags = kwargs.get("tags", [])
_golden_file_test(
name = name,
srcs = srcs,
goldens = native.glob(["*.golden"]),
tags = tags,
**kwargs
)
_golden_file_update(
name = name + ".update",
srcs = srcs,
tags = tags,
)
Loading