From 145776f787fd151ff05f256df91754af2e0adf4c Mon Sep 17 00:00:00 2001 From: Artur Khusainov Date: Sat, 20 Jan 2024 23:08:49 +0300 Subject: [PATCH] Upload releases using platform plugins (#81) --- .github/workflows/hangar.yml | 17 +++ .github/workflows/modrinth.yml | 38 +------ README.md | 6 +- buildSrc/build.gradle.kts | 3 + buildSrc/src/main/kotlin/PlatformReadme.kt | 59 ++++++++++ gradle/libs.versions.toml | 4 + packages/single/build.gradle.kts | 126 ++++++++++++++++++++- 7 files changed, 217 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/hangar.yml create mode 100644 buildSrc/src/main/kotlin/PlatformReadme.kt diff --git a/.github/workflows/hangar.yml b/.github/workflows/hangar.yml new file mode 100644 index 0000000..46b68e1 --- /dev/null +++ b/.github/workflows/hangar.yml @@ -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 }} diff --git a/.github/workflows/modrinth.yml b/.github/workflows/modrinth.yml index 2f950e2..7f95fbb 100644 --- a/.github/workflows/modrinth.yml +++ b/.github/workflows/modrinth.yml @@ -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/mc-publish@v3.3 - 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 }} diff --git a/README.md b/README.md index 21440fe..1ef8eed 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Companion for map mods +

@@ -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" /> + **With this plugin your minimap will never be confused which world you're in.** @@ -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. @@ -92,6 +94,7 @@ Velocity uses `plugins/mapmodcompanion/config.toml`. The configuration file reloads automatically if it's modified. + ## Alternatives - If you're running Forge or Fabric server, just install the map mod on your server: this will unlock all its features. @@ -99,3 +102,4 @@ The configuration file reloads automatically if it's modified. - [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) + \ No newline at end of file diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 9769335..6385986 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -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" }) } diff --git a/buildSrc/src/main/kotlin/PlatformReadme.kt b/buildSrc/src/main/kotlin/PlatformReadme.kt new file mode 100644 index 0000000..0df96b3 --- /dev/null +++ b/buildSrc/src/main/kotlin/PlatformReadme.kt @@ -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 = "" + val 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})") + } + } + } + } + } +} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e9c7567..98945f4 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" } @@ -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" } diff --git a/packages/single/build.gradle.kts b/packages/single/build.gradle.kts index 237e961..aae2d35 100644 --- a/packages/single/build.gradle.kts +++ b/packages/single/build.gradle.kts @@ -1,5 +1,9 @@ +import net.swiftzer.semver.SemVer + plugins { id("java-shadow") + id("com.modrinth.minotaur") + id("io.papermc.hangar-publish-plugin") } dependencies { @@ -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 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") + } + } +} \ No newline at end of file