Skip to content

Commit

Permalink
chore(config): move TURBO_RUN_SUMMARY to config
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-olszewski committed Sep 5, 2024
1 parent 3b98c16 commit 5bbc8c3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
7 changes: 6 additions & 1 deletion crates/turborepo-lib/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ pub struct RunArgs {
#[clap(long, default_missing_value = "true")]
pub remote_cache_read_only: Option<Option<bool>>,
/// Generate a summary of the turbo run
#[clap(long, env = "TURBO_RUN_SUMMARY", default_missing_value = "true")]
#[clap(long, default_missing_value = "true")]
pub summarize: Option<Option<bool>>,

// Pass a string to enable posting Run Summaries to Vercel
Expand Down Expand Up @@ -959,6 +959,11 @@ impl RunArgs {
Some(remote_cache_read_only.unwrap_or(true))
}

pub fn summarize(&self) -> Option<bool> {
let summarize = self.summarize?;
Some(summarize.unwrap_or(true))
}

pub fn track(&self, telemetry: &CommandEventBuilder) {
// default to true
track_usage!(telemetry, self.no_cache, |val| val);
Expand Down
1 change: 1 addition & 0 deletions crates/turborepo-lib/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ impl CommandBase {
.run_args()
.and_then(|args| args.remote_cache_read_only()),
)
.with_run_summary(self.args.run_args().and_then(|args| args.summarize()))
.build()
}

Expand Down
7 changes: 7 additions & 0 deletions crates/turborepo-lib/src/config/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const TURBO_MAPPING: &[(&str, &str)] = [
("turbo_log_order", "log_order"),
("turbo_remote_only", "remote_only"),
("turbo_remote_cache_read_only", "remote_cache_read_only"),
("turbo_run_summary", "run_summary"),
]
.as_slice();

Expand Down Expand Up @@ -84,6 +85,7 @@ impl ResolvedConfigurationOptions for EnvVars {
let force = self.truthy_value("force").flatten();
let remote_only = self.truthy_value("remote_only").flatten();
let remote_cache_read_only = self.truthy_value("remote_cache_read_only").flatten();
let run_summary = self.truthy_value("run_summary").flatten();

// Process timeout
let timeout = self
Expand Down Expand Up @@ -168,6 +170,7 @@ impl ResolvedConfigurationOptions for EnvVars {
force,
remote_only,
remote_cache_read_only,
run_summary,

// Processed numbers
timeout,
Expand Down Expand Up @@ -313,6 +316,7 @@ mod test {
env.insert("turbo_log_order".into(), "grouped".into());
env.insert("turbo_remote_only".into(), "1".into());
env.insert("turbo_remote_cache_read_only".into(), "1".into());
env.insert("turbo_run_summary".into(), "true".into());

let config = EnvVars::new(&env)
.unwrap()
Expand All @@ -323,6 +327,7 @@ mod test {
assert_eq!(config.log_order(), LogOrder::Grouped);
assert!(config.remote_only());
assert!(config.remote_cache_read_only());
assert!(config.run_summary());
assert_eq!(turbo_api, config.api_url.unwrap());
assert_eq!(turbo_login, config.login_url.unwrap());
assert_eq!(turbo_team, config.team_slug.unwrap());
Expand Down Expand Up @@ -359,6 +364,7 @@ mod test {
env.insert("turbo_log_order".into(), "".into());
env.insert("turbo_remote_only".into(), "".into());
env.insert("turbo_remote_cache_read_only".into(), "".into());
env.insert("turbo_run_summary".into(), "".into());

let config = EnvVars::new(&env)
.unwrap()
Expand All @@ -380,6 +386,7 @@ mod test {
assert_eq!(config.log_order(), LogOrder::Auto);
assert!(!config.remote_only());
assert!(!config.remote_cache_read_only());
assert!(!config.run_summary());
}

#[test]
Expand Down
5 changes: 5 additions & 0 deletions crates/turborepo-lib/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ pub struct ConfigurationOptions {
pub(crate) log_order: Option<LogOrder>,
pub(crate) remote_only: Option<bool>,
pub(crate) remote_cache_read_only: Option<bool>,
pub(crate) run_summary: Option<bool>,
}

#[derive(Default)]
Expand Down Expand Up @@ -357,6 +358,10 @@ impl ConfigurationOptions {
self.remote_cache_read_only.unwrap_or_default()
}

pub fn run_summary(&self) -> bool {
self.run_summary.unwrap_or_default()
}

pub fn root_turbo_json_path(&self, repo_root: &AbsoluteSystemPath) -> AbsoluteSystemPathBuf {
self.root_turbo_json_path
.clone()
Expand Down
6 changes: 3 additions & 3 deletions crates/turborepo-lib/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub struct RunOpts {
pub(crate) single_package: bool,
pub log_prefix: ResolvedLogPrefix,
pub log_order: ResolvedLogOrder,
pub summarize: Option<Option<bool>>,
pub summarize: bool,
pub(crate) experimental_space_id: Option<String>,
pub is_github_actions: bool,
}
Expand Down Expand Up @@ -247,7 +247,7 @@ impl<'a> TryFrom<OptsInputs<'a>> for RunOpts {
tasks: inputs.execution_args.tasks.clone(),
log_prefix,
log_order,
summarize: inputs.run_args.summarize,
summarize: inputs.config.run_summary(),
experimental_space_id: inputs
.run_args
.experimental_space_id
Expand Down Expand Up @@ -502,7 +502,7 @@ mod test {
single_package: false,
log_prefix: crate::opts::ResolvedLogPrefix::Task,
log_order: crate::opts::ResolvedLogOrder::Stream,
summarize: None,
summarize: false,
experimental_space_id: None,
is_github_actions: false,
daemon: None,
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/run/summary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl RunTracker {
task_factory: TaskSummaryFactory<'a>,
) -> Result<RunSummary<'a>, Error> {
let single_package = run_opts.single_package;
let should_save = run_opts.summarize.flatten().is_some_and(|s| s);
let should_save = run_opts.summarize;

let run_type = match run_opts.dry_run {
None => RunType::Real,
Expand Down

0 comments on commit 5bbc8c3

Please sign in to comment.