-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore reckon properties in composite builds
Composite builds that include multiple builds that use reckon can run into unexpected behavior, because any reckon.* props passed in on the command line are used by all builds. This can cause it to try to increment a version incorrectly. The new behavior makes it so that only the main build within a composite will actually respect the gradle properties. This does imply that you can't really release a version of an included build, but the expectation is that that's not what anyone would intend to do. That could be proven wrong, but it would require something more involved to support. This fixes #74.
- Loading branch information
1 parent
c332caf
commit d800e15
Showing
3 changed files
with
123 additions
and
18 deletions.
There are no files selected for viewing
17 changes: 1 addition & 16 deletions
17
reckon-gradle/src/compatTest/groovy/org/ajoberstar/reckon/gradle/BaseCompatTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
...gradle/src/compatTest/groovy/org/ajoberstar/reckon/gradle/CompositeBuildCompatTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package org.ajoberstar.reckon.gradle | ||
|
||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
import org.ajoberstar.grgit.Grgit | ||
import org.gradle.testkit.runner.GradleRunner | ||
import org.gradle.testkit.runner.BuildResult | ||
import org.gradle.testkit.runner.TaskOutcome | ||
import org.junit.Rule | ||
import org.junit.rules.TemporaryFolder | ||
|
||
// Composite builds were added in 3.1 | ||
@IgnoreIf({ System.properties['compat.gradle.version'] == '3.0' }) | ||
class CompositeBuildCompatTest extends Specification { | ||
@Rule TemporaryFolder tempDir = new TemporaryFolder() | ||
File project1Dir | ||
File project2Dir | ||
File build1File | ||
File build2File | ||
|
||
def setup() { | ||
project1Dir = tempDir.newFolder('project1') | ||
project2Dir = tempDir.newFolder('project2') | ||
build1File = projectFile(project1Dir, 'build.gradle') | ||
build2File = projectFile(project2Dir, 'build.gradle') | ||
|
||
def grgit1 = Grgit.init(dir: project1Dir) | ||
projectFile(project1Dir, 'file.txt') << 'stuff' | ||
projectFile(project1Dir, '.gitignore') << '.gradle\nbuild\n' | ||
build1File << '''\ | ||
plugins { | ||
id 'org.ajoberstar.grgit' | ||
id 'org.ajoberstar.reckon' | ||
} | ||
reckon { | ||
normal = scopeFromProp() | ||
preRelease = stageFromProp('beta', 'final') | ||
} | ||
task printVersion { | ||
doLast { | ||
println "${project.name} version is ${project.version}" | ||
} | ||
} | ||
''' | ||
grgit1.add(patterns: ['.']) | ||
grgit1.commit(message: 'first commit') | ||
grgit1.tag.add(name: '1.3.0', message: 'stuff') | ||
grgit1.close() | ||
|
||
def grgit2 = Grgit.init(dir: project2Dir) | ||
projectFile(project2Dir, 'file.txt') << 'stuff' | ||
projectFile(project2Dir, '.gitignore') << '.gradle\nbuild\n' | ||
build2File << '''\ | ||
plugins { | ||
id 'org.ajoberstar.grgit' | ||
id 'org.ajoberstar.reckon' | ||
} | ||
reckon { | ||
normal = scopeFromProp() | ||
preRelease = stageFromProp('beta', 'final') | ||
} | ||
task printVersion { | ||
doLast { | ||
println "${project.name} version is ${project.version}" | ||
} | ||
} | ||
''' | ||
grgit2.add(patterns: ['.']) | ||
grgit2.commit(message: 'first commit') | ||
grgit2.tag.add(name: '1.0.0-beta.1', message: 'stuff') | ||
grgit2.close() | ||
} | ||
|
||
def 'if build included in composite build, reckon properties are ignored'() { | ||
when: | ||
def result = build(project2Dir, 'printVersion', '--include-build', project1Dir.absolutePath, '-Preckon.scope=major', '-Preckon.stage=beta') | ||
then: | ||
result.output.contains('Reckoned version: 1.3.0') | ||
result.output.contains('Reckoned version: 1.0.0-beta.2') | ||
} | ||
|
||
private BuildResult build(File projectDir, String... args = []) { | ||
return GradleRunner.create() | ||
.withGradleVersion(System.properties['compat.gradle.version']) | ||
.withPluginClasspath() | ||
.withProjectDir(projectDir) | ||
.forwardOutput() | ||
.withArguments((args + '--stacktrace') as String[]) | ||
.build() | ||
} | ||
|
||
private BuildResult buildAndFail(File projectDir, String... args = []) { | ||
return GradleRunner.create() | ||
.withGradleVersion(System.properties['compat.gradle.version']) | ||
.withPluginClasspath() | ||
.withProjectDir(projectDir) | ||
.forwardOutput() | ||
.withArguments((args + '--stacktrace') as String[]) | ||
.buildAndFail() | ||
} | ||
|
||
private File projectFile(File projectDir, String path) { | ||
File file = new File(projectDir, path) | ||
file.parentFile.mkdirs() | ||
return file | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters