try hangar release

This commit is contained in:
alexcrea 2026-01-12 00:04:52 +01:00
parent 62205085c7
commit 152e2c8d86
Signed by: alexcrea
GPG key ID: E346CD16413450E3
3 changed files with 89 additions and 4 deletions

View file

@ -67,7 +67,7 @@ jobs:
run: echo "SMALL_COMMIT_HASH=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_ENV run: echo "SMALL_COMMIT_HASH=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_ENV
- name: Build with Gradle Wrapper - name: Build with Gradle Wrapper
run: ./gradlew build --parallel run: ./gradlew build --parallel --stacktrace
# only submit dependency on push # only submit dependency on push
- name: Generate and submit dependency graph - name: Generate and submit dependency graph
@ -109,4 +109,12 @@ jobs:
with: with:
files: | files: |
build/libs/${{ env.ONLINE_JAR_NAME }} build/libs/${{ env.ONLINE_JAR_NAME }}
build/libs/${{ env.OFFLINE_JAR_NAME }} 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

View file

@ -2,7 +2,10 @@ import cn.lalaki.pub.BaseCentralPortalPlusExtension
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import groovy.util.Node import groovy.util.Node
import groovy.util.NodeList import groovy.util.NodeList
import io.papermc.hangarpublishplugin.model.HangarPublication
import io.papermc.hangarpublishplugin.model.Platforms
import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import java.io.ByteArrayOutputStream
plugins { plugins {
kotlin("jvm") version "2.1.0" kotlin("jvm") version "2.1.0"
@ -15,13 +18,16 @@ plugins {
id("cn.lalaki.central").version("1.2.8") id("cn.lalaki.central").version("1.2.8")
// Paper // Paper
id("io.papermc.paperweight.userdev") version "2.0.0-beta.17" apply false 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" group = "xyz.alexcrea"
version = "1.15.9" version = "1.15.9"
val isDevBuild = System.getenv("SMALL_COMMIT_HASH") != null
val isPreRelease = System.getenv("IS_PRERELEASE") == "true"
val effectiveVersion = "$version" + 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 { repositories {
// EcoEnchants // 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<ShadowJar>
jar.set(task.flatMap { it.archiveFile })
// Set platform versions from gradle.properties file
val versions: List<String> = (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")
}
}

View file

@ -6,4 +6,7 @@ signing.secretKeyRingFile=~/.gnupg/secring.gpg
kotlin.daemon.jvmargs=-Xmx8G kotlin.daemon.jvmargs=-Xmx8G
# list of nms # 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 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