fancynpcs: update Jenkinsfile and build.gradle.kts

This commit is contained in:
Oliver
2025-03-29 16:58:24 +01:00
parent e32f4ee52a
commit e58002ce5a
2 changed files with 21 additions and 41 deletions

View File

@@ -14,14 +14,14 @@ pipeline {
stages { stages {
stage('Checkout') { stage('Checkout') {
steps { steps {
git url: 'https://github.com/FancyMcPlugins/FancyNpcs', branch: 'main' git url: 'https://github.com/FancyMcPlugins/fancyplugins', branch: 'main'
} }
} }
stage('Build') { stage('Build') {
steps { steps {
sh 'chmod +x gradlew' sh 'chmod +x gradlew'
sh './gradlew clean shadowJar' sh './gradlew clean :plugins:fancynpcs:shadowJar'
echo 'Built the plugin!' echo 'Built the plugin!'
} }
} }
@@ -33,10 +33,10 @@ pipeline {
string(credentialsId: 'MODRINTH_PUBLISH_API_TOKEN', variable: 'MODRINTH_PUBLISH_API_TOKEN'), string(credentialsId: 'MODRINTH_PUBLISH_API_TOKEN', variable: 'MODRINTH_PUBLISH_API_TOKEN'),
string(credentialsId: 'HANGAR_PUBLISH_API_TOKEN', variable: 'HANGAR_PUBLISH_API_TOKEN') string(credentialsId: 'HANGAR_PUBLISH_API_TOKEN', variable: 'HANGAR_PUBLISH_API_TOKEN')
]) { ]) {
sh 'export MODRINTH_PUBLISH_API_TOKEN=${MODRINTH_PUBLISH_API_TOKEN} && ./gradlew modrinth' sh 'export MODRINTH_PUBLISH_API_TOKEN=${MODRINTH_PUBLISH_API_TOKEN} && ./gradlew :plugins:fancynpcs:modrinth'
echo 'Published to Modrinth!' echo 'Published to Modrinth!'
sh 'export HANGAR_PUBLISH_API_TOKEN=${HANGAR_PUBLISH_API_TOKEN} && ./gradlew publishAllPublicationsToHangar' sh 'export HANGAR_PUBLISH_API_TOKEN=${HANGAR_PUBLISH_API_TOKEN} && ./gradlew :plugins:fancynpcs:publishAllPublicationsToHangar'
echo 'Published to Hangar!' echo 'Published to Hangar!'
} }
} }

View File

@@ -1,6 +1,4 @@
import net.minecrell.pluginyml.paper.PaperPluginDescription import net.minecrell.pluginyml.paper.PaperPluginDescription
import java.io.BufferedReader
import java.io.InputStreamReader
plugins { plugins {
id("java-library") id("java-library")
@@ -28,7 +26,8 @@ val supportedVersions =
"1.21.1", "1.21.1",
"1.21.2", "1.21.2",
"1.21.3", "1.21.3",
"1.21.4" "1.21.4",
"1.21.5"
) )
allprojects { allprojects {
@@ -103,11 +102,11 @@ paper {
tasks { tasks {
runServer { runServer {
minecraftVersion("1.21.5") minecraftVersion("1.21.4")
downloadPlugins { downloadPlugins {
hangar("ViaVersion", "5.2.1") hangar("ViaVersion", "5.3.0")
hangar("ViaBackwards", "5.2.1") hangar("ViaBackwards", "5.3.0")
hangar("PlaceholderAPI", "2.11.6") hangar("PlaceholderAPI", "2.11.6")
// modrinth("multiverse-core", "4.3.11") // modrinth("multiverse-core", "4.3.11")
} }
@@ -117,7 +116,7 @@ tasks {
relocate("org.incendo", "de.oliver") relocate("org.incendo", "de.oliver")
relocate("org.lushplugins.chatcolorhandler", "de.oliver.fancynpcs.libs.chatcolorhandler") relocate("org.lushplugins.chatcolorhandler", "de.oliver.fancynpcs.libs.chatcolorhandler")
archiveClassifier.set("") archiveClassifier.set("")
dependsOn(":api:shadowJar") dependsOn(":plugins:fancynpcs:api:shadowJar")
} }
publishing { publishing {
@@ -169,7 +168,7 @@ tasks {
val props = mapOf( val props = mapOf(
"description" to project.description, "description" to project.description,
"version" to project.version, "version" to project.version,
"hash" to getCurrentCommitHash(), "hash" to gitCommitHash.get(),
"build" to (System.getenv("BUILD_ID") ?: "").ifEmpty { "undefined" } "build" to (System.getenv("BUILD_ID") ?: "").ifEmpty { "undefined" }
) )
@@ -186,43 +185,24 @@ tasks {
} }
tasks.publishAllPublicationsToHangar { tasks.publishAllPublicationsToHangar {
dependsOn("shadowJar") dependsOn(":plugins:fancynpcs:shadowJar")
} }
tasks.modrinth { tasks.modrinth {
dependsOn("shadowJar") dependsOn(":plugins:fancynpcs:shadowJar")
} }
java { java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21)) toolchain.languageVersion.set(JavaLanguageVersion.of(21))
} }
fun getCurrentCommitHash(): String { val gitCommitHash: Provider<String> = providers.exec {
val process = ProcessBuilder("git", "rev-parse", "HEAD").start() commandLine("git", "rev-parse", "HEAD")
val reader = BufferedReader(InputStreamReader(process.inputStream)) }.standardOutput.asText.map { it.trim() }
val commitHash = reader.readLine()
reader.close()
process.waitFor()
if (process.exitValue() == 0) {
return commitHash ?: ""
} else {
throw IllegalStateException("Failed to retrieve the commit hash.")
}
}
fun getLastCommitMessage(): String { val gitCommitMessage: Provider<String> = providers.exec {
val process = ProcessBuilder("git", "log", "-1", "--pretty=%B").start() commandLine("git", "log", "-1", "--pretty=%B")
val reader = BufferedReader(InputStreamReader(process.inputStream)) }.standardOutput.asText.map { it.trim() }
val commitMessage = reader.readLine()
reader.close()
process.waitFor()
if (process.exitValue() == 0) {
println("Commit message: $commitMessage")
return commitMessage ?: ""
} else {
throw IllegalStateException("Failed to retrieve the commit message.")
}
}
hangarPublish { hangarPublish {
publications.register("plugin") { publications.register("plugin") {
@@ -239,7 +219,7 @@ hangarPublish {
} }
} }
changelog = getLastCommitMessage() changelog = gitCommitMessage.get()
} }
} }
@@ -252,5 +232,5 @@ modrinth {
gameVersions.addAll(supportedVersions) gameVersions.addAll(supportedVersions)
loaders.add("paper") loaders.add("paper")
loaders.add("folia") loaders.add("folia")
changelog.set(getLastCommitMessage()) changelog.set(gitCommitMessage.get())
} }