Skip to content

Commit

Permalink
Merge pull request #317 from Zemnmez/version-pipelining
Browse files Browse the repository at this point in the history
version pipelining
  • Loading branch information
Zemnmez authored Jun 6, 2022
2 parents dfad1c4 + 012ccb8 commit e5d99af
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 6 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,10 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Checkout versioned branch
run: git switch versioned
- name: Merge with main
run: git merge main
- name: Open PR to 'versioned' branch
run: gh pr create -f
run: gh pr create -f --head main --base versioned
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set PR to merge automatically
run: gh pr merge --auto --merge
run: gh pr merge --auto --merge --head main --base versioned

1 change: 1 addition & 0 deletions bzl/hash/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# no output defined here
50 changes: 50 additions & 0 deletions bzl/hash/rules.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
def _impl(ctx):
# Create actions to generate the three output files.
# Actions are run only when the corresponding file is requested.

inputs = ctx.files.srcs
arguments = [ file.path for file in ctx.files.srcs ]

ctx.actions.run_shell(
outputs = [ctx.outputs.md5],
inputs = inputs,
command = "md5sum $@ > {}".format( ctx.outputs.md5.path),
arguments = arguments,
)

ctx.actions.run_shell(
outputs = [ctx.outputs.sha1],
inputs = inputs,
command = "sha1sum $@ > {}".format( ctx.outputs.sha1.path),
arguments = arguments,
)

ctx.actions.run_shell(
outputs = [ctx.outputs.sha256],
inputs = inputs,
command = "sha256sum $@ > {}".format( ctx.outputs.sha256.path),
arguments = arguments,
)

# By default (if you run `bazel build` on this target, or if you use it as a
# source of another target), only the sha256 is computed.
return DefaultInfo(files = depset([ctx.outputs.sha256]))

_hashes = rule(
implementation = _impl,
attrs = {
"srcs": attr.label_list(mandatory = True, allow_files = True),
"md5": attr.output(),
"sha1": attr.output(),
"sha256": attr.output(),
},
)

def hashes(**kwargs):
name = kwargs["name"]
_hashes(
md5 = "%s.md5" % name,
sha1 = "%s.sha1" % name,
sha256 = "%s.sha256" % name,
**kwargs
)
13 changes: 13 additions & 0 deletions bzl/hash/test/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("//bzl/hash:rules.bzl", "hashes")
load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test")

hashes(
name = "hashes",
srcs = [ "input1.txt", "input2.txt" ]
)

generated_file_test(
name = "version_concat_test",
generated = ":hashes",
src = "expected.txt"
)
2 changes: 2 additions & 0 deletions bzl/hash/test/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 bzl/hash/test/input1.txt
486ea46224d1bb4fb680f34f7c9ad96a8f24ec88be73ea8e5a6c65260e9cb8a7 bzl/hash/test/input2.txt
1 change: 1 addition & 0 deletions bzl/hash/test/input1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
1 change: 1 addition & 0 deletions bzl/hash/test/input2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
world

0 comments on commit e5d99af

Please sign in to comment.