diff --git a/.github/workflows/build-commit.yml b/.github/workflows/build-commit.yml new file mode 100644 index 00000000..37eede3f --- /dev/null +++ b/.github/workflows/build-commit.yml @@ -0,0 +1,38 @@ +name: build-commit +on: [ push ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Extract Current Branch Name + shell: bash + # bash pattern expansion to grab the branch name without the slashes + run: ref="${GITHUB_REF#refs/heads/}" && echo "branch=${ref////-}" >> $GITHUB_OUTPUT + id: ref + + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Validate Gradle Wrapper + uses: gradle/actions/wrapper-validation@v3 + + - name: Setup JDK + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 21 + cache: gradle + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + + - name: Gradle Build + run: ./gradle build + + - name: Capture Build Artifacts + uses: actions/upload-artifact@v4 + with: + name: simply-no-shading-artifacts-${{ steps.ref.outputs.branch }} + path: build/libs/*.jar diff --git a/.github/workflows/build-pull-request.yml b/.github/workflows/build-pull-request.yml new file mode 100644 index 00000000..0ca3a7ba --- /dev/null +++ b/.github/workflows/build-pull-request.yml @@ -0,0 +1,26 @@ +name: build-pull-request +on: [ push ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Validate Gradle Wrapper + uses: gradle/actions/wrapper-validation@v3 + + - name: Setup JDK + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 21 + cache: gradle + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + + - name: Gradle Build + run: ./gradle build diff --git a/.github/workflows/publish.yml b/.github/workflows/build-release.yml similarity index 57% rename from .github/workflows/publish.yml rename to .github/workflows/build-release.yml index ac9cf946..57fe1508 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/build-release.yml @@ -1,34 +1,45 @@ -name: Publish +name: build-release on: release: - types: [published] + types: + - published jobs: build: + runs-on: ubuntu-latest + permissions: contents: write - runs-on: ubuntu-latest + steps: - - name: Checkout repository + - name: Checkout Repository uses: actions/checkout@v4 - - name: Validate gradle wrapper - uses: gradle/wrapper-validation-action@v3 + + - name: Validate Gradle Wrapper + uses: gradle/actions/wrapper-validation@v3 + - name: Setup JDK uses: actions/setup-java@v4 with: distribution: temurin java-version: 21 - - name: Make gradle wrapper executable + cache: gradle + + - name: Make Gradle Wrapper Executable run: chmod +x ./gradlew + - name: Build - run: ./gradlew clean -Pversion=${{ github.ref_name }} build --stacktrace - - name: Upload binaries to release + run: ./gradlew clean build -Pbuild.release=true + + - name: Upload Binaries to GitHub Release uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} - file: build/libs/* + file: 'build/libs/*.jar;LICENSE' file_glob: true - - uses: Kir-Antipov/mc-publish@v3.3 + + - name: Upload Binaries to Modrinth + uses: Kir-Antipov/mc-publish@v3.3 with: modrinth-id: 9gx5Xvc5 modrinth-token: ${{ secrets.MODRINTH_TOKEN }} diff --git a/.github/workflows/build-tag.yml b/.github/workflows/build-tag.yml new file mode 100644 index 00000000..fb49c677 --- /dev/null +++ b/.github/workflows/build-tag.yml @@ -0,0 +1,38 @@ +name: build-tag +on: [ push ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Extract Current Branch Name + shell: bash + # bash pattern expansion to grab the branch name without the slashes + run: ref="${GITHUB_REF#refs/heads/}" && echo "branch=${ref////-}" >> $GITHUB_OUTPUT + id: ref + + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Validate Gradle Wrapper + uses: gradle/actions/wrapper-validation@v3 + + - name: Setup JDK + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 21 + cache: gradle + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + + - name: Gradle Build + run: ./gradlew build -Pbuild.release=true + + - name: Capture Build Artifacts + uses: actions/upload-artifact@v4 + with: + name: simply-no-shading-artifacts-${{ steps.ref.outputs.branch }} + path: build/libs/*.jar diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index fd597535..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Build -on: - push: - branches: - - '**' - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Validate gradle wrapper - uses: gradle/wrapper-validation-action@v3 - - name: Setup JDK - uses: actions/setup-java@v4 - with: - distribution: temurin - java-version: 21 - cache: gradle - - name: Make gradle wrapper executable - run: chmod +x ./gradlew - - name: Shorten SHA - shell: bash - run: echo "short_sha=$(git rev-parse --short HEAD)" >> "$GITHUB_ENV" - - name: Build - uses: burrunan/gradle-cache-action@v1 - with: - arguments: -Pversion=${{ env.short_sha }}-alpha build --stacktrace - - name: Capture build artifacts - uses: actions/upload-artifact@v4 - with: - name: Artifacts - path: build/libs/ diff --git a/.github/workflows/pull_build.yml b/.github/workflows/pull_build.yml deleted file mode 100644 index e227c5df..00000000 --- a/.github/workflows/pull_build.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Pull Request Build -on: [ pull_request ] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Validate gradle wrapper - uses: gradle/wrapper-validation-action@v3 - - name: Setup JDK - uses: actions/setup-java@v4 - with: - distribution: temurin - java-version: 21 - cache: gradle - - name: Make gradle wrapper executable - run: chmod +x ./gradlew - - name: Shorten SHA - shell: bash - run: echo "short_sha=$(git rev-parse --short ${{ github.event.pull_request.head.sha }})" >> "$GITHUB_ENV" - - name: Build - uses: burrunan/gradle-cache-action@v1 - with: - arguments: -Pversion=${{ env.short_sha }}-alpha.pr.${{ github.event.number }} build --stacktrace - - name: Capture build artifacts - uses: actions/upload-artifact@v4 - with: - name: Artifacts - path: build/libs/ diff --git a/build.gradle.kts b/build.gradle.kts index 99786c50..d22b3e3f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,5 @@ object Constants { + const val MOD_NAME: String = "Simply No Shading" const val MOD_VERSION: String = "7.0.0" } @@ -27,16 +28,101 @@ java { withSourcesJar() } +dependencies { + fun net.fabricmc.loom.configuration.FabricApiExtension.module(moduleName: String): Dependency = + fabricApi.module(moduleName, libs.versions.fabric.api.get()) + + minecraft(libs.minecraft) + mappings(loom.officialMojangMappings()) + modImplementation(libs.fabric.loader) + + modRuntimeOnly(libs.fabric.api) + modCompileOnly(fabricApi.module("fabric-lifecycle-events-v1")) + modCompileOnly(fabricApi.module("fabric-key-binding-api-v1")) + modCompileOnly(fabricApi.module("fabric-resource-loader-v0")) + "modClientImplementation"(libs.modmenu) { + exclude(mapOf("module" to "fabric-loader")) + } +} + +testing { + suites { + val clientTest by registering(JvmTestSuite::class) { + val client by sourceSets.getting + + sources { + compileClasspath += client.compileClasspath + runtimeClasspath += client.runtimeClasspath + } + + dependencies { + implementation(client.output) + } + } + } +} + +tasks { + withType { + val data = mapOf( + "gameVersion" to libs.versions.fabric.minecraft.get(), + "javaVersion" to libs.versions.java.get(), + "minecraftVersion" to libs.versions.minecraft.get(), + "version" to version, + ) + + inputs.properties(data) + + filesMatching("fabric.mod.json") { + expand(data) + } + } + + withType { + options.encoding = "UTF-8" + } + + javadoc { + classpath += sourceSets["client"].compileClasspath + source += sourceSets["client"].allJava + val options = this.options as StandardJavadocDocletOptions; + + val title = "${Constants.MOD_NAME} ${version}" + options.docTitle(title) + options.windowTitle(title) + + options.tags( + "apiNote:a:API Note", + "implNote:a:Implementation Note", + "implSpec:a:Implementation Requirements", + ) + } + + jar { + manifest { + attributes(mapOf( + "Implementation-Title" to Constants.MOD_NAME, + "Implementation-Version" to Constants.MOD_VERSION, + "Implementation-Vendor" to "StartsMercury", + )) + } + } +} + /******************************************************************************/ -/* DEPENDENCIES */ +/* COMPATIBILITY TESTS */ /******************************************************************************/ +createCompatTest("bedrockify") +createCompatTest("enhancedblockentities") +createCompatTest("sodium") +createCompatTest("indium", "sodium") + repositories { maven { name = "shedaniel's Maven" url = uri("https://maven.shedaniel.me") content { - // cloth-config-fabric includeGroup("me.shedaniel.cloth") } } @@ -45,12 +131,10 @@ repositories { name = "Terraformers Maven" url = uri("https://maven.terraformersmc.com") content { - // modmenu includeGroup("com.terraformersmc") } } - // mod dependencies without dedicated repositories maven { name = "Modrinth Maven" url = uri("https://api.modrinth.com/maven") @@ -59,7 +143,6 @@ repositories { } } - // mod dependencies that aren't on modrinth or have corrupt version numbers ivy { name = "GitHub Releases" url = uri("https://github.com") @@ -74,131 +157,22 @@ repositories { } } -createCompatTest("bedrockify") -createCompatTest("enhancedblockentities") -createCompatTest("sodium") -createCompatTest("indium", "sodium") - dependencies { - fun net.fabricmc.loom.configuration.FabricApiExtension.module(moduleName: String): Dependency = - fabricApi.module(moduleName, libs.versions.fabric.api.get()) - - // ARRP - "modEnhancedblockentitiesCompatTestClientRuntimeOnly"(libs.arrp) { - exclude(mapOf("module" to "fabric-loader")) - } - - // BedrockIfy "modBedrockifyAuto"(libs.bedrockify) - - // Cloth Config "modBedrockifyCompatTestClientRuntimeOnly"(libs.cloth.config) { exclude(mapOf("group" to "net.fabricmc.fabric-api")) exclude(mapOf("module" to "fabric-loader")) exclude(mapOf("module" to "gson")) } - // Deobfuscation Mappings (required) - mappings(loom.officialMojangMappings()) - - // Enhanced Block Entities "modEnhancedblockentitiesClientAuto"(libs.enhancedblockentities) - - // Fabric API - modRuntimeOnly(libs.fabric.api) - - // Fabric Lifecycle Events (v1) - modCompileOnly(fabricApi.module("fabric-lifecycle-events-v1")) - - // Fabric Loader (required) - modImplementation(libs.fabric.loader) - - // Fabric Key Binding API (v1) - modCompileOnly(fabricApi.module("fabric-key-binding-api-v1")) - - // Fabric Resource Loader (v0) - modCompileOnly(fabricApi.module("fabric-resource-loader-v0")) - - // Indium - "modIndiumClientAuto"(libs.indium) - - // Minecraft (required) - minecraft(libs.minecraft) - - // ModMenu - "modClientImplementation"(libs.modmenu) { + "modEnhancedblockentitiesCompatTestClientRuntimeOnly"(libs.arrp) { exclude(mapOf("module" to "fabric-loader")) } - // Sodium "modSodiumClientAuto"(libs.sodium) -} - -/******************************************************************************/ -/* TESTING SUITES */ -/******************************************************************************/ - -testing { - suites { - val clientTest by registering(JvmTestSuite::class) { - val client by sourceSets.getting - - sources { - compileClasspath += client.compileClasspath - runtimeClasspath += client.runtimeClasspath - } - dependencies { - implementation(client.output) - } - } - } -} - -/******************************************************************************/ -/* TASK CONFIGURATIONS */ -/******************************************************************************/ - -tasks.withType { - val data = mapOf( - "gameVersion" to libs.versions.fabric.minecraft.get(), - "javaVersion" to libs.versions.java.get(), - "minecraftVersion" to libs.versions.minecraft.get(), - "version" to version, - ) - - inputs.properties(data) - - filesMatching("fabric.mod.json") { - expand(data) - } -} - -tasks.withType { - options.encoding = "UTF-8" -} - -tasks.named("javadoc") { - classpath += sourceSets["client"].compileClasspath - source += sourceSets["client"].allJava - - when (val options = this.options) { - is StandardJavadocDocletOptions -> options.tags( - "apiNote:a:API Note", - "implNote:a:Implementation Note", - "implSpec:a:Implementation Requirements", - ) - } -} - -tasks.named("jar") { - manifest { - attributes(mapOf( - "Implementation-Title" to "Simply No Shading", - "Implementation-Version" to Constants.MOD_VERSION, - "Implementation-Vendor" to "StartsMercury", - )) - } + "modIndiumClientAuto"(libs.indium) } /******************************************************************************/ @@ -287,18 +261,28 @@ fun createCompatTest(name: String, vararg fosters: String) { } } -/** - * Helper function to construct the complete version. - */ fun createVersionString(): String { - val version = version + val builder = StringBuilder() + + val isReleaseBuild = project.hasProperty("build.release") + val buildId = System.getenv("GITHUB_RUN_NUMBER") - return if (version is String && version != DEFAULT_VERSION) { - version + if (isReleaseBuild) { + builder.append(Constants.MOD_VERSION) } else { - val mod = Constants.MOD_VERSION - val minecraft = libs.versions.fabric.minecraft + builder.append(Constants.MOD_VERSION.substringBefore('-')) + builder.append("-snapshot") + } + + builder.append("+mc").append(libs.versions.minecraft.get()) - "$mod+mc$minecraft" + if (!isReleaseBuild) { + if (buildId != null) { + builder.append("-build.${buildId}") + } else { + builder.append("-local") + } } + + return builder.toString() }