Skip to content

Commit

Permalink
Add support for publishing to Modrinth
Browse files Browse the repository at this point in the history
  • Loading branch information
r4g3baby committed Oct 29, 2023
1 parent 187b82d commit 3d6e927
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 25 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,22 @@ jobs:
run: |
git fetch --unshallow --tags
tag=$(git tag --sort version:refname | tail -n 2 | head -n 1)
changelog=$(git log $tag..HEAD --pretty=format:'- %h %s%n' --reverse)
changelog=$(git log $tag...HEAD --pretty=format:'- %h %s' --reverse)
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "CHANGELOG<<$EOF" >> $GITHUB_OUTPUT
echo "$changelog" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
- name: Create Draft Release
- name: Publish GitHub Release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body: |
${{ steps.generate_changelog.outputs.CHANGELOG }}
files: build/libs/*.jar
draft: true

- name: Publish Modrinth Release
env:
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
run: ./gradlew modrinth
63 changes: 41 additions & 22 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import org.apache.tools.ant.filters.ReplaceTokens
import java.io.ByteArrayOutputStream

plugins {
id("com.github.johnrengelman.shadow") version "8.1.1"
id("com.modrinth.minotaur") version "2.8.4"
kotlin("jvm") version "1.9.10"
id("maven-publish")
}

group = "com.r4g3baby"
Expand Down Expand Up @@ -52,7 +55,7 @@ tasks {
processResources {
filteringCharset = "UTF-8"
filesMatching("**plugin.yml") {
filter<org.apache.tools.ant.filters.ReplaceTokens>(
filter<ReplaceTokens>(
"tokens" to mapOf(
"name" to project.name,
"version" to project.version,
Expand Down Expand Up @@ -80,32 +83,48 @@ tasks {
from(file("LICENSE"))

dependencies {
exclude("META-INF/NOTICE")
exclude("META-INF/maven/**")
exclude("META-INF/versions/**")
exclude("META-INF/**.kotlin_module")
exclude("META-INF/**")
}

minimize()
}
}

publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/r4g3baby/SimpleScore")
credentials {
username = project.findProperty("github.actor") as String? ?: System.getenv("GITHUB_ACTOR")
password = project.findProperty("github.token") as String? ?: System.getenv("GITHUB_TOKEN")
}
}
}
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"
)
loaders = arrayListOf("bukkit", "spigot", "paper")
changelog = run {
val tags = ByteArrayOutputStream().apply {
exec {
commandLine("git", "tag", "--sort", "version:refname")
standardOutput = this@apply
}
}.toString().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"

publications {
register<MavenPublication>("gpr") {
artifactId = project.name.lowercase()
from(components["kotlin"])
val repoUrl = findProperty("github.repo") as String? ?: System.getenv("GITHUB_REPO_URL")
val changelog = ByteArrayOutputStream().apply {
write("### Commits:\n".toByteArray())

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

write("\n\nCompare Changes: [$tagsRange]($repoUrl/compare/$tagsRange)".toByteArray())
}.toString()

return@run changelog
}

syncBodyFrom = file("README.md").readText()
modrinth.get().dependsOn(modrinthSyncBody)
}
}
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
github.repo=https://github.com/r4g3baby/SimpleScore

# modrinth.token=
modrinth.project=qG43Afem

kotlin.code.style=official

0 comments on commit 3d6e927

Please sign in to comment.