Skip to content

Commit

Permalink
test(core): swap env dict for env file in dev_pnpm_task_binary rule
Browse files Browse the repository at this point in the history
  • Loading branch information
vindard committed Jan 9, 2024
1 parent 96c8cc5 commit b45bd70
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 38 deletions.
21 changes: 1 addition & 20 deletions core/api/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -255,26 +255,7 @@ dev_pnpm_task_binary(
command = "dev:cron",
srcs = [":src"],
visibility = ["PUBLIC"],
env = {
"MONGODB_CON": "mongodb://localhost:27017/galoy",

"HELMREVISION": "dummy",
"KRATOS_PG_CON": "pg://dummy",
"OATHKEEPER_DECISION_ENDPOINT": "http://dummy",
"NETWORK": "regtest",
"TWILIO_ACCOUNT_SID": "dummy",
"TWILIO_AUTH_TOKEN": "dummy",
"TWILIO_VERIFY_SERVICE_ID": "dummy",
"KRATOS_PUBLIC_API": "http://dummy",
"KRATOS_ADMIN_API": "http://dummy",
"KRATOS_MASTER_USER_PASSWORD": "dummy",
"KRATOS_CALLBACK_API_KEY": "dummy",
"BRIA_HOST": "dummy",
"BRIA_API_KEY": "dummy",
"REDIS_MASTER_NAME": "dummy",
"REDIS_PASSWORD": "dummy",
"REDIS_0_DNS": "dummy",
},
env_file = ".env",
)

dev_pnpm_task_binary(
Expand Down
26 changes: 8 additions & 18 deletions toolchains/workspace-pnpm/macros.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1032,18 +1032,7 @@ def madge_check(
**kwargs,
)

def dict_to_env_string(input_dict):
env_strings = []

# TODO: handle different types of 'value' instead of casting everything to string
for key, value in input_dict.items():
env_strings.append('export ' + key +'=' + str(value))

return '\n'.join(env_strings)

def pnpm_task_binary_impl(ctx: AnalysisContext) -> list[[DefaultInfo, RunInfo]]:
env_file = ctx.actions.write(".env", dict_to_env_string(ctx.attrs.env), is_executable = True)

script = ctx.actions.write("pnpm-run.sh", """\
#!/usr/bin/env bash
set -euo pipefail
Expand All @@ -1059,7 +1048,9 @@ if [ "$install_node_modules" = "True" ]; then
pnpm install --frozen-lockfile
fi
source "$env_file"
if [[ -f "$env_file" ]]; then
source "$env_file"
fi
if [ "${*:5}" ]; then
exec pnpm run --report-summary "$npm_run_command" -- "${@:5}"
Expand All @@ -1068,6 +1059,7 @@ else
fi
""", is_executable = True)

env_file = ctx.attrs.env_file if ctx.attrs.env_file else ""
args = cmd_args([
script,
str(ctx.attrs.local_node_modules),
Expand All @@ -1085,12 +1077,10 @@ dev_pnpm_task_binary = rule(impl = pnpm_task_binary_impl, attrs = {
"local_node_modules": attrs.bool(default = True, doc = """Need to run pnpm install first?"""),
"srcs": attrs.list(attrs.source(), default = [], doc = """List of sources we require"""),
"deps": attrs.list(attrs.source(), default = [], doc = """List of dependencies we require"""),
"env": attrs.dict(
key = attrs.string(),
value = attrs.arg(),
sorted = False,
default = {},
doc = """Env values to inject for pnpm command run"""
"env_file": attrs.option(
attrs.string(),
doc = """File name and relative path for env variables required.""",
default = None,
),
})

Expand Down

0 comments on commit b45bd70

Please sign in to comment.