use provider for hangar changelog

This commit is contained in:
alexcrea 2026-08-16 18:58:39 +02:00
parent db9188607b
commit 8e7153a746
Signed by: alexcrea
GPG key ID: E59DF23EE2A2266C

View file

@ -5,7 +5,6 @@ import groovy.util.NodeList
import io.papermc.hangarpublishplugin.model.HangarPublication import io.papermc.hangarpublishplugin.model.HangarPublication
import io.papermc.hangarpublishplugin.model.Platforms import io.papermc.hangarpublishplugin.model.Platforms
import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import java.io.ByteArrayOutputStream
plugins { plugins {
kotlin("jvm") version "2.4.0" kotlin("jvm") version "2.4.0"
@ -215,7 +214,7 @@ tasks {
exclude("net/kyori/**") exclude("net/kyori/**")
} }
val offlineJar = register<ShadowJar>("OfflineJar") { val offlineJar = register<ShadowJar>("offlineJar") {
configureBaseShadow("offline", emptyArray()) configureBaseShadow("offline", emptyArray())
from(sourceSets.main.get().output) from(sourceSets.main.get().output)
@ -358,35 +357,25 @@ publishing {
} }
// hangar publish // hangar publish
fun executeGitCommand(vararg command: String): String { fun latestCommitMessage(): Provider<String> {
val byteOut = ByteArrayOutputStream() return providers.exec {
providers.exec { commandLine("git", "log", "-1", "--pretty=%B")
commandLine = listOf("git", *command) }.standardOutput.asText.map(String::trim)
standardOutput = byteOut
}
return byteOut.toString(Charsets.UTF_8.name()).trim()
} }
fun changelog(isOnline: Boolean): Provider<String> {
fun latestCommitMessage(): String { val changelog = if(isDevBuild) latestCommitMessage()
return executeGitCommand("log", "-1", "--pretty=%B") else providers.environmentVariable("RELEASE_CHANGELOG")
}
fun changelog(isOnline: Boolean): String {
var changelog = if(isDevBuild) latestCommitMessage()
else System.getenv("RELEASE_CHANGELOG")
if(!isOnline) {
changelog = "This is an offline version of the plugin. \\\n" +
"This mean that this plugin libraries are shaded into this plugin \\\n" +
"You likely want to use the normal version of this plugin\n\n" + changelog
}
if(changelog == null || changelog.isEmpty()) {
changelog = "empty changelog"
}
return changelog return changelog
.filter{!it.isEmpty()}
.map {
if(!isOnline)
return@map "This is an offline version of the plugin. \\\n" +
"This mean that this plugin libraries are shaded into this plugin \\\n" +
"You likely want to use the normal version of this plugin\n\n" + it
else return@map it
}.orElse("empty changelog")
} }
hangarPublish { hangarPublish {
@ -400,6 +389,7 @@ hangarPublish {
channel.set(if (isDevBuild || isPreRelease) devChannel else releaseChannel) channel.set(if (isDevBuild || isPreRelease) devChannel else releaseChannel)
changelog.set(changelog(isOnline)) changelog.set(changelog(isOnline))
id.set("CustomAnvil") id.set("CustomAnvil")
apiKey.set(System.getenv("HANGAR_API_TOKEN")) apiKey.set(System.getenv("HANGAR_API_TOKEN"))