Skip to content

Commit fa5b4e8

Browse files
committed
/TagStrategy: fail the build with meaningful error message when 'v' is used as a tag
1 parent bdea694 commit fa5b4e8

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/integTest/groovy/nebula/plugin/release/ReleasePluginIntegrationSpec.groovy

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,18 @@ class ReleasePluginIntegrationSpec extends GitVersioningIntegrationSpec {
682682
!new File(projectDir, "build/libs/${moduleName}-3.1.2-rc.1.jar").exists()
683683
}
684684

685+
def 'using v as tag fails when running tasks'() {
686+
git.tag.add(name: "v3.1.2")
687+
git.tag.add(name: "v")
688+
689+
when:
690+
def result = runTasksWithFailure('final', '-Prelease.useLastTag=true')
691+
692+
then:
693+
result.standardError.contains "Tag name 'v' is invalid. 'v' should be use as prefix for semver versions only, example: v1.0.0"
694+
!new File(projectDir, "build/libs/${moduleName}-3.1.2.jar").exists()
695+
}
696+
685697
def 'useLastTag uses release tag when running "final"'() {
686698
git.tag.add(name: "v3.1.2-rc.1")
687699
git.tag.add(name: "v3.1.2")

src/main/groovy/nebula/plugin/release/git/base/TagStrategy.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import com.github.zafarkhaja.semver.Version
2020
import groovy.transform.CompileDynamic
2121
import org.ajoberstar.grgit.Grgit
2222
import org.ajoberstar.grgit.Tag
23+
import org.gradle.api.GradleException
2324
import org.slf4j.Logger
2425
import org.slf4j.LoggerFactory
2526

@@ -40,6 +41,9 @@ class TagStrategy {
4041
*/
4142
Closure<Version> parseTag = { Tag tag ->
4243
try {
44+
if(tag.name == 'v') {
45+
throw new GradleException("Tag name '${tag.name}' is invalid. 'v' should be use as prefix for semver versions only, example: v1.0.0")
46+
}
4347
Version.valueOf(tag.name[0] == 'v' ? tag.name[1..-1] : tag.name)
4448
} catch (ParseException e) {
4549
null

0 commit comments

Comments
 (0)