Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TagStrategy: fail the build with meaningful error message when 'v' is used as a tag #239

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 == 'v') {
throw new GradleException("Tag name 'v' 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