Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(env): add VERCEL_ENV into default global env map #9635

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions crates/turborepo-env/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use thiserror::Error;

pub mod platform;

const DEFAULT_ENV_VARS: [&str; 1] = ["VERCEL_ANALYTICS_ID"];
const DEFAULT_ENV_VARS: &[&str] = ["VERCEL_ANALYTICS_ID", "VERCEL_ENV"].as_slice();

#[derive(Clone, Debug, Error)]
pub enum Error {
Expand All @@ -22,7 +22,7 @@ pub enum Error {
}

// TODO: Consider using immutable data structures here
#[derive(Clone, Debug, Default, Serialize)]
#[derive(Clone, Debug, Default, Serialize, PartialEq)]
#[serde(transparent)]
pub struct EnvironmentVariableMap(HashMap<String, String>);

Expand Down Expand Up @@ -278,7 +278,7 @@ pub fn get_global_hashable_env_vars(
env_at_execution_start: &EnvironmentVariableMap,
global_env: &[String],
) -> Result<DetailedMap, Error> {
let default_env_var_map = env_at_execution_start.from_wildcards(&DEFAULT_ENV_VARS[..])?;
let default_env_var_map = env_at_execution_start.from_wildcards(DEFAULT_ENV_VARS)?;

let user_env_var_set =
env_at_execution_start.wildcard_map_from_wildcards_unresolved(global_env)?;
Expand Down Expand Up @@ -335,4 +335,27 @@ mod tests {
assert_eq!(actual.get("Turbo"), None);
}
}

#[test_case(&[], &["VERCEL_ANALYTICS_ID", "VERCEL_ENV"] ; "defaults")]
#[test_case(&["!VERCEL*"], &[] ; "removing defaults")]
#[test_case(&["FOO*", "!FOOD"], &["FOO", "FOOBAR", "VERCEL_ANALYTICS_ID", "VERCEL_ENV"] ; "intersecting globs")]
fn test_global_env(inputs: &[&str], expected: &[&str]) {
let env_at_start = EnvironmentVariableMap(
vec![
("VERCEL_ENV", "prod"),
("VERCEL_ANALYTICS_ID", "1"),
("FOO", "bar"),
("FOOBAR", "baz"),
("FOOD", "cheese"),
]
.into_iter()
.map(|(k, v)| (k.to_owned(), v.to_owned()))
.collect(),
);
let inputs = inputs.iter().map(|s| s.to_string()).collect::<Vec<_>>();
let actual = get_global_hashable_env_vars(&env_at_start, &inputs).unwrap();
let mut actual = actual.all.keys().map(|s| s.as_str()).collect::<Vec<_>>();
actual.sort();
assert_eq!(actual, expected);
}
}
Loading