From 77005c2b2944dbbac8128848e4488743a4a1f9a8 Mon Sep 17 00:00:00 2001 From: Phillipp Glanz <6745190+TheMeinerLP@users.noreply.github.com> Date: Sun, 12 May 2024 11:35:19 +0200 Subject: [PATCH 1/5] Change release system --- .github/FUNDING.yml | 1 + .github/workflows/build.yml | 67 ------------- .github/workflows/publish.yml | 33 ++++++ build-logic/build.gradle.kts | 7 ++ build-logic/src/main/kotlin/extensions.kt | 20 ++++ build.gradle.kts | 117 ++++++++++------------ gradle.properties | 2 +- settings.gradle.kts | 1 + 8 files changed, 115 insertions(+), 133 deletions(-) delete mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/publish.yml create mode 100644 build-logic/build.gradle.kts create mode 100644 build-logic/src/main/kotlin/extensions.kt diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 85f545a7..98485282 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,3 +1,4 @@ # These are supported funding model platforms patreon: TheMeinerLP # Replace with a single Patreon username +github: TheMeinerLP diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index cbd096fb..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,67 +0,0 @@ -name: Build -on: - push: - branches: - - master - 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: Clean Build - run: ./gradlew shadowJar --no-daemon - - name: Determine release status - if: ${{ runner.os == 'Linux' }} - run: | - if [ "$(./gradlew properties | awk '/^version:/ { print $2; }' | grep '\-SNAPSHOT')" ]; then - echo "STATUS=snapshot" >> $GITHUB_ENV - else - echo "STATUS=release" >> $GITHUB_ENV - fi - - name: Archive Artifacts - uses: actions/upload-artifact@v3 - with: - name: BetterGoPaint Archive - path: build/libs/BetterGoPaint-*.jar - - name: Publish to hangar - if: ${{ runner.os == 'Linux' && env.STATUS == 'release' && github.event_name == 'push' && github.ref == 'refs/heads/master'}} - run: ./gradlew publishAllPublicationsToHangar --no-daemon - env: - HANGAR_SECRET: ${{secrets.HANGAR_KEY}} - HANGAR_CHANNEL: "Release" - - name: Publish to hangar snapshot - if: ${{ runner.os == 'Linux' && env.STATUS != 'release' && github.event_name == 'push' && github.ref == 'refs/heads/master'}} - run: ./gradlew publishAllPublicationsToHangar --no-daemon - env: - HANGAR_SECRET: ${{secrets.HANGAR_KEY}} - HANGAR_CHANNEL: "Snapshot" - - name: Publish to Modrinth - if: ${{ runner.os == 'Linux' && env.STATUS == 'release' && github.event_name == 'push' && github.ref == 'refs/heads/master'}} - run: ./gradlew modrinth --no-daemon - env: - MODRINTH_TOKEN: ${{ secrets.MODRINTH_KEY }} - MODRINTH_CHANNEL: "release" - SHA_SHORT: ${{steps.vars.outputs.sha_short}} - - name: Publish to Modrinth Snapshot - if: ${{ runner.os == 'Linux' && env.STATUS != 'release' && github.event_name == 'push' && github.ref == 'refs/heads/master'}} - run: ./gradlew modrinth --no-daemon - env: - MODRINTH_TOKEN: ${{ secrets.MODRINTH_KEY }} - MODRINTH_CHANNEL: "beta" diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..3030870a --- /dev/null +++ b/.github/workflows/publish.yml @@ -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 diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts new file mode 100644 index 00000000..cc02e636 --- /dev/null +++ b/build-logic/build.gradle.kts @@ -0,0 +1,7 @@ +plugins { + `kotlin-dsl` +} + +repositories { + gradlePluginPortal() +} diff --git a/build-logic/src/main/kotlin/extensions.kt b/build-logic/src/main/kotlin/extensions.kt new file mode 100644 index 00000000..dbd9c3b4 --- /dev/null +++ b/build-logic/src/main/kotlin/extensions.kt @@ -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 { + val byteOut = ByteArrayOutputStream() + exec { + commandLine = listOf("git") + args + standardOutput = byteOut + } + return byteOut.toString(Charsets.UTF_8.name()).trim() +} diff --git a/build.gradle.kts b/build.gradle.kts index 90260bbe..68312a64 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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()) { @@ -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( @@ -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 { @@ -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") + } +} + + + diff --git a/gradle.properties b/gradle.properties index 89916015..764684ce 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/settings.gradle.kts b/settings.gradle.kts index 93f69704..1427e0e7 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1 +1,2 @@ rootProject.name = "BetterGoPaint" +includeBuild("build-logic") From ffa16d5f9cd49b2bac83d9593b46cc67e55b4838 Mon Sep 17 00:00:00 2001 From: Phillipp Glanz <6745190+TheMeinerLP@users.noreply.github.com> Date: Sun, 12 May 2024 11:39:11 +0200 Subject: [PATCH 2/5] Add missing imports --- build-logic/src/main/kotlin/extensions.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build-logic/src/main/kotlin/extensions.kt b/build-logic/src/main/kotlin/extensions.kt index dbd9c3b4..f21d5671 100644 --- a/build-logic/src/main/kotlin/extensions.kt +++ b/build-logic/src/main/kotlin/extensions.kt @@ -1,3 +1,6 @@ +import java.io.ByteArrayOutputStream +import org.gradle.api.Project + fun Project.latestCommitHash(): String { return runGitCommand(listOf("rev-parse", "--short", "HEAD")) } From 578a9d3bd10fb17552b1a991ff5905458e46010e Mon Sep 17 00:00:00 2001 From: Phillipp Glanz <6745190+TheMeinerLP@users.noreply.github.com> Date: Sun, 12 May 2024 11:44:48 +0200 Subject: [PATCH 3/5] Add build logic folder --- build-logic/src/main/kotlin/olf.build-logic.gradle.kts | 0 build.gradle.kts | 1 + 2 files changed, 1 insertion(+) create mode 100644 build-logic/src/main/kotlin/olf.build-logic.gradle.kts diff --git a/build-logic/src/main/kotlin/olf.build-logic.gradle.kts b/build-logic/src/main/kotlin/olf.build-logic.gradle.kts new file mode 100644 index 00000000..e69de29b diff --git a/build.gradle.kts b/build.gradle.kts index 68312a64..5a1f86f0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,6 +6,7 @@ import xyz.jpenilla.runpaper.task.RunServer 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("net.minecrell.plugin-yml.bukkit") version "0.5.3" From 5664a968088024db0c07cf492a49d8b8a215035d Mon Sep 17 00:00:00 2001 From: Phillipp Glanz <6745190+TheMeinerLP@users.noreply.github.com> Date: Sun, 12 May 2024 11:59:05 +0200 Subject: [PATCH 4/5] Improve build logic --- build-logic/src/main/kotlin/extensions.kt | 22 +++++++++++++++++++++- build.gradle.kts | 10 ++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/build-logic/src/main/kotlin/extensions.kt b/build-logic/src/main/kotlin/extensions.kt index f21d5671..0c696da7 100644 --- a/build-logic/src/main/kotlin/extensions.kt +++ b/build-logic/src/main/kotlin/extensions.kt @@ -1,5 +1,25 @@ -import java.io.ByteArrayOutputStream 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 { + publications.named("mavenJava") { + apply(configurer) + } + } +} fun Project.latestCommitHash(): String { return runGitCommand(listOf("rev-parse", "--short", "HEAD")) diff --git a/build.gradle.kts b/build.gradle.kts index 5a1f86f0..2ad3d0ea 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -135,22 +135,24 @@ java { } tasks { + named("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) } @@ -201,7 +203,7 @@ if (!isRelease || isMainBranch) { // Only publish releases from the main branch versionNumber.set(suffixedVersion) versionName.set(suffixedVersion) changelog.set(changelogContent) - uploadFile.set(tasks.shadowJar as Any) + uploadFile.set(tasks.shadowJar.flatMap { it.archiveFile }) gameVersions.addAll(supportedMinecraftVersions) loaders.add("paper") loaders.add("bukkit") From ab637940ac75f740b038547ca554991cb3bcb13b Mon Sep 17 00:00:00 2001 From: Phillipp Glanz <6745190+TheMeinerLP@users.noreply.github.com> Date: Sun, 12 May 2024 12:00:26 +0200 Subject: [PATCH 5/5] Fix pipeline --- .github/workflows/publish.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3030870a..7eeb5c92 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,15 +1,9 @@ -name: Build +name: Publish 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