diff --git a/src/integTest/groovy/nebula/plugin/release/Issue187IntegrationSpec.groovy b/src/integTest/groovy/nebula/plugin/release/Issue187IntegrationSpec.groovy new file mode 100644 index 0000000..564bb2e --- /dev/null +++ b/src/integTest/groovy/nebula/plugin/release/Issue187IntegrationSpec.groovy @@ -0,0 +1,132 @@ +/* + * Copyright 2020 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nebula.plugin.release + +import org.gradle.api.plugins.JavaPlugin +import spock.lang.Issue +import spock.lang.Unroll + +@Issue("Inconsistent versioning for SNAPSHOT stage https://github.com/nebula-plugins/nebula-release-plugin/issues/187") +class Issue187IntegrationSpec extends GitVersioningIntegrationSpec { + @Override + def setupBuild() { + fork = false + buildFile << """ + ext.dryRun = true + group = 'test' + ${applyPlugin(ReleasePlugin)} + ${applyPlugin(JavaPlugin)} + """.stripIndent() + + git.add(patterns: ['build.gradle', '.gitignore'] as Set) + git.tag.add(name: 'v0.2.2') + } + + def 'should infer same version for SNAPSHOT when using build and snapshot task without scope'() { + buildFile << """ +release { + defaultVersionStrategy = nebula.plugin.release.git.opinion.Strategies.SNAPSHOT +} +""" + + when: + def resultBuild = runTasksSuccessfully('build') + + then: + resultBuild.standardOutput.contains('version: 0.3.0-SNAPSHOT') + + when: + def resultSnapshot = runTasksSuccessfully('snapshot') + + then: + resultSnapshot.standardOutput.contains('version: 0.3.0-SNAPSHOT') + } + + @Unroll + def 'should infer same version for SNAPSHOT when using build and snapshot task with scope #scope'() { + buildFile << """ +release { + defaultVersionStrategy = nebula.plugin.release.git.opinion.Strategies.SNAPSHOT +} +""" + + when: + def resultBuild = runTasksSuccessfully('build', "-Prelease.scope=${scope}") + + then: + resultBuild.standardOutput.contains("version: ${expectedVersion}") + + when: + def resultSnapshot = runTasksSuccessfully('snapshot', "-Prelease.scope=${scope}") + + then: + resultSnapshot.standardOutput.contains("version: ${expectedVersion}") + + where: + scope | expectedVersion + 'major' | '1.0.0-SNAPSHOT' + 'minor' | '0.3.0-SNAPSHOT' + 'patch' | '0.2.3-SNAPSHOT' + } + + @Unroll + def 'infer #expectedVersion for #task task when not using snapshot strategy'() { + when: + def resultBuild = runTasksSuccessfully('build') + + then: + resultBuild.standardOutput.contains('version: 0.3.0-dev') + + when: + def resultSnapshot = runTasksSuccessfully(task) + + then: + resultSnapshot.standardOutput.contains("version: $expectedVersion") + + where: + task | expectedVersion + 'devSnapshot' | '0.3.0-dev' + 'candidate' | '0.3.0-rc.1' + 'final' | '0.3.0' + } + + @Unroll + def 'infer #expectedVersion for #task task when not using snapshot strategy with scope #scope'() { + when: + def resultBuild = runTasksSuccessfully('build', "-Prelease.scope=${scope}") + + then: + resultBuild.standardOutput.contains("version: $expectedBuildVersion") + + when: + def resultSnapshot = runTasksSuccessfully(task, "-Prelease.scope=${scope}") + + then: + resultSnapshot.standardOutput.contains("version: $expectedReleaseVersion") + + where: + task | scope | expectedReleaseVersion | expectedBuildVersion + 'devSnapshot' | 'patch' | '0.2.3-dev' | '0.2.3-dev' + 'devSnapshot' | 'minor' | '0.3.0-dev' | '0.3.0-dev' + 'devSnapshot' | 'major' | '1.0.0-dev' | '1.0.0-dev' + 'candidate' | 'patch' | '0.2.3-rc.1' | '0.2.3-dev' + 'candidate' | 'minor' | '0.3.0-rc.1' | '0.3.0-dev' + 'candidate' | 'major' | '1.0.0-rc.1' | '1.0.0-dev' + 'final' | 'patch' | '0.2.3' | '0.2.3-dev' + 'final' | 'minor' | '0.3.0' | '0.3.0-dev' + 'final' | 'major' | '1.0.0' | '1.0.0-dev' + } +} diff --git a/src/main/groovy/nebula/plugin/release/git/opinion/Strategies.groovy b/src/main/groovy/nebula/plugin/release/git/opinion/Strategies.groovy index 51c76c5..d7c16d5 100644 --- a/src/main/groovy/nebula/plugin/release/git/opinion/Strategies.groovy +++ b/src/main/groovy/nebula/plugin/release/git/opinion/Strategies.groovy @@ -175,7 +175,7 @@ final class Strategies { * Always use the scope provided to increment the normal component. */ static PartialSemVerStrategy useScope(ChangeScope scope) { - return closure { state -> incrementNormalFromScope(state, scope) } + return closure { state -> incrementNormalFromScope(state, scope)} } } @@ -307,6 +307,7 @@ final class Strategies { static final SemVerStrategy SNAPSHOT = DEFAULT.copyWith( name: 'snapshot', stages: ['SNAPSHOT'] as SortedSet, + normalStrategy: one(Normal.USE_SCOPE_PROP, Normal.USE_NEAREST_ANY, Normal.useScope(ChangeScope.MINOR)), allowDirtyRepo: true, preReleaseStrategy: PreRelease.STAGE_FIXED, createTag: false, diff --git a/src/test/groovy/nebula/plugin/release/git/opinion/StrategiesSpec.groovy b/src/test/groovy/nebula/plugin/release/git/opinion/StrategiesSpec.groovy index 82c8754..9ba1180 100644 --- a/src/test/groovy/nebula/plugin/release/git/opinion/StrategiesSpec.groovy +++ b/src/test/groovy/nebula/plugin/release/git/opinion/StrategiesSpec.groovy @@ -343,8 +343,8 @@ class StrategiesSpec extends Specification { Strategies.SNAPSHOT.doInfer(project, grgit, locator) == new ReleaseVersion(expected, nearestNormal, false) where: scope | stage | nearestNormal | nearestAny | repoDirty | expected - null | null | '1.0.0' | '1.0.0' | false | '1.0.1-SNAPSHOT' - null | null | '1.0.0' | '1.0.0' | true | '1.0.1-SNAPSHOT' + null | null | '1.0.0' | '1.0.0' | false | '1.1.0-SNAPSHOT' + null | null | '1.0.0' | '1.0.0' | true | '1.1.0-SNAPSHOT' null | 'SNAPSHOT' | '1.0.0' | '1.1.0-beta' | true | '1.1.0-SNAPSHOT' null | 'SNAPSHOT' | '1.0.0' | '1.1.0-zed' | true | '1.1.0-SNAPSHOT' 'PATCH' | 'SNAPSHOT' | '1.0.0' | '1.1.0-zed' | true | '1.0.1-SNAPSHOT'