Skip to content

Commit

Permalink
/TagStrategy: fail the build with meaningful error message when 'v' i…
Browse files Browse the repository at this point in the history
…s used as a tag
  • Loading branch information
rpalcolea committed Jul 18, 2023
1 parent bdea694 commit 0a83762
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,18 @@ class ReleasePluginIntegrationSpec extends GitVersioningIntegrationSpec {
!new File(projectDir, "build/libs/${moduleName}-3.1.2-rc.1.jar").exists()
}

def 'using v as tag fails when running tasks'() {
git.tag.add(name: "v3.1.2")
git.tag.add(name: "v")

when:
def result = runTasksWithFailure('final', '-Prelease.useLastTag=true')

then:
result.standardError.contains "Tag name 'v' is invalid. 'v' should be use as prefix for semver versions only, example: v1.0.0"
!new File(projectDir, "build/libs/${moduleName}-3.1.2.jar").exists()
}

def 'useLastTag uses release tag when running "final"'() {
git.tag.add(name: "v3.1.2-rc.1")
git.tag.add(name: "v3.1.2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.github.zafarkhaja.semver.Version
import groovy.transform.CompileDynamic
import org.ajoberstar.grgit.Grgit
import org.ajoberstar.grgit.Tag
import org.gradle.api.GradleException
import org.slf4j.Logger
import org.slf4j.LoggerFactory

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

0 comments on commit 0a83762

Please sign in to comment.