From 70725d4aaf0a6b6ff9e01d6942421c99f0b00ed7 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Fri, 11 Aug 2023 00:26:51 +1000 Subject: [PATCH] Add Hangar publishing --- .github/workflows/publish.yml | 26 +++++++++ build-logic/src/main/kotlin/extensions.kt | 18 ++++++ build.gradle.kts | 2 +- gradle.properties | 5 ++ universal/build.gradle.kts | 69 +++++++++++++++++++++++ 5 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/publish.yml create mode 100644 gradle.properties diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..e96bb1bd --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,26 @@ +name: Publish to Hangar and Modrinth +on: + push: + branches: + - master + - dev + +jobs: + publish: + if: github.repository_owner == 'ViaVersion' + runs-on: ubuntu-22.04 + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + - name: Validate Gradle Wrapper + uses: gradle/wrapper-validation-action@v1 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: 17 + - name: Publish + env: + HANGAR_TOKEN: ${{ secrets.HANGAR_TOKEN }} + MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} + run: ./gradlew publishAllPublicationsToHangar # add 'modrinth' after it is approved diff --git a/build-logic/src/main/kotlin/extensions.kt b/build-logic/src/main/kotlin/extensions.kt index c55b057b..7fb95ba0 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) { sourceCompatibility = JavaVersion.toVersion(version) targetCompatibility = JavaVersion.toVersion(version) diff --git a/build.gradle.kts b/build.gradle.kts index 583ad5e3..f84d0b0a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { allprojects { group = "com.viaversion" - version = "4.8.0-23w32a-SNAPSHOT" + version = property("projectVersion") as String // from gradle.properties description = "Allow older clients to join newer server versions." } diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 00000000..914ae341 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,5 @@ +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.10-1.20.1 +waterfallVersion=1.20 +velocityVersion=3.2 \ No newline at end of file diff --git a/universal/build.gradle.kts b/universal/build.gradle.kts index 9347643d..bb1c1b99 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,69 @@ tasks { } publishShadowJar() + +val branch = rootProject.branchName() +val isMainBranch = branch == "master" +val ver = (project.version as String) + "+" + System.getenv("GITHUB_RUN_NUMBER") +val changelogContent = rootProject.lastCommitMessage() +modrinth { + val mcVersions: List = (property("mcVersions") as String) + .split(",") + .map { it.trim() } + token.set(System.getenv("MODRINTH_TOKEN")) + projectId.set("viabackwards") + versionType.set(if (isMainBranch) "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") + } +} + +if (isMainBranch) { // Don't spam releases until Hangar has per channel notifications + hangarPublish { + publications.register("plugin") { + version.set(ver) + namespace("ViaVersion", "ViaBackwards") + channel.set(if (isMainBranch) "Snapshot" else "Alpha") + changelog.set(changelogContent) + apiKey.set(System.getenv("HANGAR_TOKEN")) + platforms { + register(Platforms.PAPER) { + jar.set(tasks.shadowJar.flatMap { it.archiveFile }) + platformVersions.set(listOf(property("mcVersionRange") as String)) + dependencies { + hangar("ViaVersion", "ViaVersion") { + required.set(true) + } + } + } + register(Platforms.VELOCITY) { + jar.set(tasks.shadowJar.flatMap { it.archiveFile }) + platformVersions.set(listOf(property("velocityVersion") as String)) + dependencies { + hangar("ViaVersion", "ViaVersion") { + required.set(true) + } + } + } + register(Platforms.WATERFALL) { + jar.set(tasks.shadowJar.flatMap { it.archiveFile }) + platformVersions.set(listOf(property("waterfallVersion") as String)) + dependencies { + hangar("ViaVersion", "ViaVersion") { + required.set(true) + } + } + } + } + } + } +}