Skip to content

Commit

Permalink
Don't hash env var when the value is an empty string (vercel#4312)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehulkar authored Mar 23, 2023
1 parent df6ba02 commit 71f4b24
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 50 deletions.
66 changes: 33 additions & 33 deletions cli/integration_tests/basic_monorepo/dry_run.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,42 @@ Setup
# Part 3 are Tasks to Run, and we have to validate each task separately
$ cat tmp-3.txt | grep "my-app#build" -A 15
my-app#build
Task = build
Package = my-app
Hash = 45ec4e15c3dcf5c2
Cached (Local) = false
Cached (Remote) = false
Directory = apps/my-app
Command = echo 'building'
Outputs = apple.json, banana.txt
Log File = apps/my-app/.turbo/turbo-build.log
Dependencies =
Dependendents =
Inputs Files Considered = 1
Configured Environment Variables =
Inferred Environment Variables =
Global Environment Variables = SOME_ENV_VAR=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855, VERCEL_ANALYTICS_ID=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Task = build
Package = my-app
Hash = 45ec4e15c3dcf5c2
Cached (Local) = false
Cached (Remote) = false
Directory = apps/my-app
Command = echo 'building'
Outputs = apple.json, banana.txt
Log File = apps/my-app/.turbo/turbo-build.log
Dependencies =
Dependendents =
Inputs Files Considered = 1
Configured Environment Variables =
Inferred Environment Variables =
Global Environment Variables = SOME_ENV_VAR=, VERCEL_ANALYTICS_ID=

$ cat tmp-3.txt | grep "util#build" -A 15
util#build
Task = build
Package = util
Hash = c36e55f947cd2d28
Cached (Local) = false
Cached (Remote) = false
Directory = packages/util
Command = echo 'building'
Outputs =
Log File = packages/util/.turbo/turbo-build.log
Dependencies =
Dependendents =
Inputs Files Considered = 1
Configured Environment Variables = NODE_ENV=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Inferred Environment Variables =
Global Environment Variables = SOME_ENV_VAR=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855, VERCEL_ANALYTICS_ID=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Task = build
Package = util
Hash = c36e55f947cd2d28
Cached (Local) = false
Cached (Remote) = false
Directory = packages/util
Command = echo 'building'
Outputs =
Log File = packages/util/.turbo/turbo-build.log
Dependencies =
Dependendents =
Inputs Files Considered = 1
Configured Environment Variables = NODE_ENV=
Inferred Environment Variables =
Global Environment Variables = SOME_ENV_VAR=, VERCEL_ANALYTICS_ID=

# Run the task with NODE_ENV set and see it in summary. Use util package so it's just one package
$ NODE_ENV=banana ${TURBO} run build --dry --filter=util | grep "Environment Variables"
Configured Environment Variables = NODE_ENV=b493d48364afe44d11c0165cf470a4164d1e2609911ef998be868d46ade3de4e
Inferred Environment Variables =
Global Environment Variables = SOME_ENV_VAR=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855, VERCEL_ANALYTICS_ID=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Configured Environment Variables = NODE_ENV=b493d48364afe44d11c0165cf470a4164d1e2609911ef998be868d46ade3de4e
Inferred Environment Variables =
Global Environment Variables = SOME_ENV_VAR=, VERCEL_ANALYTICS_ID=
14 changes: 7 additions & 7 deletions cli/integration_tests/basic_monorepo/dry_run_json.t
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ Setup
"configured": [],
"inferred": [],
"global": [
"SOME_ENV_VAR=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"VERCEL_ANALYTICS_ID=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
"SOME_ENV_VAR=",
"VERCEL_ANALYTICS_ID="
]
},
"hashOfExternalDependencies": "ccab0b28617f1f56"
Expand Down Expand Up @@ -148,12 +148,12 @@ Setup
"framework": "<NO FRAMEWORK DETECTED>",
"environmentVariables": {
"configured": [
"NODE_ENV=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
"NODE_ENV="
],
"inferred": [],
"global": [
"SOME_ENV_VAR=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"VERCEL_ANALYTICS_ID=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
"SOME_ENV_VAR=",
"VERCEL_ANALYTICS_ID="
]
},
"hashOfExternalDependencies": "ccab0b28617f1f56"
Expand All @@ -167,8 +167,8 @@ Run again with NODE_ENV set and see the value in the summary. --filter=util work
],
"inferred": [],
"global": [
"SOME_ENV_VAR=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"VERCEL_ANALYTICS_ID=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
"SOME_ENV_VAR=",
"VERCEL_ANALYTICS_ID="
]
}

Expand Down
4 changes: 2 additions & 2 deletions cli/integration_tests/single_package/dry-run.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Check
Inputs Files Considered = 4
Configured Environment Variables =
Inferred Environment Variables =
Global Environment Variables = VERCEL_ANALYTICS_ID=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Global Environment Variables = VERCEL_ANALYTICS_ID=
ResolvedTaskDefinition = {"outputs":["foo"],"cache":true,"dependsOn":[],"inputs":[],"outputMode":"full","env":[],"persistent":false}
Framework = <NO FRAMEWORK DETECTED>

Expand Down Expand Up @@ -71,7 +71,7 @@ Check
"configured": [],
"inferred": [],
"global": [
"VERCEL_ANALYTICS_ID=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
"VERCEL_ANALYTICS_ID="
]
},
"hashOfExternalDependencies": ""
Expand Down
8 changes: 4 additions & 4 deletions cli/integration_tests/single_package_deps/dry-run.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Check
Inputs Files Considered = 4
Configured Environment Variables =
Inferred Environment Variables =
Global Environment Variables = VERCEL_ANALYTICS_ID=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Global Environment Variables = VERCEL_ANALYTICS_ID=
ResolvedTaskDefinition = {"outputs":["foo"],"cache":true,"dependsOn":[],"inputs":[],"outputMode":"full","env":[],"persistent":false}
Framework = <NO FRAMEWORK DETECTED>
test
Expand All @@ -41,7 +41,7 @@ Check
Inputs Files Considered = 4
Configured Environment Variables =
Inferred Environment Variables =
Global Environment Variables = VERCEL_ANALYTICS_ID=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Global Environment Variables = VERCEL_ANALYTICS_ID=
ResolvedTaskDefinition = {"outputs":[],"cache":true,"dependsOn":["build"],"inputs":[],"outputMode":"full","env":[],"persistent":false}
Framework = <NO FRAMEWORK DETECTED>

Expand Down Expand Up @@ -89,7 +89,7 @@ Check
"configured": [],
"inferred": [],
"global": [
"VERCEL_ANALYTICS_ID=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
"VERCEL_ANALYTICS_ID="
]
},
"hashOfExternalDependencies": ""
Expand Down Expand Up @@ -133,7 +133,7 @@ Check
"configured": [],
"inferred": [],
"global": [
"VERCEL_ANALYTICS_ID=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
"VERCEL_ANALYTICS_ID="
]
},
"hashOfExternalDependencies": ""
Expand Down
4 changes: 2 additions & 2 deletions cli/integration_tests/single_package_no_config/dry-run.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Check
Inputs Files Considered = 3
Configured Environment Variables =
Inferred Environment Variables =
Global Environment Variables = VERCEL_ANALYTICS_ID=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Global Environment Variables = VERCEL_ANALYTICS_ID=
ResolvedTaskDefinition = {"outputs":[],"cache":false,"dependsOn":[],"inputs":[],"outputMode":"full","env":[],"persistent":false}
Framework = <NO FRAMEWORK DETECTED>

Expand Down Expand Up @@ -66,7 +66,7 @@ Check
"configured": [],
"inferred": [],
"global": [
"VERCEL_ANALYTICS_ID=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
"VERCEL_ANALYTICS_ID="
]
},
"hashOfExternalDependencies": ""
Expand Down
8 changes: 6 additions & 2 deletions cli/internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ func (evm EnvironmentVariableMap) mapToPair(transformer func(k string, v string)
// This is the value used to print out the task hash input, so the values are cryptographically hashed
func (evm EnvironmentVariableMap) ToSecretHashable() EnvironmentVariablePairs {
return evm.mapToPair(func(k, v string) string {
hashedValue := sha256.Sum256([]byte(v))
return fmt.Sprintf("%v=%x", k, hashedValue)
if v != "" {
hashedValue := sha256.Sum256([]byte(v))
return fmt.Sprintf("%v=%x", k, hashedValue)
}

return fmt.Sprintf("%v=%s", k, "")
})
}

Expand Down

0 comments on commit 71f4b24

Please sign in to comment.