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(filter): account for root internal dependencies in git based filter #8364

Merged
merged 1 commit into from
Jun 7, 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
3 changes: 2 additions & 1 deletion crates/turborepo-lib/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ impl Run {
get_internal_deps_hash(
&self.scm,
&self.repo_root,
self.pkg_dep_graph.root_internal_package_dependencies(),
self.pkg_dep_graph
.root_internal_package_dependencies_paths(),
)
})
.transpose()?;
Expand Down
5 changes: 5 additions & 0 deletions crates/turborepo-repository/src/change_mapper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,14 @@ impl<'a, PD: PackageChangeMapper> ChangeMapper<'a, PD> {
&self,
files: impl Iterator<Item = &'b AnchoredSystemPathBuf>,
) -> PackageChanges {
let root_internal_deps = self.pkg_graph.root_internal_package_dependencies();
let mut changed_packages = HashSet::new();
for file in files {
match self.package_detector.detect_package(file) {
// Internal root dependency changed so global hash has changed
PackageMapping::Package(pkg) if root_internal_deps.contains(&pkg) => {
return PackageChanges::All;
}
PackageMapping::Package(pkg) => {
changed_packages.insert(pkg);
}
Expand Down
21 changes: 20 additions & 1 deletion crates/turborepo-repository/src/package_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,26 @@ impl PackageGraph {
dependents
}

pub fn root_internal_package_dependencies(&self) -> Vec<&AnchoredSystemPath> {
pub fn root_internal_package_dependencies(&self) -> HashSet<WorkspacePackage> {
let dependencies = self.dependencies(&PackageNode::Workspace(PackageName::Root));
dependencies
.into_iter()
.filter_map(|package| match package {
PackageNode::Workspace(package) => {
let path = self
.package_dir(package)
.expect("packages in graph should have info");
Some(WorkspacePackage {
name: package.clone(),
path: path.to_owned(),
})
}
PackageNode::Root => None,
})
.collect()
}

pub fn root_internal_package_dependencies_paths(&self) -> Vec<&AnchoredSystemPath> {
let dependencies = self.dependencies(&PackageNode::Workspace(PackageName::Root));
dependencies
.into_iter()
Expand Down
14 changes: 14 additions & 0 deletions turborepo-tests/integration/tests/run-caching/root-deps.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Setup
$ . ${TESTDIR}/../../../helpers/setup_integration_test.sh root_deps

Verify that no packages are in scope
$ ${TURBO} build --filter='[HEAD]' --dry=json | jq '.packages'
[]

Warm the cache
$ ${TURBO} build --filter=another --output-logs=hash-only
\xe2\x80\xa2 Packages in scope: another (esc)
Expand Down Expand Up @@ -40,6 +44,16 @@ All tasks should be a cache miss, even ones that don't depend on changed package
Time:\s+[.0-9]+m?s (re)


Verify that all packages are in scope on a internal root dep change
$ ${TURBO} build --filter='[HEAD]' --dry=json | jq '.packages'
[
"//",
"another",
"my-app",
"util",
"yet-another"
]

Change a file that is git ignored
$ mkdir packages/util/dist
$ touch packages/util/dist/unused.txt
Expand Down
Loading