From 302f486f1c702fe631a03ba2c28cb9638c431619 Mon Sep 17 00:00:00 2001 From: moonleay Date: Fri, 10 May 2024 15:17:26 +0000 Subject: [PATCH] chore/add-ci (#3) Added ci for dev and release builds. Reviewed-on: https://codeberg.org/moonleay/Gimbal/pulls/3 Co-authored-by: moonleay Co-committed-by: moonleay --- .forgejo/workflows/build-dev.yml | 42 ++++++++++++++++++++++ .forgejo/workflows/build-release.yml | 54 ++++++++++++++++++++++++++++ build.gradle.kts | 53 +++++++++++++++++++++------ src/main/resources/fabric.mod.json | 3 ++ 4 files changed, 141 insertions(+), 11 deletions(-) create mode 100644 .forgejo/workflows/build-dev.yml create mode 100644 .forgejo/workflows/build-release.yml diff --git a/.forgejo/workflows/build-dev.yml b/.forgejo/workflows/build-dev.yml new file mode 100644 index 0000000..e0449f4 --- /dev/null +++ b/.forgejo/workflows/build-dev.yml @@ -0,0 +1,42 @@ +on: + push: + branches-ignore: + - refs/tags/ + +jobs: + dev: + runs-on: nodebullshit + steps: + - uses: actions/checkout@v3 + name: Checkout + + - name: Set short git commit reference + id: vars + run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + - uses: https://github.com/actions/setup-java@v4 + name: Setup Java + with: + distribution: temurin + java-version: 17 + + - uses: https://github.com/gradle/actions/setup-gradle@v3 + name: Setup Gradle + env: + GIT_SHA_SHORT: ${{ steps.vars.outputs.sha_short }} + + - run: ./gradlew runDatagen + name: Generate assets + env: + GIT_SHA_SHORT: ${{ steps.vars.outputs.sha_short }} + + - run: ./gradlew build + name: Build project + env: + GIT_SHA_SHORT: ${{ steps.vars.outputs.sha_short }} + + - run: ./gradlew publish + name: Upload + env: + GIT_SHA_SHORT: ${{ steps.vars.outputs.sha_short }} + PACKAGE_REPO_KEY: ${{ secrets.PACKAGE_REPO_KEY }} diff --git a/.forgejo/workflows/build-release.yml b/.forgejo/workflows/build-release.yml new file mode 100644 index 0000000..01b60ea --- /dev/null +++ b/.forgejo/workflows/build-release.yml @@ -0,0 +1,54 @@ +on: + release: + types: + - released + - prereleased + - created + - published + +jobs: + release: + runs-on: nodebullshit + steps: + - uses: actions/checkout@v3 + name: Checkout + + - name: Fetch the full git repository + run: git fetch --prune --unshallow + + - name: Set short git commit reference + id: vars + run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + - uses: https://github.com/actions/setup-java@v4 + name: Setup Java + with: + distribution: temurin + java-version: 17 + + - uses: https://github.com/gradle/actions/setup-gradle@v3 + name: Setup Gradle + env: + GIT_SHA_SHORT: ${{ steps.vars.outputs.sha_short }} + + - run: ./gradlew runDatagen + name: Generate assets + env: + GIT_SHA_SHORT: ${{ steps.vars.outputs.sha_short }} + + - run: ./gradlew build + name: Build project + env: + GIT_SHA_SHORT: ${{ steps.vars.outputs.sha_short }} + + - run: ./gradlew publish + name: Upload + env: + GIT_SHA_SHORT: ${{ steps.vars.outputs.sha_short }} + PACKAGE_REPO_KEY: ${{ secrets.PACKAGE_REPO_KEY }} + + - run: ./gradlew modrinth + name: Publish to Modrinth + env: + GIT_SHA_SHORT: ${{ steps.vars.outputs.sha_short }} + MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} diff --git a/build.gradle.kts b/build.gradle.kts index b0bfac9..efb5c4d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -27,10 +27,13 @@ plugins { `maven-publish` eclipse id("org.jetbrains.gradle.plugin.idea-ext") + id("com.modrinth.minotaur") version "2.+" } -val mavenVersion = System.getenv("CI_COMMIT_TAG") ?: System.getenv("CI_COMMIT_SHORT_SHA")?.let { "$it-dev" } -?: "0.3.0" //"0.0.0-SNAPSHOT" +val ver = if ((System.getenv("GITHUB_REF") ?: "local").startsWith("refs/tags/")) + System.getenv("GITHUB_REF_NAME") ?: "err" else System.getenv("GIT_SHA_SHORT") ?: "0.0.0" + +val mavenVersion = ver val modId: String by project val modName: String by project @@ -184,17 +187,18 @@ publishing { } repositories { - if (System.getenv("CI_JOB_TOKEN") != null) { + if (System.getenv("CI") != null) { maven { - name = "GitLab" - val projectId = System.getenv("CI_PROJECT_ID") - val apiV4 = System.getenv("CI_API_V4_URL") - url = uri("$apiV4/projects/$projectId/packages/maven") + name = "Codeberg" + val repoOwner = System.getenv("GITHUB_REPOSITORY_OWNER") + val serverUrl = System.getenv("GITHUB_SERVER_URL") + val accessToken = System.getenv("PACKAGE_REPO_KEY") + url = uri("$serverUrl/api/packages/$repoOwner/maven") authentication { - create("token", HttpHeaderAuthentication::class.java) { - credentials(HttpHeaderCredentials::class.java) { - name = "Job-Token" - value = System.getenv("CI_JOB_TOKEN") + create("header", HttpHeaderAuthentication::class.java) { + credentials(HttpHeaderCredentials::class) { + name = "Authorization" + value = "token $accessToken" } } } @@ -203,6 +207,33 @@ publishing { } } +// build.gradle.kts +modrinth { + token.set(System.getenv("MODRINTH_TOKEN")) // Remember to have the MODRINTH_TOKEN environment variable set or else this will fail - just make sure it stays private! + projectId.set(modId) // This can be the project ID or the slug. Either will work! + versionNumber.set(mavenVersion) // You don't need to set this manually. Will fail if Modrinth has this version already + versionName.set("$modName $mavenVersion for $minecraftVersion") + versionType.set("alpha") // This is the default -- can also be `beta` or `alpha` + uploadFile.set(tasks.remapJar) // With Loom, this MUST be set to `remapJar` instead of `jar`! + gameVersions.addAll(listOf(project.ext["minecraft.version"] as String)) // Must be an array, even with only one version + loaders.add("fabric") // Must also be an array - no need to specify this if you're using Loom or ForgeGradle + changelog.set( + "Changelog v$mavenVersion\n\nCheckout the changelog [on codeberg](${System.getenv("GITHUB_SERVER_URL") ?: ""}/${ + System.getenv( + "GITHUB_REPOSITORY" + ) ?: "" + }/releases/tag/${System.getenv("GITHUB_REF_NAME") ?: ""})" + ) + dependencies { // A special DSL for creating dependencies + // scope.type + // The scope can be `required`, `optional`, `incompatible`, or `embedded` + // The type can either be `project` or `version` + required.project("fabric-api") // Creates a new required dependency on Fabric API + required.project("fabric-language-kotlin") + } +} + + rootProject.idea.project { this as ExtensionAware configure { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 2a47121..0f9c789 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -7,6 +7,9 @@ "authors": [ "moonleay" ], + "contributors": [ + "Cookieso" + ], "icon": "assets/${modId}/logo.png", "contact": { "email": "contact@moonleay.net",