Skip to content

Commit

Permalink
fix: Allow internal tasks in affected tracker.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Nov 28, 2024
1 parent ea87b53 commit 3a0192e
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 31 deletions.
8 changes: 4 additions & 4 deletions crates/action-graph/src/action_graph_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions crates/action-graph/tests/action_graph_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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())
Expand Down
6 changes: 4 additions & 2 deletions crates/affected/src/affected_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
Expand Down Expand Up @@ -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)?;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/app/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
5 changes: 1 addition & 4 deletions crates/app/src/commands/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/app/src/commands/graph/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/app/src/queries/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions crates/project-graph/tests/project_graph_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
);
}
Expand All @@ -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"]
);
}
Expand All @@ -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"]
);
}
Expand All @@ -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"]
);
}
Expand All @@ -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"]
);
}
Expand All @@ -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"]
);
}
Expand All @@ -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"]
);
}
Expand All @@ -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"]
);
}
Expand All @@ -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",
Expand Down Expand Up @@ -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"]
);

Expand Down
10 changes: 8 additions & 2 deletions crates/workspace-graph/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl WorkspaceGraph {
Ok(project)
}

pub fn get_all_projects(&self) -> miette::Result<Vec<Arc<Project>>> {
pub fn get_projects(&self) -> miette::Result<Vec<Arc<Project>>> {
self.projects.get_all()
}

Expand Down Expand Up @@ -93,12 +93,18 @@ impl WorkspaceGraph {
Ok(all)
}

pub fn get_all_tasks(&self) -> miette::Result<Vec<Arc<Task>>> {
/// Get all non-internal tasks.
pub fn get_tasks(&self) -> miette::Result<Vec<Arc<Task>>> {
Ok(self
.tasks
.get_all()?
.into_iter()
.filter(|task| !task.is_internal())
.collect())
}

/// Get all tasks, including internal.
pub fn get_tasks_with_internal(&self) -> miette::Result<Vec<Arc<Task>>> {
self.tasks.get_all()
}
}

0 comments on commit 3a0192e

Please sign in to comment.