Skip to content

Commit

Permalink
Ability to configure skipping build all (#255)
Browse files Browse the repository at this point in the history
* Add ability to configure skipping buildAll in case no projects changed

* Update Doc
  • Loading branch information
tonyhaddad authored Nov 6, 2024
1 parent fc8905a commit 78f344e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ affectedModuleDetector {
ignoredFiles = [
".*\\.md", ".*\\.txt", ".*README"
]
buildAllWhenNoProjectsChanged = true // default is true
includeUncommitted = true
top = "HEAD"
customTasks = [
Expand All @@ -113,6 +114,7 @@ affectedModuleDetector {
- `logFolder`: A folder to output the log file in
- `specifiedBranch`: A branch to specify changes against. Must be used in combination with configuration `compareFrom = "SpecifiedBranchCommit"`
- `ignoredFiles`: A set of files that will be filtered out of the list of changed files retrieved by git.
- `buildAllWhenNoProjectsChanged`: If true, the plugin will build all projects when no projects are considered affected.
- `compareFrom`: A commit to compare the branch changes against. Can be either:
- PreviousCommit: compare against the previous commit
- ForkCommit: compare against the commit the branch was forked from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ class AffectedModuleConfiguration {
*/
var includeUncommitted: Boolean = true

/**
* If we should build all projects when no projects have changed
*/
var buildAllWhenNoProjectsChanged: Boolean = true

/**
* The top of the git log to use, only used when [includeUncommitted] is false
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ class AffectedModuleDetectorImpl constructor(
var buildAll = false

// Should only trigger if there are no changedFiles
if (changedProjects.isEmpty() && unknownFiles.isEmpty()) {
if (config.buildAllWhenNoProjectsChanged && changedProjects.isEmpty() && unknownFiles.isEmpty()) {
buildAll = true
}
logger?.info(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.dropbox.affectedmoduledetector

import com.google.common.truth.Truth.assertThat
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Assert.fail
import org.junit.Before
import org.junit.Rule
Expand Down Expand Up @@ -324,4 +326,29 @@ class AffectedModuleConfigurationTest {

assert(actual.first().taskDescription == "Description of fake task")
}

@Test
fun `GIVEN AffectedModuleConfiguration WHEN buildAllWhenNoProjectsChanged THEN then default value is true`() {
// GIVEN
// config

// WHEN
val buildAllWhenNoProjectsChanged = config.buildAllWhenNoProjectsChanged

// THEN
assertTrue(buildAllWhenNoProjectsChanged)
}

@Test
fun `GIVEN AffectedModuleConfiguration WHEN buildAllWhenNoProjectsChanged is set to false THEN then value is false`() {
// GIVEN
val buildAll = false
config.buildAllWhenNoProjectsChanged = buildAll

// WHEN
val actual = config.buildAllWhenNoProjectsChanged

// THEN
assertFalse(actual)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,29 @@ class AffectedModuleDetectorImplTest {
)
}

@Test
fun noChangeSkipAll() {
val detector = AffectedModuleDetectorImpl(
rootProject = root,
logger = logger,
ignoreUnknownProjects = false,
projectSubset = ProjectSubset.ALL_AFFECTED_PROJECTS,
injectedGitClient = MockGitClient(
changedFiles = emptyList(),
tmpFolder = tmpFolder.root
),
config = affectedModuleConfiguration.also {
it.buildAllWhenNoProjectsChanged = false
}
)
MatcherAssert.assertThat(
detector.affectedProjects,
CoreMatchers.`is`(
emptySet()
)
)
}

@Test
fun changeInOneOnlyDependent() {
val detector = AffectedModuleDetectorImpl(
Expand Down

0 comments on commit 78f344e

Please sign in to comment.