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

Avoid building all projects when only ignored files are changed in affected module detector #256

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ abstract class AffectedModuleDetector {
rootProject.extensions.findByType(AffectedModuleConfiguration::class.java)
) {
"Root project ${rootProject.path} must have the AffectedModuleConfiguration " +
"extension added."
"extension added."
}

val logger =
Expand Down Expand Up @@ -415,6 +415,10 @@ class AffectedModuleDetectorImpl constructor(
top = top,
includeUncommitted = includeUncommitted
).forEach { fileName ->
if (isIgnoredFile(fileName)) {
// Skip ignored files
return@forEach
}
if (affectsAllModules(fileName)) {
return allProjects
}
Expand All @@ -429,20 +433,24 @@ class AffectedModuleDetectorImpl constructor(
unknownFiles.add(filePath)
logger?.info(
"Couldn't find containing project for file$filePath. " +
"Adding to unknownFiles."
"Adding to unknownFiles."
)
} else {
changedProjects.add(containingProject)
logger?.info(
"For file $filePath containing project is $containingProject. " +
"Adding to changedProjects."
"Adding to changedProjects."
)
}
}

return changedProjects
}

private fun isIgnoredFile(filePath: String): Boolean {
return config.ignoredFiles.any { filePath.matches(it.toRegex()) }
}

/**
* Gets all dependent projects from the set of changedProjects. This doesn't include the
* original changedProjects. Always build is still here to ensure at least 1 thing is built
Expand Down Expand Up @@ -475,13 +483,13 @@ class AffectedModuleDetectorImpl constructor(

var buildAll = false

// Should only trigger if there are no changedFiles
if (changedProjects.isEmpty() && unknownFiles.isEmpty()) {
// Should only trigger if there are no changedFiles and no changes in non-ignored files
if (changedProjects.isEmpty() && unknownFiles.isEmpty() && changedFiles.isEmpty()) {
buildAll = true
}
logger?.info(
"unknownFiles: $unknownFiles, changedProjects: $changedProjects, buildAll: " +
"$buildAll"
"$buildAll"
)

// If we're in a buildAll state, we return allProjects unless it's the changed target,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ class AffectedModuleDetectorImplTest {
affectedModuleConfiguration = AffectedModuleConfiguration().also {
it.baseDir = tmpDir.absolutePath
it.pathsAffectingAllModules = pathsAffectingAllModules
it.ignoredFiles = setOf(".*\\.md", ".*\\.txt", ".*README")
}
}

Expand Down Expand Up @@ -1522,6 +1523,69 @@ class AffectedModuleDetectorImplTest {
)
}

@Test
fun changeInIgnoredFile() {
val detector = AffectedModuleDetectorImpl(
rootProject = root,
logger = logger,
ignoreUnknownProjects = false,
projectSubset = ProjectSubset.ALL_AFFECTED_PROJECTS,
injectedGitClient = MockGitClient(
changedFiles = listOf("README.md"),
tmpFolder = tmpFolder.root
),
config = affectedModuleConfiguration
)
MatcherAssert.assertThat(
detector.affectedProjects,
CoreMatchers.`is`(
emptySet()
)
)
}

@Test
fun changeInIgnoredFileWithDependentProjects() {
val detector = AffectedModuleDetectorImpl(
rootProject = root,
logger = logger,
ignoreUnknownProjects = false,
projectSubset = ProjectSubset.DEPENDENT_PROJECTS,
injectedGitClient = MockGitClient(
changedFiles = listOf("README.md"),
tmpFolder = tmpFolder.root
),
config = affectedModuleConfiguration
)
MatcherAssert.assertThat(
detector.affectedProjects,
CoreMatchers.`is`(
emptySet()
)
)
}

@Test
fun changeInIgnoredFileWithChangedProjects() {
val detector = AffectedModuleDetectorImpl(
rootProject = root,
logger = logger,
ignoreUnknownProjects = false,
projectSubset = ProjectSubset.CHANGED_PROJECTS,
injectedGitClient = MockGitClient(
changedFiles = listOf("README.md"),
tmpFolder = tmpFolder.root
),
config = affectedModuleConfiguration
)
MatcherAssert.assertThat(
detector.affectedProjects,
CoreMatchers.`is`(
emptySet()
)
)
}

// For both Linux/Windows
fun convertToFilePath(vararg list: String): String {
return list.toList().joinToString(File.separator)
Expand Down
Loading