Skip to content

Commit

Permalink
Restore summaries for run commands. (vercel#8587)
Browse files Browse the repository at this point in the history
### Description

Fixes vercel#8290 

Bring back the summary of runs when using `turbo run`.

### Testing Instructions

👀
  • Loading branch information
anthonyshew authored Jun 24, 2024
1 parent 8c65c36 commit 16685e4
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub async fn run(base: CommandBase, telemetry: CommandEventBuilder) -> Result<i3

let (sender, handle) = run.start_experimental_ui()?.unzip();

let result = run.run(sender.clone()).await;
let result = run.run(sender.clone(), false).await;

if let Some(analytics_handle) = analytics_handle {
analytics_handle.close_with_timeout().await;
Expand Down
8 changes: 6 additions & 2 deletions crates/turborepo-lib/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ impl Run {
Ok(Some((sender, handle)))
}

pub async fn run(&mut self, experimental_ui_sender: Option<AppSender>) -> Result<i32, Error> {
pub async fn run(
&mut self,
experimental_ui_sender: Option<AppSender>,
is_watch: bool,
) -> Result<i32, Error> {
if let Some(subscriber) = self.signal_handler.subscribe() {
let run_cache = self.run_cache.clone();
tokio::spawn(async move {
Expand Down Expand Up @@ -349,6 +353,7 @@ impl Run {
&self.repo_root,
global_env,
experimental_ui_sender,
is_watch,
);

if self.opts.run_opts.dry_run.is_some() {
Expand Down Expand Up @@ -387,7 +392,6 @@ impl Run {
&self.engine,
&self.env_at_execution_start,
self.opts.scope_opts.pkg_inference_root.as_deref(),
self.experimental_ui,
)
.await?;

Expand Down
8 changes: 4 additions & 4 deletions crates/turborepo-lib/src/run/summary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ impl RunTracker {
engine: &'a Engine,
hash_tracker: TaskHashTracker,
env_at_execution_start: &'a EnvironmentVariableMap,
has_experimental_ui: bool,
is_watch: bool,
) -> Result<(), Error> {
let end_time = Local::now();

Expand Down Expand Up @@ -286,7 +286,7 @@ impl RunTracker {
.await?;

run_summary
.finish(end_time, exit_code, pkg_dep_graph, ui, has_experimental_ui)
.finish(end_time, exit_code, pkg_dep_graph, ui, is_watch)
.await
}

Expand Down Expand Up @@ -361,7 +361,7 @@ impl<'a> RunSummary<'a> {
exit_code: i32,
pkg_dep_graph: &PackageGraph,
ui: UI,
has_experimental_ui: bool,
is_watch: bool,
) -> Result<(), Error> {
if matches!(self.run_type, RunType::DryJson | RunType::DryText) {
return self.close_dry_run(pkg_dep_graph, ui);
Expand All @@ -373,7 +373,7 @@ impl<'a> RunSummary<'a> {
}
}

if !has_experimental_ui {
if !is_watch {
if let Some(execution) = &self.execution {
let path = self.get_path();
let failed_tasks = self.get_failed_tasks();
Expand Down
13 changes: 6 additions & 7 deletions crates/turborepo-lib/src/run/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl WatchClient {
.build(&signal_handler, telemetry)
.await?;

Ok(run.run(self.ui_sender.clone()).await?)
Ok(run.run(self.ui_sender.clone(), true).await?)
}
ChangedPackages::All => {
let mut args = self.base.args().clone();
Expand Down Expand Up @@ -321,16 +321,15 @@ impl WatchClient {
let ui_sender = self.ui_sender.clone();
// If we have persistent tasks, we run them on a separate thread
// since persistent tasks don't finish
self.persistent_tasks_handle =
Some(tokio::spawn(
async move { persistent_run.run(ui_sender).await },
));
self.persistent_tasks_handle = Some(tokio::spawn(async move {
persistent_run.run(ui_sender, true).await
}));

// But we still run the regular tasks blocking
let mut non_persistent_run = self.run.create_run_without_persistent_tasks();
Ok(non_persistent_run.run(self.ui_sender.clone()).await?)
Ok(non_persistent_run.run(self.ui_sender.clone(), true).await?)
} else {
Ok(self.run.run(self.ui_sender.clone()).await?)
Ok(self.run.run(self.ui_sender.clone(), true).await?)
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions crates/turborepo-lib/src/task_graph/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub struct Visitor<'a> {
task_hasher: TaskHasher<'a>,
ui: UI,
experimental_ui_sender: Option<AppSender>,
is_watch: bool,
}

#[derive(Debug, thiserror::Error)]
Expand Down Expand Up @@ -109,6 +110,7 @@ impl<'a> Visitor<'a> {
repo_root: &'a AbsoluteSystemPath,
global_env: EnvironmentVariableMap,
experimental_ui_sender: Option<AppSender>,
is_watch: bool,
) -> Self {
let task_hasher = TaskHasher::new(
package_inputs_hashes,
Expand Down Expand Up @@ -136,6 +138,7 @@ impl<'a> Visitor<'a> {
ui,
global_env,
experimental_ui_sender,
is_watch,
}
}

Expand Down Expand Up @@ -301,6 +304,12 @@ impl<'a> Visitor<'a> {
}
drop(factory);

if !self.is_watch {
if let Some(handle) = &self.experimental_ui_sender {
handle.stop();
}
}

if !internal_errors.is_empty() {
return Err(Error::InternalErrors(
internal_errors.into_iter().map(|e| e.to_string()).join(","),
Expand Down Expand Up @@ -337,7 +346,6 @@ impl<'a> Visitor<'a> {
engine: &Engine,
env_at_execution_start: &EnvironmentVariableMap,
pkg_inference_root: Option<&AnchoredSystemPath>,
has_experimental_ui: bool,
) -> Result<(), Error> {
let Self {
package_graph,
Expand All @@ -346,6 +354,7 @@ impl<'a> Visitor<'a> {
repo_root,
global_env_mode,
task_hasher,
is_watch,
..
} = self;

Expand All @@ -366,7 +375,7 @@ impl<'a> Visitor<'a> {
engine,
task_hasher.task_hash_tracker(),
env_at_execution_start,
has_experimental_ui,
is_watch,
)
.await?)
}
Expand Down
3 changes: 2 additions & 1 deletion turbo.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"$schema": "./docs/public/schema.json",
"$schema": "https://turbo.build/schema.json",
"ui": "tui",
// The following are used by tools such as pnpm, gh actions to setup pnpm, and the Go toolchain
"globalPassThroughEnv": [
"Path",
Expand Down

0 comments on commit 16685e4

Please sign in to comment.