diff --git a/src/integTest/groovy/nebula/plugin/release/ReleasePluginIntegrationSpec.groovy b/src/integTest/groovy/nebula/plugin/release/ReleasePluginIntegrationSpec.groovy index 03092f0..2be1098 100644 --- a/src/integTest/groovy/nebula/plugin/release/ReleasePluginIntegrationSpec.groovy +++ b/src/integTest/groovy/nebula/plugin/release/ReleasePluginIntegrationSpec.groovy @@ -1183,6 +1183,63 @@ class ReleasePluginIntegrationSpec extends GitVersioningIntegrationSpec { result.standardError.contains('Nebula Release plugin does not support branches that end with dash (-)') } + @Unroll + def 'useLastTag errors out if version has invalid number of digits - #version'() { + git.tag.add(name: "v$version") + + when: + def result = runTasksWithFailure('final', '-Prelease.useLastTag=true') + + then: + result.standardError.contains "Current commit has following tags: [v${version}] but they were not recognized as valid versions" + !new File(projectDir, "build/libs/${moduleName}-${version}.jar").exists() + + where: + version << [ + '42.5.3.5', + '42.5.3.5.3', + '42.5.3.1-rc.1', + '42.5.3.1.4-rc.1', + ] + } + + @Unroll + def 'release with the override of version calculation errors out if version has invalid number of digits - #version'() { + when: + def result = runTasksWithFailure('final', "-Prelease.version=${version}") + + then: + result.standardError.contains "Supplied release.version ($version) is not valid per semver spec. For more information, please refer to https://semver.org/" + !new File(projectDir, "build/libs/${moduleName}-${version}.jar").exists() + !originGit.tag.list()*.name.contains("v${version}") + + where: + version << [ + '42.5.3.5', + '42.5.3.5.3', + '42.5.3.1-rc.1', + '42.5.3.1.4-rc.1', + ] + } + + @Unroll + def 'release with the override of version calculation does not errors out if version has invalid number of digits but verification is off - #version'() { + when: + def result = runTasksSuccessfully('final', "-Prelease.version=${version}", "-Prelease.ignoreSuppliedVersionVerification=true") + + then: + !result.standardError.contains("Supplied release.version ($version) is not valid per semver spec. For more information, please refer to https://semver.org/") + new File(projectDir, "build/libs/${moduleName}-${version}.jar").exists() + + where: + version << [ + '42.5.3.5', + '42.5.3.5.3', + '42.5.3.1-rc.1', + '42.5.3.1.4-rc.1', + ] + } + private void replaceDevWithImmutableSnapshot() { new File(buildFile.parentFile, "gradle.properties").text = """ nebula.release.features.replaceDevWithImmutableSnapshot=true diff --git a/src/main/groovy/nebula/plugin/release/OverrideStrategies.groovy b/src/main/groovy/nebula/plugin/release/OverrideStrategies.groovy index 305742f..b9f7891 100644 --- a/src/main/groovy/nebula/plugin/release/OverrideStrategies.groovy +++ b/src/main/groovy/nebula/plugin/release/OverrideStrategies.groovy @@ -15,6 +15,7 @@ */ package nebula.plugin.release +import com.github.zafarkhaja.semver.UnexpectedCharacterException import com.github.zafarkhaja.semver.Version import nebula.plugin.release.git.base.ReleasePluginExtension import nebula.plugin.release.git.base.ReleaseVersion @@ -119,6 +120,8 @@ class OverrideStrategies { static class GradlePropertyStrategy implements VersionStrategy { static final String PROPERTY_NAME = 'release.version' + static final String VERSION_VERIFICATION_PROPERTY_NAME = 'release.ignoreSuppliedVersionVerification' + Project project String propertyName @@ -148,9 +151,26 @@ class OverrideStrategies { requestedVersion = VersionSanitizerUtil.sanitize(requestedVersion.toString()) } + boolean isValidVersion = validateRequestedVersion(requestedVersion) + if(!isValidVersion) { + throw new GradleException("Supplied release.version ($requestedVersion) is not valid per semver spec. For more information, please refer to https://semver.org/") + } + new ReleaseVersion(requestedVersion, null, true) } + private boolean validateRequestedVersion(String version) { + if(project.hasProperty(VERSION_VERIFICATION_PROPERTY_NAME)) { + return true + } + + try { + Version.valueOf(version[0] == 'v' ? version[1..-1] : version) + return true + } catch(UnexpectedCharacterException e) { + return false + } + } } diff --git a/src/test/groovy/nebula/plugin/release/OverrideStrategiesSpec.groovy b/src/test/groovy/nebula/plugin/release/OverrideStrategiesSpec.groovy index 92d0243..a4cdf6b 100644 --- a/src/test/groovy/nebula/plugin/release/OverrideStrategiesSpec.groovy +++ b/src/test/groovy/nebula/plugin/release/OverrideStrategiesSpec.groovy @@ -37,7 +37,7 @@ class OverrideStrategiesSpec extends ProjectSpec { def 'able to set via gradle property and sanitize'() { setup: - project.ext.set('release.version', '42.5.0+feature') + project.ext.set('release.version', '42.5.0-rc.1+feature') project.ext.set('release.sanitizeVersion', true) when: @@ -48,6 +48,6 @@ class OverrideStrategiesSpec extends ProjectSpec { } then: - project.version.toString() == '42.5.0.feature' + project.version.toString() == '42.5.0-rc.1.feature' } } diff --git a/stale_outputs_checked b/stale_outputs_checked new file mode 100644 index 0000000..e69de29