Skip to content

Commit

Permalink
Add support for publishing to Hangar
Browse files Browse the repository at this point in the history
  • Loading branch information
r4g3baby committed Nov 16, 2023
1 parent cd0bbf6 commit a155b09
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ jobs:
${{ steps.generate_changelog.outputs.CHANGELOG }}
files: build/libs/*.jar

- name: Publish Hangar Release
env:
HANGAR_TOKEN: ${{ secrets.HANGAR_TOKEN }}
run: ./gradlew publishPluginPublicationToHangar

- name: Publish Modrinth Release
env:
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
Expand Down
75 changes: 49 additions & 26 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import io.papermc.hangarpublishplugin.model.Platforms
import org.apache.tools.ant.filters.ReplaceTokens
import java.io.ByteArrayOutputStream

plugins {
id("com.github.johnrengelman.shadow") version "8.1.1"
id("io.papermc.hangar-publish-plugin") version "0.1.0"
id("com.modrinth.minotaur") version "2.8.4"
kotlin("jvm") version "1.9.20"
}
Expand Down Expand Up @@ -89,42 +91,63 @@ tasks {
minimize()
}

hangarPublish {
publications.register("plugin") {
apiKey = findProperty("hangar.token") as String? ?: System.getenv("HANGAR_TOKEN")
id = findProperty("hangar.project") as String? ?: System.getenv("HANGAR_PROJECT")
version = project.version as String
channel = "Release"
changelog = generateChangelog()

platforms {
register(Platforms.PAPER) {
jar.set(shadowJar.flatMap { it.archiveFile })
platformVersions = mapVersions("hangar.versions")
}
}
}
}

modrinth {
token = findProperty("modrinth.token") as String? ?: System.getenv("MODRINTH_TOKEN")
projectId = findProperty("modrinth.project") as String? ?: System.getenv("MODRINTH_PROJECT")
uploadFile = shadowJar.get()
gameVersions = arrayListOf(
"1.8", "1.9", "1.10", "1.11", "1.12", "1.13", "1.14", "1.15", "1.16", "1.17", "1.18", "1.19", "1.20"
)
gameVersions = mapVersions("modrinth.versions")
loaders = arrayListOf("bukkit", "spigot", "paper")
changelog = provider {
val tags = ByteArrayOutputStream().apply {
exec {
commandLine("git", "tag", "--sort", "version:refname")
standardOutput = this@apply
}
}.toString().trim().split("\n")
changelog = generateChangelog()

val tagsRange = if (tags.size > 1) {
"${tags[tags.size - 2]}...${tags[tags.size - 1]}"
} else if (tags.isNotEmpty()) tags[0] else "HEAD~1...HEAD"
syncBodyFrom = file("README.md").readText()
modrinth.get().dependsOn(modrinthSyncBody)
}
}

val repoUrl = findProperty("github.repo") as String? ?: System.getenv("GITHUB_REPO_URL")
val changelog = ByteArrayOutputStream().apply {
write("### Commits:\n".toByteArray())
fun mapVersions(propertyName: String): Provider<List<String>> = provider {
return@provider (property(propertyName) as String).split(",").map { it.trim() }
}

exec {
commandLine("git", "log", tagsRange, "--pretty=format:- [%h]($repoUrl/commit/%H) %s", "--reverse")
standardOutput = this@apply
}
fun generateChangelog(): Provider<String> = provider {
val tags = ByteArrayOutputStream().apply {
exec {
commandLine("git", "tag", "--sort", "version:refname")
standardOutput = this@apply
}
}.toString(Charsets.UTF_8.name()).trim().split("\n")

val tagsRange = if (tags.size > 1) {
"${tags[tags.size - 2]}...${tags[tags.size - 1]}"
} else if (tags.isNotEmpty()) tags[0] else "HEAD~1...HEAD"

write("\n\nCompare Changes: [$tagsRange]($repoUrl/compare/$tagsRange)".toByteArray())
}.toString()
val repoUrl = findProperty("github.repo") as String? ?: System.getenv("GITHUB_REPO_URL")
val changelog = ByteArrayOutputStream().apply {
write("### Commits:\n".toByteArray())

return@provider changelog
exec {
commandLine("git", "log", tagsRange, "--pretty=format:- [%h]($repoUrl/commit/%H) %s", "--reverse")
standardOutput = this@apply
}

syncBodyFrom = file("README.md").readText()
modrinth.get().dependsOn(modrinthSyncBody)
}
write("\n\nCompare Changes: [$tagsRange]($repoUrl/compare/$tagsRange)".toByteArray())
}.toString(Charsets.UTF_8.name())

return@provider changelog
}
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
github.repo=https://github.com/r4g3baby/SimpleScore

# hangar.token=
hangar.project=SimpleScore
hangar.versions=1.8.x-1.20.2

# modrinth.token=
modrinth.project=qG43Afem
modrinth.versions=1.8,1.9,1.10,1.11,1.12,1.13,1.14,1.15,1.16,1.17,1.18,1.19,1.20

kotlin.code.style=official

0 comments on commit a155b09

Please sign in to comment.