Skip to content

Commit

Permalink
Merge pull request #188 from nebula-plugins/issue-187/fix-inconsisten…
Browse files Browse the repository at this point in the history
…t-versioning-in-snapshot-stage

Fix inconsistency versioning in snapshot stage.
  • Loading branch information
rpalcolea committed May 20, 2020
2 parents 3720983 + ae67dc8 commit 9687109
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 3 deletions.
@@ -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'
}
}
Expand Up @@ -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)}
}
}

Expand Down Expand Up @@ -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,
Expand Down
Expand Up @@ -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'
Expand Down

0 comments on commit 9687109

Please sign in to comment.