2022-10-07 16:03:38 +02:00
|
|
|
import io.gitlab.jfronny.scripts.*
|
2022-10-06 19:30:52 +02:00
|
|
|
import org.eclipse.jgit.api.Git
|
|
|
|
import java.awt.Toolkit
|
|
|
|
import java.awt.datatransfer.StringSelection
|
|
|
|
|
2022-11-04 19:14:40 +01:00
|
|
|
val isRelease = project.hasProperty("release")
|
|
|
|
|
2022-10-06 19:30:52 +02:00
|
|
|
versionS = "0.0.0+nogit"
|
|
|
|
versionType = VersionType.ALPHA
|
|
|
|
if (File(projectDir, ".git").exists()) {
|
|
|
|
Git.open(projectDir).use { git ->
|
|
|
|
versionS = "0.0.0+notag"
|
|
|
|
val tags: List<Tag> = git.getTags()
|
|
|
|
if (tags.isNotEmpty()) {
|
|
|
|
if (tags[0].fullMessage != null) changelog += "${tags[0].fullMessage}\n"
|
|
|
|
versionS = tags[0].name
|
|
|
|
val vt = when(versionS[0]) {
|
|
|
|
'v' -> VersionType.RELEASE
|
|
|
|
'b' -> VersionType.BETA
|
|
|
|
'a' -> VersionType.ALPHA
|
|
|
|
else -> null
|
|
|
|
}
|
|
|
|
versionType = vt ?: VersionType.RELEASE
|
|
|
|
if (vt != null) versionS = versionS.substring(1)
|
2022-11-04 19:14:40 +01:00
|
|
|
if (isRelease) {
|
|
|
|
changelog += "Commits in ${versionType.displayName} $versionS:\n"
|
|
|
|
changelog += git.log(if (tags.size >= 2) tags[1].id else null, tags[0].id)
|
|
|
|
.reversed()
|
|
|
|
.joinToString("\n") { "- ${it.shortMessage}" }
|
|
|
|
} else {
|
|
|
|
changelog += "Commits after ${versionType.displayName} $versionS:\n"
|
|
|
|
changelog += git.log(tags[0].id)
|
|
|
|
.reversed()
|
|
|
|
.joinToString("\n") { "- ${it.shortMessage}" }
|
|
|
|
}
|
2022-10-06 19:30:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-06 22:43:11 +02:00
|
|
|
if (changelog == "") changelog = "No changelog"
|
2022-10-06 19:30:52 +02:00
|
|
|
|
2022-11-04 19:14:40 +01:00
|
|
|
if (!isRelease) {
|
2022-11-03 14:59:34 +01:00
|
|
|
versionS += "-SNAPSHOT"
|
2022-10-13 19:27:02 +02:00
|
|
|
}
|
2022-10-06 19:30:52 +02:00
|
|
|
|
|
|
|
println(changelog)
|
|
|
|
|
|
|
|
tasks.register("copyVersionNumber") {
|
|
|
|
doLast {
|
|
|
|
Toolkit.getDefaultToolkit().systemClipboard.setContents(StringSelection(versionS), null)
|
|
|
|
println("Copied version number: $versionS")
|
|
|
|
}
|
|
|
|
}
|