diff --git a/src/main/groovy/com/cinnober/gradle/semver_git/SemverGitPlugin.groovy b/src/main/groovy/com/cinnober/gradle/semver_git/SemverGitPlugin.groovy index 3840098..e13d443 100644 --- a/src/main/groovy/com/cinnober/gradle/semver_git/SemverGitPlugin.groovy +++ b/src/main/groovy/com/cinnober/gradle/semver_git/SemverGitPlugin.groovy @@ -52,12 +52,11 @@ class SemverGitPlugin implements Plugin { } def static String checkVersion(String version) { - parseVersion(version); - return version; + return formatVersion(parseVersion(version)); } def static Object[] parseVersion(String version) { - def pattern = /^([0-9]+)\.([0-9]+)\.([0-9]+)(-([a-zA-Z0-9.-]+))?$/ + def pattern = /^(?:refs\/tags\/)?([0-9]+)\.([0-9]+)\.([0-9]+)(-([a-zA-Z0-9.-]+))?$/ def matcher = version =~ pattern def arr = matcher.collect { it }[0] if (arr == null) { @@ -124,4 +123,4 @@ class SemverGitPlugin implements Plugin { println "Version: " + project.version } } -} \ No newline at end of file +} diff --git a/src/test/groovy/com/cinnober/gradle/semver_git/SemverGitPluginTest.groovy b/src/test/groovy/com/cinnober/gradle/semver_git/SemverGitPluginTest.groovy index 9106a62..f819805 100644 --- a/src/test/groovy/com/cinnober/gradle/semver_git/SemverGitPluginTest.groovy +++ b/src/test/groovy/com/cinnober/gradle/semver_git/SemverGitPluginTest.groovy @@ -45,6 +45,21 @@ class SemverGitPluginTest extends GroovyTestCase { void testParseVersion12_34_56_rc78() { testParseVersion("12.34.56-rc78", [12,34,56,"rc78"]); } + void testParseVersionRefsTags100() { + testParseVersion("refs/tags/1.0.0", [1,0,0,null]); + } + void testParseVersionRefsTags123() { + testParseVersion("refs/tags/1.2.3", [1,2,3,null]); + } + void testParseVersionRefsTags123beta() { + testParseVersion("refs/tags/1.2.3-beta", [1,2,3,"beta"]); + } + void testParseVersionRefsTags123snapshot() { + testParseVersion("refs/tags/1.2.3-SNAPSHOT", [1,2,3,"SNAPSHOT"]); + } + void testParseVersionRefsTags12_34_56_rc78() { + testParseVersion("refs/tags/12.34.56-rc78", [12,34,56,"rc78"]); + } void testFailParseVersion_abc() { shouldFail({SemverGitPlugin.parseVersion("a.b.c")}); } @@ -105,4 +120,7 @@ class SemverGitPluginTest extends GroovyTestCase { testNextVersion("1.0.0-SNAPSHOT", "1.0.0-beta", "major", "SNAPSHOT"); } -} \ No newline at end of file + void testCheckVersionShouldReturnWithoutRefsTags() { + assertEquals("1.0.0-beta", SemverGitPlugin.checkVersion("refs/tags/1.0.0-beta")) + } +}