Skip to content
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
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ affectedModuleDetector {
excludedModules = [
"sample-util"
]
includeUncommitted = true
top = "HEAD"
}
```

Expand All @@ -85,14 +87,16 @@ affectedModuleDetector {
- PreviousCommit: compare against the previous commit
- ForkCommit: compare against the commit the branch was forked from
- SpecifiedBranchCommit: specify the branch to compare changes against using the `specifiedBranch` configuration before the `compareFrom` configuration
- `excludedModules` : A list of modules that will be excluded from the build process



- `excludedModules`: A list of modules that will be excluded from the build process
- `includeUncommitted`: If uncommitted files should be considered affected
- `top`: The top of the git log to use. Must be used in combination with configuration `includeUncommitted = false`



By default, the Detector will look for `assembleAndroidDebugTest`, `connectedAndroidDebugTest`, and `testDebug`. Modules can specify a configuration block to specify which variant tests to run:
```groovy
affectedTestConfiguration {
assembleAndroidTestTask = "assmebleAndroidReleaseTest"
assembleAndroidTestTask = "assembleAndroidReleaseTest"
runAndroidTestTask = "connectedAndroidReleaseTest"
jvmTestTask = "testRelease"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ class AffectedModuleConfiguration {
*/
var excludedModules = emptySet<String>()

/**
* If uncommitted files should be considered affected
*/
var includeUncommitted: Boolean = true

/**
* The top of the git log to use, only used when [includeUncommitted] is false
*/
var top: String = "HEAD"
set(value) {
require(!includeUncommitted) {
"Set includeUncommitted to false to set a custom top"
}
field = value
}

companion object {
const val name = "affectedModuleDetector"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class AffectedModuleDetectorImpl constructor(
}

private val changedProjects by lazy {
findChangedProjects()
findChangedProjects(config.top, config.includeUncommitted)
}

private val dependentProjects by lazy {
Expand Down Expand Up @@ -401,9 +401,13 @@ class AffectedModuleDetectorImpl constructor(
*
* Also populates the unknownFiles var which is used in findAffectedProjects
*/
private fun findChangedProjects(): Set<Project> {
private fun findChangedProjects(
top: Sha,
includeUncommitted: Boolean = true
): Set<Project> {
git.findChangedFiles(
includeUncommitted = true
top = top,
includeUncommitted = includeUncommitted
).forEach { fileName ->
if (affectsAllModules(fileName)) {
return allProjects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ internal class GitClientImpl(
return commandRunner.executeAndParse(if (includeUncommitted) {
"$CHANGED_FILES_CMD_PREFIX $sha"
} else {
"$CHANGED_FILES_CMD_PREFIX $top $sha"
"$CHANGED_FILES_CMD_PREFIX $top..$sha"
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,47 @@ class AffectedModuleConfigurationTest {
assertThat(config.compareFrom).isEqualTo("PreviousCommit")
}
}

@Test
fun `GIVEN AffectedModuleConfiguration WHEN top THEN is HEAD`() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding tests!

val actual = config.top

assertThat(actual).isEqualTo("HEAD")
}

@Test
fun `GIVEN AffectedModuleConfiguration WHEN includeUncommitted is true top is set to sha THEN exception thrown and value not set`() {
val includeUncommitted = true
val sha = "12345"

try {
config.includeUncommitted = includeUncommitted
config.top = sha
} catch (e: IllegalArgumentException) {
// THEN
assertThat(e.message).isEqualTo("Set includeUncommitted to false to set a custom top")
return
}

fail("Expected to catch an exception")
}

@Test
fun `GIVEN AffectedModuleConfiguration WHEN includeUncommitted is false and top is set to sha THEN top is sha`() {
val includeUncommitted = false
val sha = "12345"

config.includeUncommitted = includeUncommitted
config.top = sha

val actual = config.top
assertThat(actual).isEqualTo(sha)
}

@Test
fun `GIVEN AffectedModuleConfiguration WHEN includeUncommitted THEN is true`() {
val actual = config.includeUncommitted

assertThat(actual).isTrue()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class GitClientImplTest {
convertToFilePath("a", "b", "c.java"),
convertToFilePath("d", "e", "f.java"))
commandRunner.addReply(
"$CHANGED_FILES_CMD_PREFIX otherSha mySha",
"$CHANGED_FILES_CMD_PREFIX otherSha..mySha",
changes.joinToString(System.lineSeparator())
)
commitShaProvider.addReply("mySha")
Expand Down