Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix affected for empty inputs. #1746

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion crates/affected/src/affected_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 9 additions & 1 deletion crates/affected/tests/__fixtures__/tasks/base/moon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
104 changes: 79 additions & 25 deletions crates/affected/tests/affected_tracker_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion website/docs/guides/root-project.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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!

:::
Expand Down
Loading