Skip to content

Commit 78f344e

Browse files
authored
Ability to configure skipping build all (#255)
* Add ability to configure skipping buildAll in case no projects changed * Update Doc
1 parent fc8905a commit 78f344e

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ affectedModuleDetector {
9595
ignoredFiles = [
9696
".*\\.md", ".*\\.txt", ".*README"
9797
]
98+
buildAllWhenNoProjectsChanged = true // default is true
9899
includeUncommitted = true
99100
top = "HEAD"
100101
customTasks = [
@@ -113,6 +114,7 @@ affectedModuleDetector {
113114
- `logFolder`: A folder to output the log file in
114115
- `specifiedBranch`: A branch to specify changes against. Must be used in combination with configuration `compareFrom = "SpecifiedBranchCommit"`
115116
- `ignoredFiles`: A set of files that will be filtered out of the list of changed files retrieved by git.
117+
- `buildAllWhenNoProjectsChanged`: If true, the plugin will build all projects when no projects are considered affected.
116118
- `compareFrom`: A commit to compare the branch changes against. Can be either:
117119
- PreviousCommit: compare against the previous commit
118120
- ForkCommit: compare against the commit the branch was forked from

affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleConfiguration.kt

+5
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ class AffectedModuleConfiguration {
115115
*/
116116
var includeUncommitted: Boolean = true
117117

118+
/**
119+
* If we should build all projects when no projects have changed
120+
*/
121+
var buildAllWhenNoProjectsChanged: Boolean = true
122+
118123
/**
119124
* The top of the git log to use, only used when [includeUncommitted] is false
120125
*/

affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ class AffectedModuleDetectorImpl constructor(
482482
var buildAll = false
483483

484484
// Should only trigger if there are no changedFiles
485-
if (changedProjects.isEmpty() && unknownFiles.isEmpty()) {
485+
if (config.buildAllWhenNoProjectsChanged && changedProjects.isEmpty() && unknownFiles.isEmpty()) {
486486
buildAll = true
487487
}
488488
logger?.info(

affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleConfigurationTest.kt

+27
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.dropbox.affectedmoduledetector
22

33
import com.google.common.truth.Truth.assertThat
4+
import org.junit.Assert.assertFalse
5+
import org.junit.Assert.assertTrue
46
import org.junit.Assert.fail
57
import org.junit.Before
68
import org.junit.Rule
@@ -324,4 +326,29 @@ class AffectedModuleConfigurationTest {
324326

325327
assert(actual.first().taskDescription == "Description of fake task")
326328
}
329+
330+
@Test
331+
fun `GIVEN AffectedModuleConfiguration WHEN buildAllWhenNoProjectsChanged THEN then default value is true`() {
332+
// GIVEN
333+
// config
334+
335+
// WHEN
336+
val buildAllWhenNoProjectsChanged = config.buildAllWhenNoProjectsChanged
337+
338+
// THEN
339+
assertTrue(buildAllWhenNoProjectsChanged)
340+
}
341+
342+
@Test
343+
fun `GIVEN AffectedModuleConfiguration WHEN buildAllWhenNoProjectsChanged is set to false THEN then value is false`() {
344+
// GIVEN
345+
val buildAll = false
346+
config.buildAllWhenNoProjectsChanged = buildAll
347+
348+
// WHEN
349+
val actual = config.buildAllWhenNoProjectsChanged
350+
351+
// THEN
352+
assertFalse(actual)
353+
}
327354
}

affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetectorImplTest.kt

+23
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,29 @@ class AffectedModuleDetectorImplTest {
337337
)
338338
}
339339

340+
@Test
341+
fun noChangeSkipAll() {
342+
val detector = AffectedModuleDetectorImpl(
343+
rootProject = root,
344+
logger = logger,
345+
ignoreUnknownProjects = false,
346+
projectSubset = ProjectSubset.ALL_AFFECTED_PROJECTS,
347+
injectedGitClient = MockGitClient(
348+
changedFiles = emptyList(),
349+
tmpFolder = tmpFolder.root
350+
),
351+
config = affectedModuleConfiguration.also {
352+
it.buildAllWhenNoProjectsChanged = false
353+
}
354+
)
355+
MatcherAssert.assertThat(
356+
detector.affectedProjects,
357+
CoreMatchers.`is`(
358+
emptySet()
359+
)
360+
)
361+
}
362+
340363
@Test
341364
fun changeInOneOnlyDependent() {
342365
val detector = AffectedModuleDetectorImpl(

0 commit comments

Comments
 (0)