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..7eeb5c92 --- /dev/null +++ b/.github/workflows/publish.yml @@ -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 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..0c696da7 --- /dev/null +++ b/build-logic/src/main/kotlin/extensions.kt @@ -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 { + publications.named("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 { + val byteOut = ByteArrayOutputStream() + exec { + commandLine = listOf("git") + args + standardOutput = byteOut + } + return byteOut.toString(Charsets.UTF_8.name()).trim() +} 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 90260bbe..2ad3d0ea 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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()) { @@ -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( @@ -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 { @@ -194,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) } @@ -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") + } +} + + + 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")