From 6e84c792041eae740bb0e5b54e0188c2c98a336a Mon Sep 17 00:00:00 2001 From: LaylaMeower Date: Thu, 14 Dec 2023 21:01:16 +0200 Subject: [PATCH] Added the current bot version to `/about`; Changed CI to create releases when pushing to `root` branch. --- .github/workflows/ci.yml | 12 ++----- .github/workflows/develop.yml | 10 +----- .github/workflows/root.yml | 35 +++++++++++++------ .version | 1 + build.gradle.kts | 23 +++++++++--- .../quest/laxla/trouper/AboutExtension.kt | 2 +- src/main/kotlin/quest/laxla/trouper/App.kt | 1 + 7 files changed, 50 insertions(+), 34 deletions(-) create mode 100644 .version diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d13c2bc..ae6fd1f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,8 @@ on: - develop pull_request: + branches-ignore: + - root jobs: build: @@ -22,20 +24,12 @@ jobs: java-version: 17 distribution: temurin - - name: Gradle (Build) + - name: Build uses: gradle/gradle-build-action@v2 with: arguments: build - - name: Upload artifacts (Main JAR) - uses: actions/upload-artifact@v3 - - with: - name: Main JAR - path: build/libs/*-all.jar - if-no-files-found: error - - name: Upload artifacts (JARs) uses: actions/upload-artifact@v3 diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index 33828cf..8b30e86 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -19,20 +19,12 @@ jobs: java-version: 17 distribution: temurin - - name: Gradle (Build) + - name: Build uses: gradle/gradle-build-action@v2 with: arguments: build - - name: Upload artifacts (Main JAR) - uses: actions/upload-artifact@v3 - - with: - name: Main JAR - path: build/libs/*-all.jar - if-no-files-found: error - - name: Upload artifacts (JARs) uses: actions/upload-artifact@v3 diff --git a/.github/workflows/root.yml b/.github/workflows/root.yml index 2a005ff..6ba0aae 100644 --- a/.github/workflows/root.yml +++ b/.github/workflows/root.yml @@ -11,6 +11,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + fetch-tags: true - name: Set up Java uses: actions/setup-java@v4 @@ -19,25 +21,38 @@ jobs: java-version: 17 distribution: temurin - - name: Gradle (Build) + - name: Build uses: gradle/gradle-build-action@v2 with: arguments: build dependency-graph: generate-and-submit - - name: Upload artifacts (Main JAR) - uses: actions/upload-artifact@v3 - - with: - name: Main JAR - path: build/libs/*-all.jar - if-no-files-found: error - - - name: Upload artifacts (JARs) + - name: Upload artifacts uses: actions/upload-artifact@v3 with: name: JARs path: build/libs/*.jar if-no-files-found: warn + + - name: Validate version + id: version + run: | + VERSION=$(cat .version) + echo "version=${VERSION}" >> $GITHUB_OUTPUT + + if git show-ref --tags --verify --quiet "refs/tags/${VERSION}"; then + echo "Version ${VERSION} was already released" + exit 0 + fi + + - name: Release artifacts + uses: marvinpinto/action-automatic-releases@v1 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + prerelease: false + automatic_release_tag: ${{ steps.version.outputs.version }} + files: | + build/libs/*.jar + LICENSE.md diff --git a/.version b/.version new file mode 100644 index 0000000..388bb06 --- /dev/null +++ b/.version @@ -0,0 +1 @@ +0.1.0-alpha diff --git a/build.gradle.kts b/build.gradle.kts index 5afb90e..f4b7140 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,7 +10,7 @@ plugins { } group = "quest.laxla" -version = "0.0.1" +version = file(".version").readText() repositories { google() @@ -43,14 +43,23 @@ dependencies { runtimeOnly("ch.qos.logback:logback-classic:$logback") } +val generatedResources = layout.buildDirectory.dir("generated/resources") + +tasks.processResources { + from(generatedResources) + + doFirst { + generatedResources.orNull?.run { + asFile.mkdirs() + file(".version").asFile.writeText(version.toString()) + } + } +} + application { mainClass = "quest.laxla.trouper.AppKt" } -val jvm: String by project - -tasks.withType { kotlinOptions.jvmTarget = jvm } - tasks.jar { manifest { attributes( @@ -59,6 +68,10 @@ tasks.jar { } } +val jvm: String by project + +tasks.withType { kotlinOptions.jvmTarget = jvm } + java { val java = JavaVersion.toVersion(jvm) sourceCompatibility = java diff --git a/src/main/kotlin/quest/laxla/trouper/AboutExtension.kt b/src/main/kotlin/quest/laxla/trouper/AboutExtension.kt index 9b85282..fbdd479 100644 --- a/src/main/kotlin/quest/laxla/trouper/AboutExtension.kt +++ b/src/main/kotlin/quest/laxla/trouper/AboutExtension.kt @@ -32,7 +32,7 @@ class AboutExtension : TrouperExtension() { allowedMentions() embed { - title = "About ${self.effectiveName}" + title = "About ${self.effectiveName}" + if (version == null) "" else " `$version`" thumbnail { url = avatar } if (isDevelopmentEnvironment) field { diff --git a/src/main/kotlin/quest/laxla/trouper/App.kt b/src/main/kotlin/quest/laxla/trouper/App.kt index 6a31b4b..ae09eda 100644 --- a/src/main/kotlin/quest/laxla/trouper/App.kt +++ b/src/main/kotlin/quest/laxla/trouper/App.kt @@ -15,6 +15,7 @@ val license = envOrNull("LICENSE") val licenseUrl = envOrNull("LICENSE_URL") val donateUrl = envOrNull("DONATE_URL") val repoUrl = envOrNull("REPO_URL") +val version = AboutExtension::class.java.getResourceAsStream("/.version")?.bufferedReader()?.use { it.readText() } fun main() = runBlocking { ExtensibleBot(token) {