Skip to content

Commit 4af3c2c

Browse files
committed
fix major/minor version bump bug
1 parent 9391f99 commit 4af3c2c

File tree

3 files changed

+193
-5
lines changed

3 files changed

+193
-5
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ gradlePlugin {
3232
id = "dev.poolside.gradle.semantic-version"
3333
group = "dev.poolside.gradle.semanticversion"
3434
implementationClass = "dev.poolside.gradle.semanticversion.SemanticVersionPlugin"
35-
version = "0.1.3"
35+
version = "0.1.4"
3636
displayName = "Poolside Semantic Version Plugin"
3737
}
3838
}

src/main/kotlin/dev/poolside/gradle/semanticversion/VersionFinder.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ object VersionFinder {
3232
logger.lifecycle("No published version of '${publication.groupId}:${publication.artifactId}:${publication.version}' resolved to '$newVersion'")
3333
newVersion
3434
} else {
35-
val newVersion = incrementVersion(latestVersion!!)
35+
val newVersion = compareAndIncrementVersion(versionParser.transform(publication.version), latestVersion!!)
3636
logger.lifecycle("Resolved published version of '${publication.groupId}:${publication.artifactId}:${publication.version}' to '$newVersion'")
3737
newVersion
3838
}
@@ -61,9 +61,17 @@ object VersionFinder {
6161
return result.versions
6262
}
6363

64-
private fun incrementVersion(version: Version): String {
65-
val parts = version.numericParts.filterNotNull()
64+
private fun compareAndIncrementVersion(original: Version, found: Version): String {
65+
// major version bump
66+
if (original.numericParts[0] > found.numericParts[0]) {
67+
return original.source + ".0"
68+
}
69+
// minor version bump
70+
if (original.numericParts[1] > found.numericParts[1]) {
71+
return original.source + ".0"
72+
}
73+
val parts = found.numericParts.filterNotNull()
6674
val last = parts.last() + 1
6775
return parts.dropLast(1).joinToString(".") + ".$last"
6876
}
69-
}
77+
}

src/test/kotlin/dev/poolside/gradle/semanticversion/SemanticVersionPluginTest.kt

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,186 @@ class SemanticVersionPluginTest {
9797
assertEquals("0.1.1", pom.version)
9898
}
9999

100+
@ParameterizedTest(name = "{index} gradle version {0}")
101+
@MethodSource("gradleVersions")
102+
fun `minor version bump`(gradleVersion: String) {
103+
var build = """
104+
plugins {
105+
java
106+
`maven-publish`
107+
id("dev.poolside.gradle.semantic-version")
108+
}
109+
repositories {
110+
maven { url = uri("${mavenRepo.absolutePath}") }
111+
}
112+
group = "dev.poolside.test"
113+
version = "0.1"
114+
publishing {
115+
repositories {
116+
maven { url = uri("${mavenRepo.absolutePath}") }
117+
}
118+
publications {
119+
create<MavenPublication>("mavenJava") {
120+
artifactId = "my-library"
121+
from(components["java"])
122+
}
123+
}
124+
}
125+
""".trimIndent()
126+
val settings = """rootProject.name = "testing""""
127+
File(testProjectDir, "build.gradle.kts").writeText(build)
128+
File(testProjectDir, "settings.gradle.kts").writeText(settings)
129+
GradleRunner.create()
130+
.withPluginClasspath()
131+
.withProjectDir(testProjectDir)
132+
.withGradleVersion(gradleVersion)
133+
.withArguments("publish")
134+
// .withDebug(true)
135+
.build()
136+
var version = "0.1.0"
137+
var pomFile = testProjectDir.walk().filter { it.name.startsWith("pom") }.first()
138+
var pom = PomParser.parse(pomFile.absolutePath)
139+
assertEquals(version, pom.version)
140+
var jarFile = mavenRepo.walk().filter { it.name.endsWith("my-library-$version.jar") }.first()
141+
assertTrue(jarFile.absolutePath.endsWith("/dev/poolside/test/my-library/$version/my-library-$version.jar"), jarFile.absolutePath)
142+
var publishedPom = mavenRepo.walk().filter { it.name.equals("my-library-$version.pom") }.first()
143+
pom = PomParser.parse(publishedPom.absolutePath)
144+
assertEquals(version, pom.version)
145+
146+
build = """
147+
plugins {
148+
java
149+
`maven-publish`
150+
id("dev.poolside.gradle.semantic-version")
151+
}
152+
repositories {
153+
maven { url = uri("${mavenRepo.absolutePath}") }
154+
}
155+
group = "dev.poolside.test"
156+
version = "0.2"
157+
publishing {
158+
repositories {
159+
maven { url = uri("${mavenRepo.absolutePath}") }
160+
}
161+
publications {
162+
create<MavenPublication>("mavenJava") {
163+
artifactId = "my-library"
164+
from(components["java"])
165+
}
166+
}
167+
}
168+
""".trimIndent()
169+
File(testProjectDir, "build.gradle.kts").writeText(build)
170+
171+
// should +0
172+
GradleRunner.create()
173+
.withPluginClasspath()
174+
.withProjectDir(testProjectDir)
175+
.withGradleVersion(gradleVersion)
176+
.withArguments("publish")
177+
// .withDebug(true)
178+
.build()
179+
version = "0.2.0"
180+
pomFile = testProjectDir.walk().filter { it.name.startsWith("pom") }.first()
181+
pom = PomParser.parse(pomFile.absolutePath)
182+
assertEquals(version, pom.version)
183+
jarFile = mavenRepo.walk().filter { it.name.endsWith("my-library-$version.jar") }.first()
184+
assertTrue(jarFile.absolutePath.endsWith("/dev/poolside/test/my-library/$version/my-library-$version.jar"), jarFile.absolutePath)
185+
publishedPom = mavenRepo.walk().filter { it.name.equals("my-library-$version.pom") }.first()
186+
pom = PomParser.parse(publishedPom.absolutePath)
187+
assertEquals(version, pom.version)
188+
}
189+
190+
@ParameterizedTest(name = "{index} gradle version {0}")
191+
@MethodSource("gradleVersions")
192+
fun `major version bump`(gradleVersion: String) {
193+
var build = """
194+
plugins {
195+
java
196+
`maven-publish`
197+
id("dev.poolside.gradle.semantic-version")
198+
}
199+
repositories {
200+
maven { url = uri("${mavenRepo.absolutePath}") }
201+
}
202+
group = "dev.poolside.test"
203+
version = "0.1"
204+
publishing {
205+
repositories {
206+
maven { url = uri("${mavenRepo.absolutePath}") }
207+
}
208+
publications {
209+
create<MavenPublication>("mavenJava") {
210+
artifactId = "my-library"
211+
from(components["java"])
212+
}
213+
}
214+
}
215+
""".trimIndent()
216+
val settings = """rootProject.name = "testing""""
217+
File(testProjectDir, "build.gradle.kts").writeText(build)
218+
File(testProjectDir, "settings.gradle.kts").writeText(settings)
219+
GradleRunner.create()
220+
.withPluginClasspath()
221+
.withProjectDir(testProjectDir)
222+
.withGradleVersion(gradleVersion)
223+
.withArguments("publish")
224+
// .withDebug(true)
225+
.build()
226+
var version = "0.1.0"
227+
var pomFile = testProjectDir.walk().filter { it.name.startsWith("pom") }.first()
228+
var pom = PomParser.parse(pomFile.absolutePath)
229+
assertEquals(version, pom.version)
230+
var jarFile = mavenRepo.walk().filter { it.name.endsWith("my-library-$version.jar") }.first()
231+
assertTrue(jarFile.absolutePath.endsWith("/dev/poolside/test/my-library/$version/my-library-$version.jar"), jarFile.absolutePath)
232+
var publishedPom = mavenRepo.walk().filter { it.name.equals("my-library-$version.pom") }.first()
233+
pom = PomParser.parse(publishedPom.absolutePath)
234+
assertEquals(version, pom.version)
235+
236+
build = """
237+
plugins {
238+
java
239+
`maven-publish`
240+
id("dev.poolside.gradle.semantic-version")
241+
}
242+
repositories {
243+
maven { url = uri("${mavenRepo.absolutePath}") }
244+
}
245+
group = "dev.poolside.test"
246+
version = "1.0"
247+
publishing {
248+
repositories {
249+
maven { url = uri("${mavenRepo.absolutePath}") }
250+
}
251+
publications {
252+
create<MavenPublication>("mavenJava") {
253+
artifactId = "my-library"
254+
from(components["java"])
255+
}
256+
}
257+
}
258+
""".trimIndent()
259+
File(testProjectDir, "build.gradle.kts").writeText(build)
260+
261+
// should +0
262+
GradleRunner.create()
263+
.withPluginClasspath()
264+
.withProjectDir(testProjectDir)
265+
.withGradleVersion(gradleVersion)
266+
.withArguments("publish")
267+
// .withDebug(true)
268+
.build()
269+
version = "1.0.0"
270+
pomFile = testProjectDir.walk().filter { it.name.startsWith("pom") }.first()
271+
pom = PomParser.parse(pomFile.absolutePath)
272+
assertEquals(version, pom.version)
273+
jarFile = mavenRepo.walk().filter { it.name.endsWith("my-library-$version.jar") }.first()
274+
assertTrue(jarFile.absolutePath.endsWith("/dev/poolside/test/my-library/$version/my-library-$version.jar"), jarFile.absolutePath)
275+
publishedPom = mavenRepo.walk().filter { it.name.equals("my-library-$version.pom") }.first()
276+
pom = PomParser.parse(publishedPom.absolutePath)
277+
assertEquals(version, pom.version)
278+
}
279+
100280
@ParameterizedTest(name = "{index} gradle version {0}")
101281
@MethodSource("gradleVersions")
102282
fun `modules version is set correctly`(gradleVersion: String) {

0 commit comments

Comments
 (0)