diff --git a/build-logic/src/main/kotlin/extensions.kt b/build-logic/src/main/kotlin/extensions.kt index c41665055..170e570cc 100644 --- a/build-logic/src/main/kotlin/extensions.kt +++ b/build-logic/src/main/kotlin/extensions.kt @@ -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)) } diff --git a/gradle.properties b/gradle.properties index 751d95bb7..bf0008601 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/universal/build.gradle.kts b/universal/build.gradle.kts index 2c8396b5a..a0fb11fb7 100644 --- a/universal/build.gradle.kts +++ b/universal/build.gradle.kts @@ -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 = System.getenv() +val branch = rootProject.branchName() +val ver = (project.version as String) + "+" + env["GITHUB_RUN_NUMBER"] +val changelogContent = rootProject.lastCommitMessage() +modrinth { + val mcVersions: List = (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)) + } + } + } +}