diff --git a/crates/action-graph/src/action_graph_builder.rs b/crates/action-graph/src/action_graph_builder.rs index 27212e955e..661c42a14b 100644 --- a/crates/action-graph/src/action_graph_builder.rs +++ b/crates/action-graph/src/action_graph_builder.rs @@ -142,8 +142,8 @@ impl<'app> ActionGraphBuilder<'app> { if downstream != DownstreamScope::None { debug!("Force loading all projects and tasks to determine relationships"); - self.workspace_graph.get_all_projects()?; - self.workspace_graph.get_all_tasks()?; + self.workspace_graph.get_projects()?; + self.workspace_graph.get_tasks_with_internal()?; } self.affected @@ -491,7 +491,7 @@ impl<'app> ActionGraphBuilder<'app> { if let Some(all_query) = &self.all_query { projects.extend(self.workspace_graph.query_projects(all_query)?); } else { - projects.extend(self.workspace_graph.get_all_projects()?); + projects.extend(self.workspace_graph.get_projects()?); }; for project in projects { @@ -589,7 +589,7 @@ impl<'app> ActionGraphBuilder<'app> { // Determine affected tasks before building if let Some(affected) = &mut self.affected { - affected.track_tasks_by_target(&initial_targets)?; + affected.track_tasks()?; } // Then build and track initial and primary diff --git a/crates/action-graph/tests/action_graph_test.rs b/crates/action-graph/tests/action_graph_test.rs index 57ad95d779..ff21740959 100644 --- a/crates/action-graph/tests/action_graph_test.rs +++ b/crates/action-graph/tests/action_graph_test.rs @@ -354,14 +354,13 @@ mod action_graph { let graph = builder.build(); - assert!(topo(graph) - .into_iter() - .find(|node| if let ActionNode::RunTask(inner) = &node { + assert!(!topo(graph).into_iter().any(|node| { + if let ActionNode::RunTask(inner) = &node { inner.target.as_str() == "bar:build" } else { false - }) - .is_none()); + } + })); } #[tokio::test] @@ -384,7 +383,8 @@ mod action_graph { .affected .as_mut() .unwrap() - .mark_task_affected(&task, moon_affected::AffectedBy::AlwaysAffected); + .mark_task_affected(&task, moon_affected::AffectedBy::AlwaysAffected) + .unwrap(); builder .run_task(&project, &task, &RunRequirements::default()) diff --git a/crates/affected/src/affected_tracker.rs b/crates/affected/src/affected_tracker.rs index 49b7740f06..769f9d86bf 100644 --- a/crates/affected/src/affected_tracker.rs +++ b/crates/affected/src/affected_tracker.rs @@ -127,7 +127,7 @@ impl<'app> AffectedTracker<'app> { pub fn track_projects(&mut self) -> miette::Result<&mut Self> { debug!("Tracking projects and marking any affected"); - for project in self.workspace_graph.get_all_projects()? { + for project in self.workspace_graph.get_projects()? { if let Some(affected) = self.is_project_affected(&project) { self.mark_project_affected(&project, affected)?; } @@ -263,7 +263,9 @@ impl<'app> AffectedTracker<'app> { pub fn track_tasks(&mut self) -> miette::Result<()> { debug!("Tracking tasks and marking any affected"); - for task in self.workspace_graph.get_all_tasks()? { + // Include internal since they can trigger affected + // for any dependents! + for task in self.workspace_graph.get_tasks_with_internal()? { if let Some(affected) = self.is_task_affected(&task)? { self.mark_task_affected(&task, affected)?; } diff --git a/crates/app/src/commands/check.rs b/crates/app/src/commands/check.rs index 6a36ab8c6a..4ed3877b52 100644 --- a/crates/app/src/commands/check.rs +++ b/crates/app/src/commands/check.rs @@ -42,7 +42,7 @@ pub async fn check(session: CliSession, args: CheckArgs) -> AppResult { if args.all { trace!("Running check on all projects"); - projects.extend(workspace_graph.get_all_projects()?); + projects.extend(workspace_graph.get_projects()?); } else if args.ids.is_empty() { trace!("Loading from path"); diff --git a/crates/app/src/commands/ci.rs b/crates/app/src/commands/ci.rs index 47e4d12118..be4ab63e5a 100644 --- a/crates/app/src/commands/ci.rs +++ b/crates/app/src/commands/ci.rs @@ -149,11 +149,8 @@ async fn gather_potential_targets( let mut targets = vec![]; - // Required for dependents - workspace_graph.get_all_projects()?; - if args.targets.is_empty() { - for task in workspace_graph.get_all_tasks()? { + for task in workspace_graph.get_tasks()? { targets.push(task.target.clone()); } } else { diff --git a/crates/app/src/commands/graph/action.rs b/crates/app/src/commands/graph/action.rs index a8841f1b97..dcfe3c427f 100644 --- a/crates/app/src/commands/graph/action.rs +++ b/crates/app/src/commands/graph/action.rs @@ -41,7 +41,7 @@ pub async fn action_graph(session: CliSession, args: ActionGraphArgs) -> AppResu // Show all targets and actions } else { - for project in workspace_graph.get_all_projects()? { + for project in workspace_graph.get_projects()? { for task in workspace_graph.get_tasks_from_project(&project.id)? { action_graph_builder.run_task(&project, &task, &requirements)?; } diff --git a/crates/app/src/queries/tasks.rs b/crates/app/src/queries/tasks.rs index 7a2fb6faf6..6b821d407a 100644 --- a/crates/app/src/queries/tasks.rs +++ b/crates/app/src/queries/tasks.rs @@ -48,7 +48,7 @@ fn load_with_regex( let type_regex = convert_to_regex("type", &options.type_of)?; let mut filtered = vec![]; - for task in workspace_graph.get_all_tasks()? { + for task in workspace_graph.get_tasks()? { if let Some(regex) = &id_regex { if !regex.is_match(&task.id) { continue; diff --git a/crates/project-graph/tests/project_graph_test.rs b/crates/project-graph/tests/project_graph_test.rs index b1a9486c00..dd29d1953c 100644 --- a/crates/project-graph/tests/project_graph_test.rs +++ b/crates/project-graph/tests/project_graph_test.rs @@ -106,7 +106,7 @@ mod project_graph { let graph = generate_workspace_graph("dependencies").await; assert_eq!( - get_ids_from_projects(graph.get_all_projects().unwrap()), + get_ids_from_projects(graph.get_projects().unwrap()), ["a", "b", "c", "d"] ); } @@ -126,7 +126,7 @@ mod project_graph { let graph = mock.build_workspace_graph().await; assert_eq!( - get_ids_from_projects(graph.get_all_projects().unwrap()), + get_ids_from_projects(graph.get_projects().unwrap()), ["a", "b", "c", "d", "dir"] ); } @@ -141,7 +141,7 @@ mod project_graph { let graph = mock.build_workspace_graph().await; assert_eq!( - get_ids_from_projects(graph.get_all_projects().unwrap()), + get_ids_from_projects(graph.get_projects().unwrap()), ["a", "c"] ); } @@ -159,7 +159,7 @@ mod project_graph { let graph = mock.build_workspace_graph().await; assert_eq!( - get_ids_from_projects(graph.get_all_projects().unwrap()), + get_ids_from_projects(graph.get_projects().unwrap()), ["b", "c"] ); } @@ -180,7 +180,7 @@ mod project_graph { let graph = mock.build_workspace_graph().await; assert_eq!( - get_ids_from_projects(graph.get_all_projects().unwrap()), + get_ids_from_projects(graph.get_projects().unwrap()), ["a", "b", "c", "root"] ); } @@ -195,7 +195,7 @@ mod project_graph { let graph = generate_workspace_graph_from_sandbox(sandbox.path()).await; assert_eq!( - get_ids_from_projects(graph.get_all_projects().unwrap()), + get_ids_from_projects(graph.get_projects().unwrap()), ["a", "b", "c", "d"] ); } @@ -208,7 +208,7 @@ mod project_graph { let graph = generate_workspace_graph_from_sandbox(sandbox.path()).await; assert_eq!( - get_ids_from_projects(graph.get_all_projects().unwrap()), + get_ids_from_projects(graph.get_projects().unwrap()), ["a", "b", "c", "d"] ); } @@ -226,7 +226,7 @@ mod project_graph { let graph = mock.build_workspace_graph().await; assert_eq!( - get_ids_from_projects(graph.get_all_projects().unwrap()), + get_ids_from_projects(graph.get_projects().unwrap()), ["app", "library", "tool", "unknown"] ); } @@ -236,7 +236,7 @@ mod project_graph { let graph = generate_workspace_graph("ids").await; assert_eq!( - get_ids_from_projects(graph.get_all_projects().unwrap()), + get_ids_from_projects(graph.get_projects().unwrap()), [ "Capital", "PascalCase", @@ -452,7 +452,7 @@ mod project_graph { let graph = generate_workspace_graph("cycle").await; assert_eq!( - get_ids_from_projects(graph.get_all_projects().unwrap()), + get_ids_from_projects(graph.get_projects().unwrap()), ["a", "b", "c"] ); diff --git a/crates/workspace-graph/src/lib.rs b/crates/workspace-graph/src/lib.rs index 52af388a1a..135e44e8fa 100644 --- a/crates/workspace-graph/src/lib.rs +++ b/crates/workspace-graph/src/lib.rs @@ -57,7 +57,7 @@ impl WorkspaceGraph { Ok(project) } - pub fn get_all_projects(&self) -> miette::Result>> { + pub fn get_projects(&self) -> miette::Result>> { self.projects.get_all() } @@ -93,7 +93,8 @@ impl WorkspaceGraph { Ok(all) } - pub fn get_all_tasks(&self) -> miette::Result>> { + /// Get all non-internal tasks. + pub fn get_tasks(&self) -> miette::Result>> { Ok(self .tasks .get_all()? @@ -101,4 +102,9 @@ impl WorkspaceGraph { .filter(|task| !task.is_internal()) .collect()) } + + /// Get all tasks, including internal. + pub fn get_tasks_with_internal(&self) -> miette::Result>> { + self.tasks.get_all() + } }