Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change release system #7

Merged
merged 5 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

27 changes: 27 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Publish
on:
push:
branches:
- master
- dev
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()
}
43 changes: 43 additions & 0 deletions build-logic/src/main/kotlin/extensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.named
import java.io.ByteArrayOutputStream

fun Project.publishShadowJar() {
configurePublication {
artifact(tasks["shadowJar"])
artifact(tasks["sourcesJar"])
}
}

private fun Project.configurePublication(configurer: MavenPublication.() -> Unit) {
extensions.configure<PublishingExtension> {
publications.named<MavenPublication>("mavenJava") {
apply(configurer)
}
}
}

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()
}
Empty file.
126 changes: 58 additions & 68 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
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("olf.build-logic")
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 +27,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 +119,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 All @@ -194,22 +135,24 @@ java {
}

tasks {
named<Jar>("jar") {
archiveClassifier.set("unshaded")
}
compileJava {
options.release.set(17)
options.encoding = "UTF-8"
}
shadowJar {
archiveClassifier.set(null as String?)
archiveClassifier.set("")
dependencies {
relocate("com.cryptomorin.xseries", "$group.xseries")
relocate("org.incendo.serverlib", "$group.serverlib")
relocate("org.bstats", "$group.metrics")
relocate("io.papermc.lib", "$group.paperlib")
}
minimize()
}

build {
named("build") {
dependsOn(shadowJar)
}

Expand All @@ -223,3 +166,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.flatMap { it.archiveFile })
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")
Loading