From 1b5eac2cd0bcb74576d39b20dc4c4bd26f3cfd46 Mon Sep 17 00:00:00 2001 From: OakLoaf Date: Wed, 18 Sep 2024 16:36:42 +0100 Subject: [PATCH] Added alpha releases --- .github/workflows/version-release.yml | 21 +++++++++--------- build.gradle.kts | 32 ++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/.github/workflows/version-release.yml b/.github/workflows/version-release.yml index 3bcbaf0..24c5c37 100644 --- a/.github/workflows/version-release.yml +++ b/.github/workflows/version-release.yml @@ -47,19 +47,18 @@ jobs: chmod +x ./gradlew ./gradlew shadowJar -# - name: Post GitHub Release -# uses: svenstaro/upload-release-action@v2 -# if: env.TAG_EXISTS == 'false' -# with: -# repo_token: ${{ secrets.REPO_TOKEN }} -# file: build/libs/*.jar -# file_glob: true -# asset_name: PluginUpdater-${{ env.VERSION }} -# tag: v${{ env.VERSION }} -# overwrite: false + - name: Post GitHub Release + uses: svenstaro/upload-release-action@v2 + if: env.TAG_EXISTS == 'false' + with: + repo_token: ${{ secrets.REPO_TOKEN }} + file: build/libs/*.jar + file_glob: true + asset_name: PluginUpdater-${{ env.VERSION }} + tag: v${{ env.VERSION }} + overwrite: false - name: Post Modrinth Release - if: env.TAG_EXISTS == 'false' run: | chmod +x ./gradlew ./gradlew modrinth \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 857d2b1..0cf2720 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,8 +1,11 @@ +import java.io.BufferedReader +import java.io.InputStreamReader + plugins { `java-library` `maven-publish` - id("com.github.johnrengelman.shadow") version("8.1.1") - id("com.modrinth.minotaur") version("2.+") + id("com.github.johnrengelman.shadow") version ("8.1.1") + id("com.modrinth.minotaur") version ("2.+") } allprojects { @@ -80,7 +83,7 @@ tasks { archiveFileName.set("${project.name}-${project.version}.jar") } - processResources{ + processResources { expand(project.properties) inputs.property("version", rootProject.version) @@ -104,9 +107,15 @@ publishing { modrinth { token.set(System.getenv("MODRINTH_TOKEN")) projectId.set("IBSpJfbm") - versionNumber.set(rootProject.version.toString()) + versionNumber.set( + if (System.getenv("TAG_EXISTS") == "false") { + rootProject.version.toString() + } else { + rootProject.version.toString() + "-" + getCurrentCommitHash() + } + ) uploadFile.set(file("build/libs/${project.name}-${project.version}.jar")) - versionType.set("release") + versionType.set(if (System.getenv("TAG_EXISTS") == "false") "release" else "false") gameVersions.addAll( "1.18", "1.18.1", "1.18.2", "1.19", "1.19.1", "1.19.2", "1.19.3", "1.19.4", @@ -115,4 +124,17 @@ modrinth { ) loaders.addAll("spigot", "paper", "purpur") syncBodyFrom.set(rootProject.file("README.md").readText()) +} + +fun getCurrentCommitHash(): String { + val process = ProcessBuilder("git", "rev-parse", "HEAD").start() + val reader = BufferedReader(InputStreamReader(process.inputStream)) + val commitHash = reader.readLine() + reader.close() + process.waitFor() + if (process.exitValue() == 0) { + return commitHash ?: "" + } else { + throw IllegalStateException("Failed to retrieve the commit hash.") + } } \ No newline at end of file