Skip to content

Commit

Permalink
Upload releases using platform plugins (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
turikhay authored Jan 20, 2024
1 parent dad3296 commit 145776f
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 36 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/hangar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Hangar release

on: workflow_dispatch

jobs:
version:
name: Detect version
uses: ./.github/workflows/version.yml
upload:
name: Build and upload
needs: version
uses: ./.github/workflows/build.yml
with:
version: ${{ needs.version.outputs.version }}
env:
HANGAR_UPLOAD: true
HANGAR_TOKEN: ${{ secrets.HANGAR_TOKEN }}
38 changes: 5 additions & 33 deletions .github/workflows/modrinth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,12 @@ jobs:
version:
name: Detect version
uses: ./.github/workflows/version.yml
build:
name: Build
upload:
name: Build and upload
needs: version
uses: ./.github/workflows/build.yml
with:
version: ${{ needs.version.outputs.version }}
upload:
name: Upload
needs:
- version
- build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: gradle-build
- name: Read VERSIONS.txt
id: supported_versions
uses: juliangruber/read-file-action@v1
with:
path: ./VERSIONS.txt
- uses: Kir-Antipov/[email protected]
with:
name: ${{ needs.version.outputs.version }}
version: ${{ needs.version.outputs.version }}
files: ${{ needs.build.outputs.artifact }}
version-type: ${{ needs.version.outputs.release-type }}
changelog: |
Changelog is available on
[GitHub](https://github.com/turikhay/MapModCompanion/releases/tag/v${{ needs.version.outputs.version }})
game-versions: ${{ steps.supported_versions.outputs.content }}
loaders: bukkit spigot paper bungeecord waterfall velocity
modrinth-id: UO7aDcrF
modrinth-featured: ${{ needs.version.outputs.pre-release != true }}
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
env:
MODRINTH_UPLOAD: true
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Companion for map mods

<!-- platform.start -->
<p>
<a href="https://github.com/turikhay/MapModCompanion/blob/main/LICENSE.txt">
<img src="https://img.shields.io/github/license/turikhay/MapModCompanion">
Expand Down Expand Up @@ -31,6 +32,7 @@
src="https://raw.githubusercontent.com/turikhay/MapModCompanion-design/main/allaylogo3_1000_10.png"
alt="Allay from Minecraft holding a compass and waving with their other hand at the viewer"
/>
<!-- platform.end -->

**With this plugin your minimap will never be confused which world you're in.**

Expand Down Expand Up @@ -78,7 +80,7 @@ Folia is supported, but isn't tested regularly. Please report if the support is

ℹ️ You should install this plugin on both sides: on BungeeCord/Velocity and on Spigot/Paper.

1. Download the latest release from [Releases](https://github.com/turikhay/MapModCompanion/releases) page
1. Download the latest release
2. Put each file into the corresponding plugins folder
3. That's it. No configuration is required. You can restart your servers now.

Expand All @@ -92,10 +94,12 @@ Velocity uses `plugins/mapmodcompanion/config.toml`.

The configuration file reloads automatically if it's modified.

<!-- platform.start -->
## Alternatives
- If you're running Forge or Fabric server, just install the map mod on your server: this will unlock all its
features.
- [worldnamepacket](https://github.com/kosma/worldnamepacket) (Velocity, Fabric, Spigot)
- [journeymap-bukkit](https://github.com/TeamJM/journeymap-bukkit) (Spigot)
- [JourneyMap Server](https://www.curseforge.com/minecraft/mc-mods/journeymap-server) (Spigot)
- [Minimap server](https://github.com/Ewpratten/MinimapServer) (Spigot)
<!-- platform.end -->
3 changes: 3 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ dependencies {
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$version")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:$version")
}
implementation(libs.semver.get().toString())
implementation("com.modrinth.minotaur:Minotaur:2.+")
implementation(with(libs.plugins.hangar.get()) { "io.papermc:hangar-publish-plugin:$version" })
}
59 changes: 59 additions & 0 deletions buildSrc/src/main/kotlin/PlatformReadme.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import org.gradle.api.DefaultTask
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.*

abstract class PlatformReadmeTask : DefaultTask() {
companion object {
val PLATFORM_START = "<!-- platform.start -->"
val PLATFORM_END = "<!-- platform.end -->"
}

@get:InputFile
@get:Optional
abstract val inputFile: RegularFileProperty

@get:OutputFile
@get:Optional
abstract val outputFile: RegularFileProperty

init {
inputFile.convention(project.objects.fileProperty().fileValue(
project.rootProject.file("README.md"))
)
outputFile.convention(project.objects.fileProperty().value(
project.layout.buildDirectory.file("README-platform.md"))
)
}

@TaskAction
fun writeFile() {
inputFile.get().asFile.reader().use { reader ->
outputFile.get().asFile.writer().use { writer ->
reader.useLines { lines ->
var blockAtLineIndex = -1
for (indexed in lines.withIndex()) {
val lineIndex = indexed.index
val line = indexed.value
if (line == PLATFORM_START) {
blockAtLineIndex = lineIndex
continue
}
if (line == PLATFORM_END) {
blockAtLineIndex = -1
continue
}
if (blockAtLineIndex > 0) {
continue
}
writer.write(line)
writer.write("\n")
}
if (blockAtLineIndex > 0) {
throw IllegalArgumentException("platform.start block was never closed " +
"(see line ${blockAtLineIndex + 1})")
}
}
}
}
}
}
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ junit = "5.10.1"
bstats = "3.0.2"
velocity-api = "3.1.1"
jackson = "2.16.1"
semver = "1.1.2"
hangar = "0.1.1"

[libraries]
spotbugs-annotations = { module = "com.github.spotbugs:spotbugs-annotations", version.ref = "spotbugs" }
Expand All @@ -15,7 +17,9 @@ bstats-bukkit = { module = "org.bstats:bstats-bukkit", version.ref = "bstats" }
bstats-velocity = { module = "org.bstats:bstats-velocity", version.ref = "bstats" }
velocity-api = { module = "com.velocitypowered:velocity-api", version.ref = "velocity-api" }
jackson-core = { module = "com.fasterxml.jackson.core:jackson-core", version.ref = "jackson" }
semver = { module = "net.swiftzer.semver:semver", version.ref = "semver" }


[plugins]
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }
hangar = { id = "io.papermc.hangar-publish-plugin", version.ref = "hangar" }
126 changes: 124 additions & 2 deletions packages/single/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import net.swiftzer.semver.SemVer

plugins {
id("java-shadow")
id("com.modrinth.minotaur")
id("io.papermc.hangar-publish-plugin")
}

dependencies {
Expand All @@ -8,6 +12,124 @@ dependencies {
implementation(project(":velocity"))
}

tasks.shadowJar {
archiveFileName = "MapModCompanion.jar"
val semVer = SemVer.parse(project.version as String)
val isRelease = semVer.preRelease == null
val updatePages = isRelease || System.getenv("UPDATE_PAGES") == "true"
val commonChangelog = """
Changelog is available on
[GitHub](https://github.com/turikhay/MapModCompanion/releases/tag/v${project.version})
""".trimIndent()
val allVersions: List<String> by lazy { rootProject.file("VERSIONS.txt").readLines() }
val readmeTask by tasks.registering(PlatformReadmeTask::class)

modrinth {
token = System.getenv("MODRINTH_TOKEN")
projectId = "UO7aDcrF"
versionNumber = project.version as String
changelog = commonChangelog
versionType = run {
val preRelease = semVer.preRelease
if (preRelease != null) {
if (preRelease.contains("beta")) {
"beta"
} else {
"alpha"
}
} else {
"release"
}
}
if (updatePages) {
syncBodyFrom = readmeTask.map { it.outputs.files.singleFile.readText() }
}
uploadFile = tasks.getByPath("shadowJar")
gameVersions = allVersions
loaders.addAll(listOf(
"bukkit",
"bungeecord",
"folia",
"paper",
"spigot",
"velocity",
"waterfall",
))
}

hangarPublish {
publications.register("plugin") {
version = project.version as String
id = "MapModCompanion"
channel = run {
val preRelease = semVer.preRelease
if (preRelease != null) {
"Beta"
} else {
"Release"
}
}
changelog = commonChangelog
apiKey = System.getenv("HANGAR_TOKEN")
platforms {
val singleJar = tasks.shadowJar.map { it.outputs.files.singleFile }
val families = allVersions.map {
val split = it.split(".") // -> 1, 20[, 4]
assert(split.size > 1)
assert(split.first() == "1") // will Minecraft 2.0 ever come out?
Integer.parseInt(split[1]) // "1.20.4" -> 20
}.sorted()
paper {
jar = singleJar
platformVersions = listOf("1.${families.first()}-1.${families.last()}") // 1.8 - latest
dependencies {
hangar("ProtocolLib") {
required = false
}
}
}
waterfall {
val wfFamilies = families.filter { it >= 11 } // Waterfall is only available >= 1.11
jar = singleJar
platformVersions = listOf("1.${wfFamilies.first()}-1.${wfFamilies.last()}")
}
velocity {
val velocityFamily = libs.versions.velocity.api.map {
val split = it.split(".")
"${split[0]}.${split[1]}"
}.get()
jar = singleJar
platformVersions = listOf(velocityFamily)
}
}
pages {
if (updatePages) {
resourcePage(readmeTask.map { it.outputs.files.singleFile.readText() })
}
}
}
}

tasks {
shadowJar {
archiveFileName = "MapModCompanion.jar"
}
getByName("modrinth") {
dependsOn(
shadowJar,
modrinthSyncBody
)
}
getByName("publishPluginPublicationToHangar") {
dependsOn(
shadowJar,
getByName("syncAllPluginPublicationPagesToHangar")
)
}
assemble {
if (System.getenv("MODRINTH_UPLOAD") == "true") {
dependsOn("modrinth")
}
if (System.getenv("HANGAR_UPLOAD") == "true") {
dependsOn("publishPluginPublicationToHangar")
}
}
}

0 comments on commit 145776f

Please sign in to comment.