Skip to content

Commit 15f5be7

Browse files
committed
Use the GitHub changelog on Modrinth and Hangar
1 parent 38657a4 commit 15f5be7

3 files changed

Lines changed: 31 additions & 25 deletions

File tree

.github/workflows/release.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ jobs:
3434
files: build/libs/*.jar
3535
continue-on-error: false
3636

37+
- name: Get GitHub Changelog
38+
run: |
39+
changelog=$(gh api repos/${{ github.repository }}/releases/tags/${{ github.ref_name }} --jq '.body')
40+
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
41+
echo "GITHUB_CHANGELOG<<$EOF" >> "$GITHUB_ENV"
42+
echo "$changelog" >> "$GITHUB_ENV"
43+
echo "$EOF" >> "$GITHUB_ENV"
44+
env:
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
continue-on-error: true
47+
3748
- name: Publish Hangar Release
3849
run: ./gradlew publishPluginPublicationToHangar
3950
env:

build.gradle.kts

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import io.papermc.hangarpublishplugin.model.Platforms
22
import org.apache.tools.ant.filters.ReplaceTokens
3-
import java.io.ByteArrayOutputStream
43

54
plugins {
65
id("maven-publish")
@@ -87,7 +86,7 @@ tasks {
8786
id = property("hangar.project") as String?
8887
version = project.version as String
8988
channel = "Release"
90-
changelog = generateChangelog()
89+
changelog = parseGitHubChangelog()
9190

9291
platforms {
9392
register(Platforms.PAPER) {
@@ -104,7 +103,7 @@ tasks {
104103
uploadFile = shadowJar.get()
105104
gameVersions = mapVersions("modrinth.versions")
106105
loaders = arrayListOf("bukkit", "spigot", "paper", "folia", "purpur")
107-
changelog = generateChangelog()
106+
changelog = parseGitHubChangelog()
108107

109108
syncBodyFrom = file("README.md").readText()
110109
modrinth.get().dependsOn(modrinthSyncBody)
@@ -115,25 +114,22 @@ fun mapVersions(propertyName: String): Provider<List<String>> = provider {
115114
return@provider (property(propertyName) as String).split(",").map { it.trim() }
116115
}
117116

118-
fun generateChangelog(): Provider<String> = provider {
119-
val tags = providers.exec {
120-
commandLine("git", "tag", "--sort", "version:refname")
121-
}.standardOutput.asText.get().trim().split("\n")
122-
123-
val tagsRange = if (tags.size > 1) {
124-
"${tags[tags.size - 2]}...${tags[tags.size - 1]}"
125-
} else if (tags.isNotEmpty()) tags[0] else "HEAD~1...HEAD"
126-
127-
val repoUrl = property("github.url") as String?
128-
val changelog = ByteArrayOutputStream().apply {
129-
write("### Commits:\n".toByteArray())
130-
131-
write(providers.exec {
132-
commandLine("git", "log", tagsRange, "--pretty=format:- [%h]($repoUrl/commit/%H) %s", "--reverse")
133-
}.standardOutput.asBytes.get())
134-
135-
write("\n\nCompare Changes: [$tagsRange]($repoUrl/compare/$tagsRange)".toByteArray())
136-
}.toString(Charsets.UTF_8.name())
137-
138-
return@provider changelog
117+
fun parseGitHubChangelog(): Provider<String> = provider {
118+
val changelog = System.getenv("GITHUB_CHANGELOG")
119+
?: return@provider "(No changelog provided)"
120+
121+
val userRegex = Regex("(?<!\\w)@([A-Za-z0-9-]+)")
122+
val pullRegex = Regex("https://github\\.com/[\\w-]+/[\\w-]+/pull/(\\d+)")
123+
val compareRegex = Regex("https://github\\.com/[\\w-]+/[\\w-]+/compare/([\\w\\.]+)")
124+
125+
changelog.replace(userRegex) {
126+
val user = it.groupValues[1]
127+
"[@$user](https://github.com/$user)"
128+
}.replace(pullRegex) {
129+
val pr = it.groupValues[1]
130+
"[#$pr](${it.value})"
131+
}.replace(compareRegex) {
132+
val range = it.groupValues[1]
133+
"[$range](${it.value})"
134+
}
139135
}

gradle.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
github.user=RuiPereiraDev
22
github.repo=SimpleScore
3-
github.url=https://github.com/RuiPereiraDev/SimpleScore
43

54
bStats.bukkit=644
65

0 commit comments

Comments
 (0)