Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysdh540 committed May 2, 2024
2 parents edc34d9 + 93d6325 commit ff510c7
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 14 deletions.
29 changes: 29 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env groovy

pipeline {
agent any

tools {
jdk "jdk-21"
}

stages {
stage("Setup") {
steps {
sh "chmod +x gradlew"
}
}

stage(":build") {
steps {
sh "./gradlew build -Pexternal_publish=true"
}
}

stage(":publish") {
steps {
sh "./gradlew publish -Pexternal_publish=true"
}
}
}
}
56 changes: 42 additions & 14 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,44 @@ enum class ReleaseChannel(
proguard = true),
}

val isRelease = rootProject.hasProperty("release_channel")
val releaseChannel = if (isRelease) ReleaseChannel.valueOf("release_channel"()) else ReleaseChannel.DEV_BUILD

println("Release Channel: $releaseChannel")

val headDateTime: ZonedDateTime = grgit.head().dateTime

val branchName = grgit.branch.current().name!!
val releaseTagPrefix = "release/"

val releaseTags = grgit.tag.list()
.filter { tag -> tag.name.startsWith(releaseTagPrefix) }
.sortedByDescending { tag -> tag.commit.dateTime }
.sortedWith { tag1, tag2 ->
if (tag1.commit.dateTime == tag2.commit.dateTime)
if (tag1.name.length != tag2.name.length)
return@sortedWith tag1.name.length.compareTo(tag2.name.length)
else
return@sortedWith tag1.name.compareTo(tag2.name)
else
return@sortedWith tag2.commit.dateTime.compareTo(tag1.commit.dateTime)
}
.dropWhile { tag -> tag.commit.dateTime > headDateTime }

val isExternalCI = (rootProject.properties["external_publish"] as String?).toBoolean()
val isRelease = rootProject.hasProperty("release_channel") || isExternalCI
val releaseIncrement = if (isRelease && !isExternalCI) 1 else 0
val releaseChannel: ReleaseChannel =
if (isExternalCI) {
val tagName = releaseTags.first().name
val suffix = """\-(\w+)\.\d+$""".toRegex().find(tagName)?.groupValues?.get(1)
if (suffix != null)
ReleaseChannel.values().find { channel -> channel.suffix == suffix }!!
else
ReleaseChannel.RELEASE
} else {
if (isRelease)
ReleaseChannel.valueOf("release_channel"())
else
ReleaseChannel.DEV_BUILD
}

println("Release Channel: $releaseChannel")

val minorVersion = "mod_version"()
val minorTagPrefix = "${releaseTagPrefix}${minorVersion}."

Expand All @@ -98,7 +121,7 @@ val maxPatch = patchHistory.maxOfOrNull { it.substringBefore('-').toInt() }
val patch =
maxPatch?.plus(
if (patchHistory.contains(maxPatch.toString()))
1
releaseIncrement
else
0
) ?: 0
Expand All @@ -114,7 +137,7 @@ if (releaseChannel.suffix != null) {
.mapNotNull { it.removePrefix(patchAndSuffix).toIntOrNull() }
.maxOrNull()

val build = (maxBuild?.plus(1)) ?: 1
val build = (maxBuild?.plus(releaseIncrement)) ?: 1
patchAndSuffix += build.toString()
}
}
Expand Down Expand Up @@ -371,10 +394,6 @@ tasks.shadowJar {
}
}

tasks.assemble {
dependsOn(tasks.shadowJar, sourcesJar)
}

val compressJar = tasks.register<CompressJarTask>("compressJar") {
dependsOn(tasks.shadowJar)
group = "build"
Expand All @@ -390,18 +409,27 @@ val compressJar = tasks.register<CompressJarTask>("compressJar") {
}
}

tasks.assemble {
dependsOn(compressJar, sourcesJar)
}

afterEvaluate {
publishing {
repositories {
if (!System.getenv("local_maven_url").isNullOrEmpty())
maven(System.getenv("local_maven_url"))
}

publications {
create<MavenPublication>("mod_id"()) {
artifact(tasks.shadowJar)
artifact(compressJar)
artifact(sourcesJar)
}
}
}

tasks.withType<AbstractPublishToMaven> {
dependsOn(tasks.shadowJar, sourcesJar)
dependsOn(compressJar, sourcesJar)
}

fun getChangelog(): String {
Expand Down

0 comments on commit ff510c7

Please sign in to comment.