Setup Hangar and modrinth autopublishing

This commit is contained in:
Nassim Jahnke 2023-08-10 21:29:03 +10:00
parent c358245c0b
commit 28787340d1
3 changed files with 65 additions and 0 deletions

View File

@ -38,6 +38,24 @@ fun Project.latestCommitHash(): String {
return byteOut.toString(Charsets.UTF_8.name()).trim()
}
fun Project.lastCommitMessage(): String {
val byteOut = ByteArrayOutputStream()
exec {
commandLine = listOf("git", "log", "-1", "--pretty=%B")
standardOutput = byteOut
}
return byteOut.toString(Charsets.UTF_8.name()).trim()
}
fun Project.branchName(): String {
val byteOut = ByteArrayOutputStream()
exec {
commandLine = listOf("git", "branch")
standardOutput = byteOut
}
return byteOut.toString(Charsets.UTF_8.name()).trim()
}
fun JavaPluginExtension.javaTarget(version: Int) {
toolchain.languageVersion.set(JavaLanguageVersion.of(version))
}

View File

@ -1,5 +1,7 @@
# Project properties - we put these here so they can be modified without causing a recompile of the build scripts
projectVersion=4.8.0-23w32a-SNAPSHOT
mcVersions=1.20.1, 1.19.4, 1.18.2, 1.17.1, 1.16.5, 1.15.2, 1.14.4, 1.8.9
mcVersionRange=1.8-1.20.1
# Gradle properties
org.gradle.daemon=true

View File

@ -1,7 +1,10 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import io.papermc.hangarpublishplugin.model.Platforms
plugins {
id("com.github.johnrengelman.shadow")
id("io.papermc.hangar-publish-plugin") version "0.0.5"
id("com.modrinth.minotaur") version "2.+"
}
val platforms = setOf(
@ -39,3 +42,45 @@ tasks {
}
publishShadowJar()
val env: MutableMap<String, String> = System.getenv()
val branch = rootProject.branchName()
val ver = (project.version as String) + "+" + env["GITHUB_RUN_NUMBER"]
val changelogContent = rootProject.lastCommitMessage()
modrinth {
val mcVersions: List<String> = (property("mcVersions") as String)
.split(",")
.map { it.trim() }
token.set(env["MODRINTH_TOKEN"])
projectId.set("viaversion")
versionType.set(if (branch == "master") "beta" else "alpha")
versionNumber.set(ver)
versionName.set("[$branch] $ver")
changelog.set(changelogContent)
uploadFile.set(tasks.shadowJar.flatMap { it.archiveFile })
gameVersions.set(mcVersions)
loaders.add("fabric")
autoAddDependsOn.set(false)
detectLoaders.set(false)
dependencies {
optional.project("viafabric")
optional.project("viafabricplus")
}
}
hangarPublish {
publications.register("plugin") {
apiEndpoint.set("https://hangar.papermc.dev/api/v1")
version.set(ver)
namespace("ViaVersion", "ViaVersion")
channel.set(if (branch == "master") "Snapshot" else "Alpha")
changelog.set(changelogContent)
apiKey.set(env["HANGAR_TOKEN"])
platforms {
register(Platforms.PAPER) {
jar.set(tasks.shadowJar.flatMap { it.archiveFile })
platformVersions.set(listOf(property("mcVersionRange") as String))
}
}
}
}