Skip to content

Commit

Permalink
Add Hangar publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytv committed Aug 10, 2023
1 parent 0d14765 commit 70725d4
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 1 deletion.
26 changes: 26 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Publish to Hangar and Modrinth
on:
push:
branches:
- master
- dev

jobs:
publish:
if: github.repository_owner == 'ViaVersion'
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
- name: Publish
env:
HANGAR_TOKEN: ${{ secrets.HANGAR_TOKEN }}
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
run: ./gradlew publishAllPublicationsToHangar # add 'modrinth' after it is approved
18 changes: 18 additions & 0 deletions build-logic/src/main/kotlin/extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ fun Project.latestCommitHash(): String {
return byteOut.toString(Charsets.UTF_8.name()).trim()
}

fun Project.lastCommitMessage(): String {
val byteOut = ByteArrayOutputStream()
exec {
commandLine = listOf("git", "log", "-1", "--pretty=%B")
standardOutput = byteOut
}
return byteOut.toString(Charsets.UTF_8.name()).trim()
}

fun Project.branchName(): String {
val byteOut = ByteArrayOutputStream()
exec {
commandLine = listOf("git", "branch")
standardOutput = byteOut
}
return byteOut.toString(Charsets.UTF_8.name()).trim()
}

fun JavaPluginExtension.javaTarget(version: Int) {
sourceCompatibility = JavaVersion.toVersion(version)
targetCompatibility = JavaVersion.toVersion(version)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {

allprojects {
group = "com.viaversion"
version = "4.8.0-23w32a-SNAPSHOT"
version = property("projectVersion") as String // from gradle.properties
description = "Allow older clients to join newer server versions."
}

Expand Down
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
projectVersion=4.8.0-23w32a-SNAPSHOT
mcVersions=1.20.1, 1.19.4, 1.18.2, 1.17.1, 1.16.5, 1.15.2, 1.14.4, 1.8.9
mcVersionRange=1.10-1.20.1
waterfallVersion=1.20
velocityVersion=3.2
69 changes: 69 additions & 0 deletions universal/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import io.papermc.hangarpublishplugin.model.Platforms

plugins {
id("com.github.johnrengelman.shadow")
id("io.papermc.hangar-publish-plugin") version "0.0.5"
id("com.modrinth.minotaur") version "2.+"
}

val platforms = setOf(
Expand Down Expand Up @@ -39,3 +42,69 @@ tasks {
}

publishShadowJar()

val branch = rootProject.branchName()
val isMainBranch = branch == "master"
val ver = (project.version as String) + "+" + System.getenv("GITHUB_RUN_NUMBER")
val changelogContent = rootProject.lastCommitMessage()
modrinth {
val mcVersions: List<String> = (property("mcVersions") as String)
.split(",")
.map { it.trim() }
token.set(System.getenv("MODRINTH_TOKEN"))
projectId.set("viabackwards")
versionType.set(if (isMainBranch) "beta" else "alpha")
versionNumber.set(ver)
versionName.set("[$branch] $ver")
changelog.set(changelogContent)
uploadFile.set(tasks.shadowJar.flatMap { it.archiveFile })
gameVersions.set(mcVersions)
loaders.add("fabric")
autoAddDependsOn.set(false)
detectLoaders.set(false)
dependencies {
optional.project("viafabric")
optional.project("viafabricplus")
}
}

if (isMainBranch) { // Don't spam releases until Hangar has per channel notifications
hangarPublish {
publications.register("plugin") {
version.set(ver)
namespace("ViaVersion", "ViaBackwards")
channel.set(if (isMainBranch) "Snapshot" else "Alpha")
changelog.set(changelogContent)
apiKey.set(System.getenv("HANGAR_TOKEN"))
platforms {
register(Platforms.PAPER) {
jar.set(tasks.shadowJar.flatMap { it.archiveFile })
platformVersions.set(listOf(property("mcVersionRange") as String))
dependencies {
hangar("ViaVersion", "ViaVersion") {
required.set(true)
}
}
}
register(Platforms.VELOCITY) {
jar.set(tasks.shadowJar.flatMap { it.archiveFile })
platformVersions.set(listOf(property("velocityVersion") as String))
dependencies {
hangar("ViaVersion", "ViaVersion") {
required.set(true)
}
}
}
register(Platforms.WATERFALL) {
jar.set(tasks.shadowJar.flatMap { it.archiveFile })
platformVersions.set(listOf(property("waterfallVersion") as String))
dependencies {
hangar("ViaVersion", "ViaVersion") {
required.set(true)
}
}
}
}
}
}
}

0 comments on commit 70725d4

Please sign in to comment.