Skip to content

Commit eab66de

Browse files
authored
Merge pull request #384 from nix-community/buildbot-effects
buildbot-effects: don't print program arguments by default
2 parents a701a54 + addce95 commit eab66de

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

bin/buildbot-effects

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
import sys
33
from pathlib import Path
4-
sys.path.append(str(Path(__file__).parent.parent))
4+
sys.path.append(str(Path(__file__).parent.parent / "buildbot_effects"))
55

66
from buildbot_effects.cli import main
77

buildbot_effects/buildbot_effects/__init__.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ def run(
2222
stdin: int | IO[str] | None = None,
2323
stdout: int | IO[str] | None = None,
2424
stderr: int | IO[str] | None = None,
25-
verbose: bool = True,
25+
debug: bool = True,
2626
) -> subprocess.CompletedProcess[str]:
27-
if verbose:
27+
if debug:
2828
print("$", shlex.join(cmd), file=sys.stderr)
2929
return subprocess.run(
3030
cmd,
@@ -36,9 +36,9 @@ def run(
3636
)
3737

3838

39-
def git_command(args: list[str], path: Path) -> str:
39+
def git_command(args: list[str], path: Path, debug: bool = False) -> str:
4040
cmd = ["git", "-C", str(path), *args]
41-
proc = run(cmd, stdout=subprocess.PIPE)
41+
proc = run(cmd, stdout=subprocess.PIPE, debug=debug)
4242
return proc.stdout.strip()
4343

4444

@@ -121,7 +121,7 @@ def list_effects(opts: EffectsOptions) -> list[str]:
121121
"--expr",
122122
f"builtins.attrNames ({effect_function(opts)})",
123123
)
124-
proc = run(cmd, stdout=subprocess.PIPE)
124+
proc = run(cmd, stdout=subprocess.PIPE, debug=opts.debug)
125125
return json.loads(proc.stdout)
126126

127127

@@ -131,11 +131,11 @@ def instantiate_effects(effect: str, opts: EffectsOptions) -> str:
131131
"--expr",
132132
f"(({effect_function(opts)}).{effect}).run or []",
133133
]
134-
proc = run(cmd, stdout=subprocess.PIPE)
134+
proc = run(cmd, stdout=subprocess.PIPE, debug=opts.debug)
135135
return proc.stdout.rstrip()
136136

137137

138-
def parse_derivation(path: str) -> dict[str, Any]:
138+
def parse_derivation(path: str, debug: bool = False) -> dict[str, Any]:
139139
cmd = [
140140
"nix",
141141
"--extra-experimental-features",
@@ -144,7 +144,7 @@ def parse_derivation(path: str) -> dict[str, Any]:
144144
"show",
145145
f"{path}^*",
146146
]
147-
proc = run(cmd, stdout=subprocess.PIPE)
147+
proc = run(cmd, stdout=subprocess.PIPE, debug=debug)
148148
return json.loads(proc.stdout)
149149

150150

@@ -176,6 +176,7 @@ def run_effects(
176176
drv_path: str,
177177
drv: dict[str, Any],
178178
secrets: dict[str, Any] | None = None,
179+
debug: bool = False,
179180
) -> None:
180181
if secrets is None:
181182
secrets = {}
@@ -257,7 +258,8 @@ def run_effects(
257258
bubblewrap_cmd.append("--")
258259
bubblewrap_cmd.extend(sandboxed_cmd)
259260
with pipe() as (r_file, w_file):
260-
print("$", shlex.join(bubblewrap_cmd), file=sys.stderr)
261+
if debug:
262+
print("$", shlex.join(bubblewrap_cmd), file=sys.stderr)
261263
proc = subprocess.Popen(
262264
bubblewrap_cmd,
263265
text=True,

buildbot_effects/buildbot_effects/cli.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ def parse_args() -> tuple[argparse.Namespace, EffectsOptions]:
5656
default=Path(),
5757
help="Path to the repository",
5858
)
59+
parser.add_argument(
60+
"--debug",
61+
default=False,
62+
action="store_true",
63+
help="Enable debug mode (may leak secrets such as GITHUB_TOKEN)",
64+
)
5965
subparser = parser.add_subparsers(
6066
dest="command",
6167
required=True,
@@ -88,6 +94,7 @@ def parse_args() -> tuple[argparse.Namespace, EffectsOptions]:
8894
rev=args.rev,
8995
repo=args.repo,
9096
path=args.path.resolve(),
97+
debug=args.debug,
9198
)
9299
return args, opts
93100

buildbot_effects/buildbot_effects/options.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ class EffectsOptions:
1111
branch: str | None = None
1212
url: str | None = None
1313
tag: str | None = None
14+
debug: bool = False

buildbot_nix/buildbot_nix/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,7 @@ def nix_eval_config(
11121112
# TODO: support other branches?
11131113
doStepIf=lambda c: c.build.getProperty("branch", "")
11141114
== project.default_branch,
1115+
logEnviron=False,
11151116
)
11161117
)
11171118

@@ -1439,6 +1440,7 @@ def buildbot_effects_config(
14391440
util.Property("command"),
14401441
# fmt: on
14411442
],
1443+
logEnviron=False,
14421444
),
14431445
],
14441446
withSecrets=secrets_list,

0 commit comments

Comments
 (0)