rules_multirun
0.9.0
published 8 months ago
79 stars
16 forks
6 watchers
Apache License 2.0
public
1 assets
963,080 downloads
14 KB
Compatability level 1
DhJFZ/qFKHh07/M6eRw7vcxTQzKaVvqoKO9iQ4DUYHw=
Maintained byKeith Smiley
0.9.0
March 21, 2024

What's Changed

  • Pass arguments from bazel run through to the multirun target being run, thanks @hunshcn!
  • Replace use of to_json() with json.encode(), thanks @mortenmj!
  • Fix default value for data for expansion_targets, thanks @harshalparekh6!

MODULE.bazel Snippet

bazel_dep(name = "rules_multirun", version = "0.9.0")

Workspace Snippet

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "rules_multirun",
    sha256 = "0e124567fa85287874eff33a791c3bbdcc5343329a56faa828ef624380d4607c",
    url = "https://github.com/keith/rules_multirun/releases/download/0.9.0/rules_multirun.0.9.0.tar.gz",
)
Deps:
Assets:

rules_multirun

These rules provide a simple interface for running multiple commands in parallel with a single bazel run invocation. This is especially useful for running multiple linters or formatters with a single command.

Usage

Setup the tools you want to run:

load("@rules_multirun//:defs.bzl", "command", "multirun")
load("@rules_python//python:defs.bzl", "py_binary")

sh_binary(
    name = "some_linter",
    ...
)

py_binary(
    name = "some_other_linter",
    ...
)

command(
    name = "lint-something",
    command = ":some_linter",
    arguments = ["check"], # Optional arguments passed directly to the tool
)

command(
    name = "lint-something-else",
    command = ":some_other_linter",
    environment = {"CHECK": "true"}, # Optional environment variables set when invoking the command
    data = ["..."] # Optional runtime data dependencies
)

multirun(
    name = "lint",
    commands = [
        "lint-something",
        "lint-something-else",
    ],
    jobs = 0, # Set to 0 to run in parallel, defaults to sequential
)

Run the multirun target with bazel:

$ bazel run //:lint

See the full API docs for more info.

Usage with platform transitions

In case if the multirun rule requires a transition to other configuration than target then a new multirun-like rule can be defined as in the following example

load("@rules_multirun//:defs.bzl", "multirun_with_transition")

def _aws_deploy_platforms_impl(settings, attr):
    return {"//command_line_option:platforms": [":aws_lambda"]}

aws_deploy_transition = transition(
    implementation = _aws_deploy_platforms_impl,
    inputs = [],
    outputs = ["//command_line_option:platforms"],
)

aws_deploy = multirun_with_transition(
    aws_deploy_transition,
    "@bazel_tools//tools/allowlists/function_transition_allowlist"
)

and used in a BUILD file

aws_deploy(
    name = "staging",
    commands = [
       ...
    ]
)

Installation

Go to the releases page to grab the WORKSPACE snippet for the latest release.

Acknowledgements

This is a fork of the original multirun rules. Those rules have a dependency on golang to run, which may not be desired, these rules use a python script instead.