sourcegraph/third_party/bazel_lib/use_default_shell_env.patch
Noah S-C 06262e0936
bazel: patches to allow use_default_shell_env for e2e testing (#59675)
Another step towards https://github.com/sourcegraph/sourcegraph/issues/59155, previously `bazel test //...` would error at analysis time on `//client/web/src/end-to-end:e2e` due to it attempting to perform variable substitution for env vars e.g. `"HEADLESS": "$(E2E_HEADLESS)"`, for values not defined via `--define` (we only set these explicitly in .aspect/bazelrc/ci.sourcegraph.bazelrc and some `sg` targets).

By leveraging https://bazel.build/rules/lib/builtins/actions#run.use_default_shell_env, we can allow the test to read values from `--action_env` while _also_ having explicit values set via `env` macro parameter. Previously, setting `env` macro parameter would completely shadow any `--action_env` values. 
Unfortunately, we cant use `--test_env` for this, as `js_run_binary` is an action not a test (or something like that?).

We also cant do env renaming anymore, meaning we have to drop the `E2E_` prefix for some env vars. At least one script needed some reworking to accommodate that `e2e_test.sh` 

![image](https://github.com/sourcegraph/sourcegraph/assets/18282288/133a98c6-411d-4a10-95fd-4abd42cedb24)


## Test plan

👁️ CI once again 👁️
2024-01-24 18:50:19 -08:00

38 lines
1.4 KiB
Diff

diff --git a/lib/private/run_binary.bzl b/lib/private/run_binary.bzl
index 7ba4210..55bd984 100644
--- a/lib/private/run_binary.bzl
+++ b/lib/private/run_binary.bzl
@@ -76,7 +76,7 @@ Possible fixes:
mnemonic = ctx.attr.mnemonic if ctx.attr.mnemonic else None,
progress_message = ctx.attr.progress_message if ctx.attr.progress_message else None,
execution_requirements = ctx.attr.execution_requirements if ctx.attr.execution_requirements else None,
- use_default_shell_env = False,
+ use_default_shell_env = True,
env = dicts.add(ctx.configuration.default_shell_env, envs),
input_manifests = tool_input_mfs,
)
@@ -95,6 +95,7 @@ _run_binary = rule(
cfg = "exec",
),
"env": attr.string_dict(),
+ "use_default_shell_env": attr.bool(default = False),
"srcs": attr.label_list(
allow_files = True,
),
@@ -113,6 +114,7 @@ def run_binary(
srcs = [],
args = [],
env = {},
+ use_default_shell_env = False,
outs = [],
out_dirs = [],
mnemonic = "RunBinary",
@@ -220,6 +222,7 @@ def run_binary(
srcs = srcs,
args = args,
env = env,
+ use_default_shell_env = use_default_shell_env,
outs = outs,
out_dirs = out_dirs + ([name] if output_dir else []),
mnemonic = mnemonic,