diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 1b003f8..91a13a7 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -67,7 +67,7 @@ jobs: run: echo "SMALL_COMMIT_HASH=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_ENV - name: Build with Gradle Wrapper - run: ./gradlew build --parallel + run: ./gradlew build --parallel --stacktrace # only submit dependency on push - name: Generate and submit dependency graph @@ -109,4 +109,12 @@ jobs: with: files: | build/libs/${{ env.ONLINE_JAR_NAME }} - build/libs/${{ env.OFFLINE_JAR_NAME }} \ No newline at end of file + build/libs/${{ env.OFFLINE_JAR_NAME }} + + - name: Hangar release + if: ${{ (github.event_name != 'release' || github.event_name != 'push') && github.repository_owner == 'alexcrea' && success() }} + env: + RELEASE_CHANGELOG: ${{ github.event.release.body }} + IS_GITHUB_PRERELEASE: ${{ github.event.release.prerelease }} + HANGAR_API_TOKEN: ${{ secrets.HANGAR_API_TOKEN }} + run: ./gradlew publishPluginPublicationToHangar --stacktrace \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index f005e45..378777e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,10 @@ import cn.lalaki.pub.BaseCentralPortalPlusExtension import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import groovy.util.Node import groovy.util.NodeList +import io.papermc.hangarpublishplugin.model.HangarPublication +import io.papermc.hangarpublishplugin.model.Platforms import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import java.io.ByteArrayOutputStream plugins { kotlin("jvm") version "2.1.0" @@ -15,13 +18,16 @@ plugins { id("cn.lalaki.central").version("1.2.8") // Paper id("io.papermc.paperweight.userdev") version "2.0.0-beta.17" apply false + id("io.papermc.hangar-publish-plugin") version "0.1.2" } group = "xyz.alexcrea" version = "1.15.9" +val isDevBuild = System.getenv("SMALL_COMMIT_HASH") != null +val isPreRelease = System.getenv("IS_PRERELEASE") == "true" val effectiveVersion = "$version" + - (if (System.getenv("SMALL_COMMIT_HASH") != null) "-dev-${System.getenv("SMALL_COMMIT_HASH")!!}" else "") + (if (isDevBuild) "-dev-${System.getenv("SMALL_COMMIT_HASH")!!}" else "") repositories { // EcoEnchants @@ -319,3 +325,71 @@ publishing { } } } + +// hangar publish + +fun executeGitCommand(vararg command: String): String { + val byteOut = ByteArrayOutputStream() + exec { + commandLine = listOf("git", *command) + standardOutput = byteOut + } + return byteOut.toString(Charsets.UTF_8.name()).trim() +} + + +fun latestCommitMessage(): String { + return executeGitCommand("log", "-1", "--pretty=%B") +} + +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 + } + + return changelog +} + +hangarPublish { + + fun HangarPublication.configure(isOnline: Boolean, devChannel: String, releaseChannel: String) { + version.set(effectiveVersion) + channel.set(if (isDevBuild || isPreRelease) devChannel else releaseChannel) + + changelog.set(changelog(isOnline)) + id.set("CustomAnvil") + apiKey.set(System.getenv("HANGAR_API_TOKEN")) + + platforms { + register(Platforms.PAPER) { + // Set the JAR file to upload + var task = if(isOnline) tasks.shadowJar + else tasks.getByName("offlineJar") as TaskProvider + + jar.set(task.flatMap { it.archiveFile }) + + // Set platform versions from gradle.properties file + val versions: List = (property("paperVersion") as String) + .split(",") + .map { it.trim() } + platformVersions.set(versions) + + //TODO dependencies + } + } + } + + publications.register("plugin") { + configure(true, "DevSnapshot", "Release") + } + + publications.register("offline") { + configure(false, "OfflineSnapshot", "OfflineRelease") + } + +} diff --git a/gradle.properties b/gradle.properties index 95311bf..19bd6be 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,7 @@ signing.secretKeyRingFile=~/.gnupg/secring.gpg kotlin.daemon.jvmargs=-Xmx8G # list of nms -subprojects.reobfnms=v1_17R1,v1_18R1,v1_18R2,v1_19R1,v1_19R2,v1_19R3,v1_20R1,v1_20R2,v1_20R3,v1_20R4,v1_21R1,v1_21R2,v1_21R3,v1_21R4,v1_21R5,v1_21R6,v1_21R7 \ No newline at end of file +subprojects.reobfnms=v1_17R1,v1_18R1,v1_18R2,v1_19R1,v1_19R2,v1_19R3,v1_20R1,v1_20R2,v1_20R3,v1_20R4,v1_21R1,v1_21R2,v1_21R3,v1_21R4,v1_21R5,v1_21R6,v1_21R7 + +# list of version for hangar release +paperVersion=1.18-1.21.11 \ No newline at end of file