From e64dde477101967279bddb17ca08edfd61d73e7d Mon Sep 17 00:00:00 2001 From: TheSuperGamer20578 <30369708+TheSuperGamer20578@users.noreply.github.com> Date: Tue, 19 Sep 2023 16:50:59 +1000 Subject: [PATCH] Properly setup GitHub Actions --- .github/workflows/dependencies.yml | 21 ------- .github/workflows/master.yml | 41 +++++++++++++ .github/workflows/push.yml | 76 +++++++++++++++++++++++ .github/workflows/qodana.yml | 18 ------ .github/workflows/release.yml | 97 ++++++++++++++++++++++++++++++ build.gradle | 88 ++++++++++++++++++++++----- gradle.properties | 13 ++-- src/main/resources/fabric.mod.json | 8 ++- 8 files changed, 302 insertions(+), 60 deletions(-) delete mode 100644 .github/workflows/dependencies.yml create mode 100644 .github/workflows/master.yml create mode 100644 .github/workflows/push.yml delete mode 100644 .github/workflows/qodana.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/dependencies.yml b/.github/workflows/dependencies.yml deleted file mode 100644 index bcb2df9..0000000 --- a/.github/workflows/dependencies.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Dependencies -on: - push: - branches: - - master - -jobs: - dependencies: - name: Dependencies - runs-on: ubuntu-latest - permissions: - contents: write - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - - uses: mikepenz/gradle-dependency-submission@v0.8.6 - with: - use-gradlew: false diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml new file mode 100644 index 0000000..26d3f8e --- /dev/null +++ b/.github/workflows/master.yml @@ -0,0 +1,41 @@ +#file: noinspection SpellCheckingInspection +name: Push (master) +on: + push: + branches: + - master + +jobs: + dependencies: + name: Dependencies + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + - uses: mikepenz/gradle-dependency-submission@v0.8.6 + with: + use-gradlew: false + modrinth-description: + name: Update Modrinth Description + runs-on: ubuntu-latest + if: false # TODO Make description work on Modrinth + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + submodules: recursive + - uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: temurin + - uses: gradle/gradle-build-action@v2 + - name: Build + run: | + gradle modrinthSyncBody + env: + MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000..0da41b2 --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,76 @@ +name: Push +on: + pull_request_target: + push: + branches: + - "*" + +permissions: + contents: read + packages: read + +jobs: + qodana: + name: Qodana + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + submodules: recursive + - uses: JetBrains/qodana-action@v2023.2 + with: + args: -e,GITHUB_ACTOR=${{ env.GITHUB_ACTOR }},-e,GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} + env: + QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + fetch-tags: true + submodules: recursive + - uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: temurin + - uses: gradle/gradle-build-action@v2 + - name: Build + run: | + gradle build -Pci=snapshot + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/upload-artifact@v3 + with: + name: Chromatic SNAPSHOT + path: build/libs + codeql: + name: CodeQL + runs-on: ubuntu-latest + permissions: + contents: read + security-events: write + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + - uses: github/codeql-action/init@v2 + with: + languages: java + - uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: temurin + - uses: gradle/gradle-build-action@v2 + - name: Build + run: | + gradle build -Pci=snapshot --no-build-cache + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/download-artifact@v3 + with: + name: Chromatic SNAPSHOT + path: build/libs + - uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/qodana.yml b/.github/workflows/qodana.yml deleted file mode 100644 index bb1d32f..0000000 --- a/.github/workflows/qodana.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: Qodana -on: - workflow_dispatch: - pull_request: - push: - -jobs: - qodana: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - submodules: recursive - - name: 'Qodana Scan' - uses: JetBrains/qodana-action@v2023.2 - env: - QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..350867e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,97 @@ +name: Release + +on: + push: + tags: + - v*.*.* + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + fetch-tags: true + submodules: recursive + - uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: temurin + - uses: gradle/gradle-build-action@v2 + - name: Build + run: | + gradle build -Pci=release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/upload-artifact@v3 + with: + name: Chromatic Release + path: build/libs + publish: + name: Publish + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + fetch-tags: true + - name: Get version information from tag + id: tag + run: | + git fetch -f origin ${{ github.ref }}:${{ github.ref }} # https://github.com/actions/checkout/issues/290 + ref=${GITHUB_REF/refs\/tags\//} + echo "tag=$ref" >> $GITHUB_OUTPUT + echo "version=${ref/v/}" >> $GITHUB_OUTPUT + if grep -q "-" <<< "$ref" + then + echo "embed_message=" >> $GITHUB_OUTPUT + if grep -q "alpha" <<< "$ref" + then + echo "embed_colour=$((0xfc2803))" >> $GITHUB_OUTPUT + elif grep -q "beta" <<< "$ref" + then + echo "embed_colour=$((0x03befc))" >> $GITHUB_OUTPUT + else + echo "embed_colour=$((0x6be8c0))" >> $GITHUB_OUTPUT + fi + else + echo "embed_message=<@&1040804523553345646>" >> $GITHUB_OUTPUT + echo "embed_colour=$((0x6be86f))" >> $GITHUB_OUTPUT + fi + { + echo $'changelog<<\04' + git tag -l --format="%(contents)" $ref | sed -n "/-----BEGIN PGP SIGNATURE-----/q;p" | tee CHANGELOG.md + echo $'\04' + } >> $GITHUB_OUTPUT + - uses: actions/download-artifact@v3 + - uses: Kir-Antipov/mc-publish@v3.3 + id: mc-publish + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + modrinth-token: ${{ secrets.MODRINTH_TOKEN }} + curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }} + game-version-filter: releases | min-major | max-major + github-discussion: Announcements + modrinth-featured: false + name: Chromatic ${{ steps.tag.outputs.tag }} + version: ${{ steps.tag.outputs.tag }} + changelog-file: CHANGELOG.md + files: "Chromatic Release/Chromatic-${{ steps.tag.outputs.version }}.jar" + - uses: tsickert/discord-webhook@v5.3.0 + with: + webhook-url: ${{ secrets.DISCORD_WEBHOOK }} + content: ${{ steps.tag.outputs.embed_message }} + embed-title: "Chromatic ${{ steps.tag.outputs.tag }} has been released!" + embed-author-name: ${{ github.actor }} + embed-author-icon-url: https://avatars.githubusercontent.com/u/${{ github.actor_id }} + embed-color: ${{ steps.tag.outputs.embed_colour }} + embed-description: | + ${{ steps.tag.outputs.changelog }} + + __**Download:**__ + [<:github:1148533096166215730> GitHub](${{ steps.mc-publish.outputs.github-url }}) + [<:modrinth:1148533092097728592> Modrinth](https://modrinth.com/mod/${{ steps.mc-publish.outputs.modrinth-id }}/version/${{ steps.mc-publish.outputs.modrinth-version }}) + [<:curseforge:1148533086959706122> CurseForge](${{ steps.mc-publish.outputs.curseforge-url }}) diff --git a/build.gradle b/build.gradle index 47fc680..ca97e41 100644 --- a/build.gradle +++ b/build.gradle @@ -1,16 +1,56 @@ plugins { id 'fabric-loom' version '1.1-SNAPSHOT' + id 'com.github.johnrengelman.shadow' version '8.1.1' + id 'com.palantir.git-version' version '3.0.0' + id 'com.modrinth.minotaur' version '2.+' + id 'io.github.themrmilchmann.curseforge-publish' version '0.4.0' } -version = project.mod_version -group = "com.TheSuperGamer20578" + +def git = versionDetails() +def prefix = 'v' +def tag +if (git.lastTag.startsWith(prefix)) { + tag = git.lastTag.substring(prefix.length()) +} else { + tag = git.lastTag +} +if (hasProperty('ci')) { + switch (property('ci')) { + case 'release': + if (git.commitDistance != 0) { + throw new InvalidUserDataException('Not on a tag') + } + if (!git.lastTag.startsWith('v')) { + throw new InvalidUserDataException('Last tag was not a version tag') + } + version = "${tag}" + break + case 'snapshot': + version = "${tag}${tag.contains('-') ? '.' : '-'}SNAPSHOT.${git.commitDistance}.${git.branchName}.${git.gitHash}" + break + default: + throw new InvalidUserDataException("Invalid ci argument: ${property("ci")}") + } +} else { + version = "${tag}${tag.contains('-') ? '.' : '-'}SNAPSHOT.${git.commitDistance}.${git.branchName}.${git.gitHash}+local" +} +group = 'io.github.thesupergamer20578' + repositories { maven { - url "https://maven.terraformersmc.com/" - } + url 'https://maven.terraformersmc.com/' + } + maven { + url 'https://maven.shedaniel.me/' + } maven { - url "https://maven.shedaniel.me/" + url 'https://maven.pkg.github.com/thesupergamer20578/chroma/' + credentials { + username = project.findProperty('gpr.user') ?: System.getenv('GITHUB_ACTOR') + password = project.findProperty('gpr.key') ?: System.getenv('GITHUB_TOKEN') + } } } @@ -18,25 +58,24 @@ dependencies { minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - modImplementation "com.terraformersmc:modmenu:6.1.0-rc.4" - modApi("me.shedaniel.cloth:cloth-config-fabric:10.0.96") { - exclude(group: "net.fabricmc.fabric-api") + modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}" + modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}" + modApi("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}") { + exclude(group: 'net.fabricmc.fabric-api') } implementation project(":lib:JChroma") include project(":lib:JChroma") } processResources { - inputs.property "version", project.version + inputs.property 'version', project.version - filesMatching("fabric.mod.json") { - expand "version": project.version + filesMatching('fabric.mod.json') { + expand 'version': project.version } } tasks.withType(JavaCompile).configureEach { - it.options.release = 11 it.options.encoding 'UTF-8' } @@ -45,7 +84,26 @@ java { } jar { - from("LICENSE") { - rename { "${it}_${project.archivesBaseName}"} + from('LICENSE') { + rename { "${it}_${project.archivesBaseName}" } } } + +shadowJar { + archiveClassifier = 'unmapped' + configurations = [project.configurations.shadow] + exclude 'META-INF' + exclude 'org/apache/commons/lang3/**' +} + +remapJar { + dependsOn shadowJar + mustRunAfter shadowJar + inputFile = file(shadowJar.archiveFile) +} + +modrinth { + projectId = 'gB2OPOxC' + token = System.getenv('MODRINTH_TOKEN') + syncBodyFrom = rootProject.file('README.md').text +} diff --git a/gradle.properties b/gradle.properties index f195153..191dea6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,10 +1,13 @@ +# Minecraft minecraft_version=1.20.1 yarn_mappings=1.20.1+build.10 loader_version=0.14.22 -# suppress inspection "UnusedProperty" -fabric_version=0.87.0+1.20.1 -mod_version = 1.2.1 +# Dependencies +fabric_api_version=0.87.0+1.20.1 +modmenu_version=7.2.1 +cloth_config_version=11.1.106 +chroma_version=0.1.0-alpha.3 -# suppress inspection "UnusedProperty" -org.gradle.jvmargs = -Xmx1G +# Gradle config +org.gradle.jvmargs=-Xmx1G diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 7885b38..4a70dd7 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -33,5 +33,11 @@ }, "mixins": [ "chromatic.mixins.json" - ] + ], + "custom": { + "mc-publish": { + "modrinth": "gB2OPOxC", + "curseforge": "558913" + } + } } \ No newline at end of file