diff --git a/CHANGELOG.md b/CHANGELOG.md index 43073d45934..9020b540542 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +#### 🐞 Fixes + +- Fixed an issue where a task with explicit no inputs (`inputs: []`) would always be marked as affected. + #### ⚙️ Internal - Updated proto to v0.43.0 (from 0.42.2). diff --git a/crates/affected/src/affected_tracker.rs b/crates/affected/src/affected_tracker.rs index f40008578e2..b92ad161be5 100644 --- a/crates/affected/src/affected_tracker.rs +++ b/crates/affected/src/affected_tracker.rs @@ -324,7 +324,7 @@ impl<'app> AffectedTracker<'app> { // inputs: [] if task.state.empty_inputs { - return Ok(Some(AffectedBy::AlwaysAffected)); + return Ok(None); } for var_name in &task.input_env { diff --git a/crates/affected/tests/__fixtures__/tasks/base/moon.yml b/crates/affected/tests/__fixtures__/tasks/base/moon.yml index 969f53f1e9e..9cd70fa8269 100644 --- a/crates/affected/tests/__fixtures__/tasks/base/moon.yml +++ b/crates/affected/tests/__fixtures__/tasks/base/moon.yml @@ -3,7 +3,15 @@ tasks: b: {} c: {} - # Affected by env vars by-env: inputs: - '$ENV' + by-file: + inputs: + - 'file.txt' + by-glob: + inputs: + - '*.txt' + + no-inputs: + inputs: [] diff --git a/crates/affected/tests/affected_tracker_test.rs b/crates/affected/tests/affected_tracker_test.rs index b811540ab9d..2b078e4d7f9 100644 --- a/crates/affected/tests/affected_tracker_test.rs +++ b/crates/affected/tests/affected_tracker_test.rs @@ -402,12 +402,90 @@ mod affected_tasks { let touched_files = FxHashSet::default(); let mut tracker = AffectedTracker::new(&workspace_graph, &touched_files); - tracker.track_projects().unwrap(); + tracker.track_tasks().unwrap(); let affected = tracker.build(); assert!(affected.tasks.is_empty()); } + #[tokio::test] + async fn not_affected_if_no_inputs() { + let workspace_graph = generate_workspace_graph("tasks").await; + let touched_files = FxHashSet::from_iter(["base/file.txt".into()]); + + let mut tracker = AffectedTracker::new(&workspace_graph, &touched_files); + tracker + .track_tasks_by_target(&[Target::parse("base:no-inputs").unwrap()]) + .unwrap(); + let affected = tracker.build(); + + assert!(affected.tasks.is_empty()); + } + + #[tokio::test] + async fn affected_by_file() { + let workspace_graph = generate_workspace_graph("tasks").await; + let touched_files = FxHashSet::from_iter(["base/file.txt".into()]); + + let mut tracker = AffectedTracker::new(&workspace_graph, &touched_files); + tracker + .track_tasks_by_target(&[Target::parse("base:by-file").unwrap()]) + .unwrap(); + let affected = tracker.build(); + + assert_eq!( + affected.tasks, + FxHashMap::from_iter([( + Target::parse("base:by-file").unwrap(), + create_state_from_file("base/file.txt") + )]) + ); + } + + #[tokio::test] + async fn affected_by_glob() { + let workspace_graph = generate_workspace_graph("tasks").await; + let touched_files = FxHashSet::from_iter(["base/file.txt".into()]); + + let mut tracker = AffectedTracker::new(&workspace_graph, &touched_files); + tracker + .track_tasks_by_target(&[Target::parse("base:by-glob").unwrap()]) + .unwrap(); + let affected = tracker.build(); + + assert_eq!( + affected.tasks, + FxHashMap::from_iter([( + Target::parse("base:by-glob").unwrap(), + create_state_from_file("base/file.txt") + )]) + ); + } + + #[tokio::test] + async fn affected_by_env_var() { + let workspace_graph = generate_workspace_graph("tasks").await; + let touched_files = FxHashSet::default(); + + env::set_var("ENV", "affected"); + + let mut tracker = AffectedTracker::new(&workspace_graph, &touched_files); + tracker + .track_tasks_by_target(&[Target::parse("base:by-env").unwrap()]) + .unwrap(); + let affected = tracker.build(); + + assert_eq!( + affected.tasks, + FxHashMap::from_iter([( + Target::parse("base:by-env").unwrap(), + create_state_from_env("ENV") + )]) + ); + + env::remove_var("ENV"); + } + #[tokio::test] async fn self_scope() { let workspace_graph = generate_workspace_graph("tasks").await; @@ -472,30 +550,6 @@ mod affected_tasks { ); } - #[tokio::test] - async fn by_env_var() { - let workspace_graph = generate_workspace_graph("tasks").await; - let touched_files = FxHashSet::default(); - - env::set_var("ENV", "affected"); - - let mut tracker = AffectedTracker::new(&workspace_graph, &touched_files); - tracker - .track_tasks_by_target(&[Target::parse("base:by-env").unwrap()]) - .unwrap(); - let affected = tracker.build(); - - assert_eq!( - affected.tasks, - FxHashMap::from_iter([( - Target::parse("base:by-env").unwrap(), - create_state_from_env("ENV") - )]) - ); - - env::remove_var("ENV"); - } - #[tokio::test] async fn marks_dependency_if_dependent_is_touched() { let workspace_graph = generate_workspace_graph("tasks").await; diff --git a/website/docs/guides/root-project.mdx b/website/docs/guides/root-project.mdx index dda65fa1074..31a6cf828e9 100644 --- a/website/docs/guides/root-project.mdx +++ b/website/docs/guides/root-project.mdx @@ -43,7 +43,7 @@ And that's it, but there are a few caveats to be aware of... :::warning -In moon v1.24, root-level tasks default to no inputs. In previous versions, inputs default to +In moon v1.24, root-level tasks default to no inputs. In previous versions, inputs defaulted to `**/*`. This section is only applicable for older moon versions! :::