Skip to content

Commit

Permalink
Env var run summary data generation (vercel#4529)
Browse files Browse the repository at this point in the history
This hoists the identification of environment mode much earlier in the
process and captures the passthrough environment variables (hashed
values included!) for run summary and `--dry=json`.
  • Loading branch information
nathanhammond authored and NicholasLYang committed Apr 21, 2023
1 parent 6ac45a7 commit c5f6568
Show file tree
Hide file tree
Showing 33 changed files with 450 additions and 73 deletions.
15 changes: 12 additions & 3 deletions cli/integration_tests/dry_json/monorepo.t
Expand Up @@ -72,6 +72,7 @@ Setup

$ cat tmpjson.log | jq 'keys'
[
"envMode",
"globalCacheInputs",
"id",
"packages",
Expand Down Expand Up @@ -122,13 +123,16 @@ Setup
},
"expandedOutputs": [],
"framework": "<NO FRAMEWORK DETECTED>",
"envMode": "loose",
"environmentVariables": {
"configured": [],
"inferred": [],
"global": [
"SOME_ENV_VAR=",
"VERCEL_ANALYTICS_ID="
]
],
"passthrough": null,
"globalPassthrough": null
}
}

Expand Down Expand Up @@ -170,6 +174,7 @@ Setup
},
"expandedOutputs": [],
"framework": "<NO FRAMEWORK DETECTED>",
"envMode": "loose",
"environmentVariables": {
"configured": [
"NODE_ENV="
Expand All @@ -178,7 +183,9 @@ Setup
"global": [
"SOME_ENV_VAR=",
"VERCEL_ANALYTICS_ID="
]
],
"passthrough": null,
"globalPassthrough": null
}
}

Expand All @@ -192,7 +199,9 @@ Run again with NODE_ENV set and see the value in the summary. --filter=util work
"global": [
"SOME_ENV_VAR=",
"VERCEL_ANALYTICS_ID="
]
],
"passthrough": null,
"globalPassthrough": null
}

Tasks that don't exist throw an error
Expand Down
6 changes: 5 additions & 1 deletion cli/integration_tests/dry_json/single_package.t
Expand Up @@ -29,6 +29,7 @@ Setup
}
}
},
"envMode": "infer",
"tasks": [
{
"taskId": "build",
Expand Down Expand Up @@ -70,12 +71,15 @@ Setup
},
"expandedOutputs": [],
"framework": "\u003cNO FRAMEWORK DETECTED\u003e",
"envMode": "loose",
"environmentVariables": {
"configured": [],
"inferred": [],
"global": [
"VERCEL_ANALYTICS_ID="
]
],
"passthrough": null,
"globalPassthrough": null
}
}
]
Expand Down
6 changes: 5 additions & 1 deletion cli/integration_tests/dry_json/single_package_no_config.t
Expand Up @@ -28,6 +28,7 @@ Setup
}
}
},
"envMode": "infer",
"tasks": [
{
"taskId": "build",
Expand Down Expand Up @@ -64,12 +65,15 @@ Setup
},
"expandedOutputs": [],
"framework": "\u003cNO FRAMEWORK DETECTED\u003e",
"envMode": "loose",
"environmentVariables": {
"configured": [],
"inferred": [],
"global": [
"VERCEL_ANALYTICS_ID="
]
],
"passthrough": null,
"globalPassthrough": null
}
}
]
Expand Down
11 changes: 9 additions & 2 deletions cli/integration_tests/dry_json/single_package_with_deps.t
Expand Up @@ -39,6 +39,7 @@ Setup
}
}
},
"envMode": "infer",
"tasks": [
{
"taskId": "build",
Expand Down Expand Up @@ -81,12 +82,15 @@ Setup
},
"expandedOutputs": [],
"framework": "\u003cNO FRAMEWORK DETECTED\u003e",
"envMode": "loose",
"environmentVariables": {
"configured": [],
"inferred": [],
"global": [
"VERCEL_ANALYTICS_ID="
]
],
"passthrough": null,
"globalPassthrough": null
}
},
{
Expand Down Expand Up @@ -128,12 +132,15 @@ Setup
},
"expandedOutputs": [],
"framework": "\u003cNO FRAMEWORK DETECTED\u003e",
"envMode": "loose",
"environmentVariables": {
"configured": [],
"inferred": [],
"global": [
"VERCEL_ANALYTICS_ID="
]
],
"passthrough": null,
"globalPassthrough": null
}
}
]
Expand Down
5 changes: 4 additions & 1 deletion cli/integration_tests/run_summary/error.t
Expand Up @@ -63,13 +63,16 @@ Validate that we got a full task summary for the failed task with an error in .e
},
"expandedOutputs": [],
"framework": "",
"envMode": "loose",
"environmentVariables": {
"configured": [],
"inferred": [],
"global": [
"SOME_ENV_VAR=",
"VERCEL_ANALYTICS_ID="
]
],
"passthrough": null,
"globalPassthrough": null
},
"execution": {
"startTime": [0-9]+, (re)
Expand Down
1 change: 1 addition & 0 deletions cli/integration_tests/run_summary/single-package.t
Expand Up @@ -51,6 +51,7 @@ Check
"command",
"dependencies",
"dependents",
"envMode",
"environmentVariables",
"excludedOutputs",
"execution",
Expand Down
206 changes: 206 additions & 0 deletions cli/integration_tests/run_summary/strict_env.t
@@ -0,0 +1,206 @@
Setup
$ . ${TESTDIR}/../_helpers/setup.sh
$ . ${TESTDIR}/../_helpers/setup_monorepo.sh $(pwd) strict_env_vars

Set the env vars
$ export GLOBAL_VAR_PT=higlobalpt
$ export GLOBAL_VAR_DEP=higlobaldep
$ export LOCAL_VAR_PT=hilocalpt
$ export LOCAL_VAR_DEP=hilocaldep
$ export OTHER_VAR=hiother
$ export SYSTEMROOT=hisysroot

Run as `infer`
$ rm -rf .turbo/runs
$ ${TURBO} run build --summarize > /dev/null
$ cat .turbo/runs/*.json | jq -r '.envMode'
infer
$ cat .turbo/runs/*.json | jq -r '.tasks[0].envMode'
loose
$ cat .turbo/runs/*.json | jq -r '.tasks[0].environmentVariables | {passthrough, globalPassthrough}'
{
"passthrough": null,
"globalPassthrough": null
}

Run as `strict`
$ rm -rf .turbo/runs
$ ${TURBO} run build --experimental-env-mode=strict --summarize > /dev/null
$ cat .turbo/runs/*.json | jq -r '.envMode'
strict
$ cat .turbo/runs/*.json | jq -r '.tasks[0].envMode'
strict
$ cat .turbo/runs/*.json | jq -r '.tasks[0].environmentVariables | {passthrough, globalPassthrough}'
{
"passthrough": null,
"globalPassthrough": null
}

Run as `loose`
$ rm -rf .turbo/runs
$ ${TURBO} run build --experimental-env-mode=loose --summarize > /dev/null
$ cat .turbo/runs/*.json | jq -r '.envMode'
loose
$ cat .turbo/runs/*.json | jq -r '.tasks[0].envMode'
loose
$ cat .turbo/runs/*.json | jq -r '.tasks[0].environmentVariables | {passthrough, globalPassthrough}'
{
"passthrough": null,
"globalPassthrough": null
}

All specified + infer
$ rm -rf .turbo/runs
$ cp "$TESTDIR/../_fixtures/strict_env_vars_configs/all.json" "$(pwd)/turbo.json" && git commit --allow-empty -am "no comment" --quiet
$ ${TURBO} run build --summarize > /dev/null
$ cat .turbo/runs/*.json | jq -r '.envMode'
strict
$ cat .turbo/runs/*.json | jq -r '.tasks[0].envMode'
strict
$ cat .turbo/runs/*.json | jq -r '.tasks[0].environmentVariables | {passthrough, globalPassthrough}'
{
"passthrough": [
"LOCAL_VAR_PT=7cd1bb19c058cf4d6ad6aa579d685bddddf3ab587b78bdcb1e6e488fb6f47a3b"
],
"globalPassthrough": [
"GLOBAL_VAR_PT=cecd31fff1e723588eac8fe1edff89a6d2ec072f5c3bd884a98297487670b1f0"
]
}

All specified + loose
$ rm -rf .turbo/runs
$ cp "$TESTDIR/../_fixtures/strict_env_vars_configs/all.json" "$(pwd)/turbo.json" && git commit --allow-empty -am "no comment" --quiet
$ ${TURBO} run build --experimental-env-mode=loose --summarize > /dev/null
$ cat .turbo/runs/*.json | jq -r '.envMode'
loose
$ cat .turbo/runs/*.json | jq -r '.tasks[0].envMode'
loose
$ cat .turbo/runs/*.json | jq -r '.tasks[0].environmentVariables | {passthrough, globalPassthrough}'
{
"passthrough": [
"LOCAL_VAR_PT=7cd1bb19c058cf4d6ad6aa579d685bddddf3ab587b78bdcb1e6e488fb6f47a3b"
],
"globalPassthrough": [
"GLOBAL_VAR_PT=cecd31fff1e723588eac8fe1edff89a6d2ec072f5c3bd884a98297487670b1f0"
]
}

Global passthrough specified empty array + infer
$ rm -rf .turbo/runs
$ cp "$TESTDIR/../_fixtures/strict_env_vars_configs/global_pt-empty.json" "$(pwd)/turbo.json" && git commit --allow-empty -am "no comment" --quiet
$ ${TURBO} run build --summarize > /dev/null
$ cat .turbo/runs/*.json | jq -r '.envMode'
strict
$ cat .turbo/runs/*.json | jq -r '.tasks[0].envMode'
strict
$ cat .turbo/runs/*.json | jq -r '.tasks[0].environmentVariables | {passthrough, globalPassthrough}'
{
"passthrough": null,
"globalPassthrough": []
}

Global passthrough specified value + infer
$ rm -rf .turbo/runs
$ cp "$TESTDIR/../_fixtures/strict_env_vars_configs/global_pt.json" "$(pwd)/turbo.json" && git commit --allow-empty -am "no comment" --quiet
$ ${TURBO} run build --summarize > /dev/null
$ cat .turbo/runs/*.json | jq -r '.envMode'
strict
$ cat .turbo/runs/*.json | jq -r '.tasks[0].envMode'
strict
$ cat .turbo/runs/*.json | jq -r '.tasks[0].environmentVariables | {passthrough, globalPassthrough}'
{
"passthrough": null,
"globalPassthrough": [
"GLOBAL_VAR_PT=cecd31fff1e723588eac8fe1edff89a6d2ec072f5c3bd884a98297487670b1f0"
]
}

Global passthrough specified empty array + loose
$ rm -rf .turbo/runs
$ cp "$TESTDIR/../_fixtures/strict_env_vars_configs/global_pt-empty.json" "$(pwd)/turbo.json" && git commit --allow-empty -am "no comment" --quiet
$ ${TURBO} run build --experimental-env-mode=loose --summarize > /dev/null
$ cat .turbo/runs/*.json | jq -r '.envMode'
loose
$ cat .turbo/runs/*.json | jq -r '.tasks[0].envMode'
loose
$ cat .turbo/runs/*.json | jq -r '.tasks[0].environmentVariables | {passthrough, globalPassthrough}'
{
"passthrough": null,
"globalPassthrough": []
}

Global passthrough specified value + loose
$ rm -rf .turbo/runs
$ cp "$TESTDIR/../_fixtures/strict_env_vars_configs/global_pt.json" "$(pwd)/turbo.json" && git commit --allow-empty -am "no comment" --quiet
$ ${TURBO} run build --experimental-env-mode=loose --summarize > /dev/null
$ cat .turbo/runs/*.json | jq -r '.envMode'
loose
$ cat .turbo/runs/*.json | jq -r '.tasks[0].envMode'
loose
$ cat .turbo/runs/*.json | jq -r '.tasks[0].environmentVariables | {passthrough, globalPassthrough}'
{
"passthrough": null,
"globalPassthrough": [
"GLOBAL_VAR_PT=cecd31fff1e723588eac8fe1edff89a6d2ec072f5c3bd884a98297487670b1f0"
]
}

Task passthrough specified empty array + infer
$ rm -rf .turbo/runs
$ cp "$TESTDIR/../_fixtures/strict_env_vars_configs/task_pt-empty.json" "$(pwd)/turbo.json" && git commit --allow-empty -am "no comment" --quiet
$ ${TURBO} run build --summarize > /dev/null
$ cat .turbo/runs/*.json | jq -r '.envMode'
infer
$ cat .turbo/runs/*.json | jq -r '.tasks[0].envMode'
strict
$ cat .turbo/runs/*.json | jq -r '.tasks[0].environmentVariables | {passthrough, globalPassthrough}'
{
"passthrough": [],
"globalPassthrough": null
}

Task passthrough specified value + infer
$ rm -rf .turbo/runs
$ cp "$TESTDIR/../_fixtures/strict_env_vars_configs/task_pt.json" "$(pwd)/turbo.json" && git commit --allow-empty -am "no comment" --quiet
$ ${TURBO} run build --summarize > /dev/null
$ cat .turbo/runs/*.json | jq -r '.envMode'
infer
$ cat .turbo/runs/*.json | jq -r '.tasks[0].envMode'
strict
$ cat .turbo/runs/*.json | jq -r '.tasks[0].environmentVariables | {passthrough, globalPassthrough}'
{
"passthrough": [
"LOCAL_VAR_PT=7cd1bb19c058cf4d6ad6aa579d685bddddf3ab587b78bdcb1e6e488fb6f47a3b"
],
"globalPassthrough": null
}

Task passthrough specified empty array + loose
$ rm -rf .turbo/runs
$ cp "$TESTDIR/../_fixtures/strict_env_vars_configs/task_pt-empty.json" "$(pwd)/turbo.json" && git commit --allow-empty -am "no comment" --quiet
$ ${TURBO} run build --experimental-env-mode=loose --summarize > /dev/null
$ cat .turbo/runs/*.json | jq -r '.envMode'
loose
$ cat .turbo/runs/*.json | jq -r '.tasks[0].envMode'
loose
$ cat .turbo/runs/*.json | jq -r '.tasks[0].environmentVariables | {passthrough, globalPassthrough}'
{
"passthrough": [],
"globalPassthrough": null
}

Task passthrough specified value + loose
$ rm -rf .turbo/runs
$ cp "$TESTDIR/../_fixtures/strict_env_vars_configs/task_pt.json" "$(pwd)/turbo.json" && git commit --allow-empty -am "no comment" --quiet
$ ${TURBO} run build --experimental-env-mode=loose --summarize > /dev/null
$ cat .turbo/runs/*.json | jq -r '.envMode'
loose
$ cat .turbo/runs/*.json | jq -r '.tasks[0].envMode'
loose
$ cat .turbo/runs/*.json | jq -r '.tasks[0].environmentVariables | {passthrough, globalPassthrough}'
{
"passthrough": [
"LOCAL_VAR_PT=7cd1bb19c058cf4d6ad6aa579d685bddddf3ab587b78bdcb1e6e488fb6f47a3b"
],
"globalPassthrough": null
}

0 comments on commit c5f6568

Please sign in to comment.