Skip to content

Commit

Permalink
Change release system
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMeinerLP committed May 12, 2024
1 parent 85fd9f3 commit 77005c2
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 133 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# These are supported funding model platforms

patreon: TheMeinerLP # Replace with a single Patreon username
github: TheMeinerLP
67 changes: 0 additions & 67 deletions .github/workflows/build.yml

This file was deleted.

33 changes: 33 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build
on:
push:
branches:
- master
- dev
pull_request:
types:
- opened
- reopened
- synchronize
- labeled
jobs:
build:
# Run on all label events (won't be duplicated) or all push events or on PR syncs not from the same repo
if: github.repository_owner == 'OneLiteFeatherNET'
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: temurin
cache: gradle
java-version: 17
- name: Publish
env:
HANGAR_SECRET: ${{secrets.HANGAR_KEY}}
MODRINTH_TOKEN: ${{ secrets.MODRINTH_KEY }}
run: ./gradlew build modrinth publishAllPublicationsToHangar --stacktrace
7 changes: 7 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
`kotlin-dsl`
}

repositories {
gradlePluginPortal()
}
20 changes: 20 additions & 0 deletions build-logic/src/main/kotlin/extensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
fun Project.latestCommitHash(): String {
return runGitCommand(listOf("rev-parse", "--short", "HEAD"))
}

fun Project.latestCommitMessage(): String {
return runGitCommand(listOf("log", "-1", "--pretty=%B"))
}

fun Project.branchName(): String {
return runGitCommand(listOf("rev-parse", "--abbrev-ref", "HEAD"))
}

fun Project.runGitCommand(args: List<String>): String {
val byteOut = ByteArrayOutputStream()
exec {
commandLine = listOf("git") + args
standardOutput = byteOut
}
return byteOut.toString(Charsets.UTF_8.name()).trim()
}
117 changes: 52 additions & 65 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import io.papermc.hangarpublishplugin.model.Platforms
import java.util.*
import net.minecrell.pluginyml.bukkit.BukkitPluginDescription
import org.ajoberstar.grgit.Grgit
import xyz.jpenilla.runpaper.task.RunServer
import java.util.*

plugins {
java
`java-library`
id("com.diffplug.spotless") version "6.18.0"
id("com.github.johnrengelman.shadow") version "8.1.1"
id("org.ajoberstar.grgit") version "5.2.0"
id("net.minecrell.plugin-yml.bukkit") version "0.5.3"
id("xyz.jpenilla.run-paper") version "2.1.0"
idea

id("io.papermc.hangar-publish-plugin") version "0.0.5"
id("com.modrinth.minotaur") version "2.+"
id("org.jetbrains.changelog") version "2.0.0"
}

if (!File("$rootDir/.git").exists()) {
Expand All @@ -29,20 +26,11 @@ if (!File("$rootDir/.git").exists()) {
""".trimIndent()
).also { System.exit(1) }
}
var baseVersion by extra("1.0.0")
var extension by extra("")
var snapshot by extra("-SNAPSHOT")

ext {
val git: Grgit = Grgit.open {
dir = File("$rootDir/.git")
}
val revision = git.head().abbreviatedId
extension = "%s+%s".format(Locale.ROOT, snapshot, revision)
allprojects {
group = "net.onelitefeather.bettergopaint"
version = property("projectVersion") as String // from gradle.properties
}

version = "%s%s".format(Locale.ROOT, baseVersion, extension)
group = "dev.themeinerlp.bettergopaint"
group = "net.onelitefeather.bettergopaint"

val minecraftVersion = "1.20.2"
val supportedMinecraftVersions = listOf(
Expand Down Expand Up @@ -130,54 +118,6 @@ bukkit {
}
}

changelog {
version.set(baseVersion)
path.set("${project.projectDir}/CHANGELOG.md")
itemPrefix.set("-")
keepUnreleasedSection.set(true)
unreleasedTerm.set("[Unreleased]")
groups.set(listOf("Added", "Changed", "Deprecated", "Removed", "Fixed", "Security"))
}

hangarPublish {
publications.register("BetterGoPaint") {
version.set(project.version.toString())
channel.set(System.getenv("HANGAR_CHANNEL"))
changelog.set(
project.changelog.renderItem(
project.changelog.getOrNull(baseVersion) ?: project.changelog.getUnreleased()
)
)
apiKey.set(System.getenv("HANGAR_SECRET"))
owner.set("TheMeinerLP")
slug.set("BetterGoPaint")

platforms {
register(Platforms.PAPER) {
jar.set(tasks.shadowJar.flatMap { it.archiveFile })
platformVersions.set(supportedMinecraftVersions)
}
}
}
}

modrinth {
token.set(System.getenv("MODRINTH_TOKEN"))
projectId.set("qf7sNg9A")
versionNumber.set(version.toString())
versionType.set(System.getenv("MODRINTH_CHANNEL"))
uploadFile.set(tasks.shadowJar as Any)
gameVersions.addAll(supportedMinecraftVersions)
loaders.add("paper")
loaders.add("bukkit")
loaders.add("folia")
changelog.set(
project.changelog.renderItem(
project.changelog.getOrNull(baseVersion) ?: project.changelog.getUnreleased()
)
)
}


spotless {
java {
Expand Down Expand Up @@ -223,3 +163,50 @@ tasks {
}
}
}

val branch = rootProject.branchName()
val baseVersion = project.version as String
val isRelease = !baseVersion.contains('-')
val isMainBranch = branch == "master"
if (!isRelease || isMainBranch) { // Only publish releases from the main branch
val suffixedVersion = if (isRelease) baseVersion else baseVersion + "+" + System.getenv("GITHUB_RUN_NUMBER")
val changelogContent = if (isRelease) {
"See [GitHub](https://github.com/OneLiteFeatherNET/BetterGoPaint) for release notes."
} else {
val commitHash = rootProject.latestCommitHash()
"[$commitHash](https://github.com/OneLiteFeatherNET/BetterGoPaint/commit/$commitHash) ${rootProject.latestCommitMessage()}"
}
hangarPublish {
publications.register("BetterGoPaint") {
version.set(project.version.toString())
channel.set(if (isRelease) "Release" else if (isMainBranch) "Snapshot" else "Alpha")
changelog.set(changelogContent)
apiKey.set(System.getenv("HANGAR_SECRET"))
owner.set("TheMeinerLP")
slug.set("BetterGoPaint")
platforms {
register(Platforms.PAPER) {
jar.set(tasks.shadowJar.flatMap { it.archiveFile })
platformVersions.set(supportedMinecraftVersions)
}
}
}
}

modrinth {
token.set(System.getenv("MODRINTH_TOKEN"))
projectId.set("qf7sNg9A")
versionType.set(if (isRelease) "release" else if (isMainBranch) "beta" else "alpha")
versionNumber.set(suffixedVersion)
versionName.set(suffixedVersion)
changelog.set(changelogContent)
uploadFile.set(tasks.shadowJar as Any)
gameVersions.addAll(supportedMinecraftVersions)
loaders.add("paper")
loaders.add("bukkit")
loaders.add("folia")
}
}



2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=3.1.0
projectVersion=1.0.0-SNAPSHOT

org.gradle.jvmargs=-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.daemon=true
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
rootProject.name = "BetterGoPaint"
includeBuild("build-logic")

0 comments on commit 77005c2

Please sign in to comment.