From 24163056397f991ae9bc8cbc42a3eda8c69bd0df Mon Sep 17 00:00:00 2001 From: 90 Date: Wed, 2 Aug 2023 13:14:48 +0100 Subject: [PATCH] Update workflows, switch to mc-publish over unifiedPublishing --- .github/workflows/build.yml | 26 +--- .github/workflows/release.yml | 68 ++++++--- build.gradle.kts | 131 ++++-------------- common/build.gradle.kts | 5 +- .../render/MEGACraftingUnitModelProvider.java | 3 + .../gripe/_90/megacells/util/Loaders.java | 5 + .../_90/megacells/util/service/Platform.java | 9 +- .../_90/megacells/util/FabricPlatform.java | 4 +- .../megacells/util/forge/ForgePlatform.java | 5 +- settings.gradle.kts | 1 - 10 files changed, 98 insertions(+), 159 deletions(-) create mode 100644 common/src/main/java/gripe/_90/megacells/util/Loaders.java diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d98f4483..50b6ad2e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,7 +5,6 @@ on: jobs: build: - if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')" runs-on: ubuntu-latest steps: - name: Checkout repository @@ -13,26 +12,13 @@ jobs: - name: Validate Gradle wrapper uses: gradle/wrapper-validation-action@v1 - name: Set up JDK 17 - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: java-version: 17 - - name: Use Gradle cache for faster builds - uses: actions/cache@v3 - with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} - - name: Cleanup Gradle Cache - # Remove some files from the Gradle cache, so they aren't cached by GitHub Actions. - # Restoring these files from a GitHub Actions cache might cause problems for future builds. - run: | - rm -f ~/.gradle/caches/modules-2/modules-2.lock - rm -f ~/.gradle/caches/modules-2/gc.properties - - name: Setup Gradle Wrapper Cache - uses: actions/cache@v3 - with: - path: ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }} + distribution: 'temurin' + - name: Set up Gradle + uses: gradle/gradle-build-action@v2 - name: Generate data - run: ./gradlew downloadAssets runData --max-workers 1 + run: ./gradlew downloadAssets runData - name: Build - run: ./gradlew build --max-workers 1 \ No newline at end of file + run: ./gradlew build \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 392fff72..6ca56a6d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,5 +1,4 @@ -name: 'Release' - +name: Release on: release: types: [published] @@ -10,30 +9,63 @@ permissions: jobs: release: runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 + - name: Checkout repository + uses: actions/checkout@v3 + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@v1 - name: Set up JDK 17 uses: actions/setup-java@v3 with: java-version: 17 distribution: 'temurin' - - name: Grant execute permission for gradlew - run: chmod +x gradlew + - name: Set up Gradle + uses: gradle/gradle-build-action@v2 - name: Generate data - run: ./gradlew downloadAssets runData --max-workers 1 + run: ./gradlew downloadAssets runData - name: Build release files + id: build env: MEGA_VERSION: ${{ github.event.release.tag_name }} - run: ./gradlew build --max-workers 1 - - name: Upload release artifacts - uses: softprops/action-gh-release@v1 + run: ./gradlew releaseInfo build + - name: Publish release files (Fabric) + uses: Kir-Antipov/mc-publish@4db8bd126f74d5e143822181a2b1201308e2c796 with: - files: build/libs/megacells-*.jar - tag_name: ${{ github.event.release.tag_name }} - - name: Upload to mod repositories - env: - MEGA_VERSION: ${{ github.event.release.tag_name }} - CHANGELOG: ${{ github.event.release.body }} - CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_API_KEY }} - run: ./gradlew :fabric:publishUnified :forge:publishUnified --max-workers 1 + github-token: ${{ secrets.GITHUB_TOKEN }} + + curseforge-id: 622112 + curseforge-token: ${{ secrets.CURSEFORGE_API_KEY }} + + modrinth-id: jjuIRIVr + modrinth-token: ${{ secrets.MODRINTH_API_KEY }} + + name: ${{ steps.build.outputs.MOD_VERSION }} (Fabric ${{ steps.build.outputs.MINECRAFT_VERSION }}) + version: fabric-${{ steps.build.outputs.MOD_VERSION }}-${{ steps.build.outputs.MINECRAFT_VERSION }} + game-versions: ${{ steps.build.outputs.MINECRAFT_VERSION }} + dependencies: | + ae2(required){curseforge:223794}{modrinth:XxWD5pD3} + appbot(optional){curseforge:610632}{modrinth:545hUrw9} + ae2wtlib(optional){curseforge:459929}{modrinth:pNabrMMw} + + files: fabric/build/libs/*[0-9].jar + - name: Publish release files (Forge) + uses: Kir-Antipov/mc-publish@4db8bd126f74d5e143822181a2b1201308e2c796 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + + curseforge-id: 622112 + curseforge-token: ${{ secrets.CURSEFORGE_API_KEY }} + + modrinth-id: jjuIRIVr + modrinth-token: ${{ secrets.MODRINTH_API_KEY }} + + name: ${{ steps.build.outputs.MOD_VERSION }} (Forge ${{ steps.build.outputs.MINECRAFT_VERSION }}) + version: forge-${{ steps.build.outputs.MOD_VERSION }}-${{ steps.build.outputs.MINECRAFT_VERSION }} + game-versions: ${{ steps.build.outputs.MINECRAFT_VERSION }} + dependencies: | + ae2(required){curseforge:223794}{modrinth:XxWD5pD3} + appmek(optional){curseforge:574300}{modrinth:IiATswDj} + appbot(optional){curseforge:610632}{modrinth:545hUrw9} + ae2wtlib(optional){curseforge:459929}{modrinth:pNabrMMw} + + files: forge/build/libs/*[0-9].jar \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index e80cb076..98ecd204 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,37 +7,24 @@ plugins { alias(libs.plugins.archLoom) apply false alias(libs.plugins.architectury) alias(libs.plugins.shadow) - alias(libs.plugins.unifiedPublishing) alias(libs.plugins.spotless) } val modId: String by project +val modVersion = (System.getenv("MEGA_VERSION") ?: "v0.0.0").substring(1) val minecraftVersion: String = libs.versions.minecraft.get() -val platforms by extra { - property("enabledPlatforms").toString().split(',') -} - -fun capitalise(str: String): String { - return str.replaceFirstChar { - if (it.isLowerCase()) { - it.titlecase() - } else { - it.toString() - } - } -} - tasks { - val collectJars by registering(Copy::class) { - val tasks = subprojects.filter { it.name in platforms }.map { it.tasks.named("remapJar") } - dependsOn(tasks) - from(tasks) - into(buildDir.resolve("libs")) - } - - assemble { - dependsOn(collectJars) + register("releaseInfo") { + doLast { + val output = System.getenv("GITHUB_OUTPUT") + + if (!output.isNullOrEmpty()) { + val outputFile = File(output) + outputFile.appendText("MOD_VERSION=$modVersion\n") + outputFile.appendText("MINECRAFT_VERSION=$minecraftVersion\n") + } + } } withType { @@ -47,14 +34,13 @@ tasks { subprojects { apply(plugin = "java") - apply(plugin = "maven-publish") apply(plugin = rootProject.libs.plugins.architectury.get().pluginId) apply(plugin = rootProject.libs.plugins.archLoom.get().pluginId) apply(plugin = rootProject.libs.plugins.spotless.get().pluginId) base.archivesName.set("$modId-${project.name}") - version = "${(System.getenv("MEGA_VERSION") ?: "v0.0.0").substring(1)}-$minecraftVersion" - group = "${property("mavenGroup")}.$modId" + version = "$modVersion-$minecraftVersion" + group = property("mavenGroup").toString() val javaVersion: String by project @@ -158,35 +144,27 @@ subprojects { prettier().config(mapOf("parser" to "json")) } } - - publishing { - publications { - create("maven${capitalise(project.name)}") { - groupId = project.group.toString() - artifactId = project.base.archivesName.get() - version = project.version.toString() - - from(components["java"]) - } - } - - // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. - repositories { - // Add repositories to publish to here. - } - } } -for (platform in platforms) { +for (platform in property("enabledPlatforms").toString().split(',')) { project(":$platform") { apply(plugin = rootProject.libs.plugins.shadow.get().pluginId) - apply(plugin = rootProject.libs.plugins.unifiedPublishing.get().pluginId) architectury { platformSetupLoomIde() loader(platform) } + fun capitalise(str: String): String { + return str.replaceFirstChar { + if (it.isLowerCase()) { + it.titlecase() + } else { + it.toString() + } + } + } + val common: Configuration by configurations.creating val shadowCommon: Configuration by configurations.creating @@ -255,66 +233,5 @@ for (platform in platforms) { javaComponent.withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) { skip() } - - if (project.version != "0.0.0") { - unifiedPublishing { - project { - val modVersion = project.version.toString() - - gameVersions.set(listOf(minecraftVersion)) - gameLoaders.set(listOf(platform)) - version.set("$platform-$modVersion") - - var releaseChannel = "release" - var changes = System.getenv("CHANGELOG") ?: "No changelog provided?" - - if (modVersion.lowercase().contains("alpha")) { - releaseChannel = "alpha" - changes = "THIS IS AN ALPHA RELEASE, MAKE A BACKUP BEFORE INSTALLING AND FREQUENTLY WHILE PLAYING, AND PLEASE REPORT ANY ISSUE YOU MAY FIND ON THE ISSUE TRACKER.\n\n$changes" - } else if (modVersion.lowercase().contains("beta")) { - releaseChannel = "beta" - changes = "This is a beta release. It is expected to be mostly stable, but in any case please report any issue you may find.\n\n$changes" - } - - releaseType.set(releaseChannel) - changelog.set(changes) - displayName.set(String.format("%s (%s %s)", - modVersion.substring(0, modVersion.lastIndexOf("-")), - capitalise(platform), - minecraftVersion)) - - mainPublication(project.tasks.getByName("remapJar")) - - relations { - depends { - curseforge.set("applied-energistics-2") - } - - optional { - curseforge.set("applied-energistics-2-wireless-terminals") - } - - optional { - curseforge.set("applied-botanics-addon") - } - - if (platform == "forge") { - optional { - curseforge.set("applied-mekanistics") - } - } - } - - val cfToken = System.getenv("CURSEFORGE_TOKEN") - - if (cfToken != null) { - curseforge { - token.set(cfToken) - id.set("622112") - } - } - } - } - } } } \ No newline at end of file diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 2d2c1e99..d00305b9 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -1,12 +1,11 @@ architectury { - val platforms: List by rootProject.extra + val platforms = property("enabledPlatforms").toString().split(',') println("Platforms: $platforms") common(platforms) } dependencies { - annotationProcessor(variantOf(libs.mixin) { classifier("processor") }) - + modImplementation(libs.fabric.loader) modCompileOnly(libs.fabric.api) modCompileOnly(libs.ae2.fabric) modCompileOnly(libs.ae2wtlib.fabric) diff --git a/common/src/main/java/gripe/_90/megacells/client/render/MEGACraftingUnitModelProvider.java b/common/src/main/java/gripe/_90/megacells/client/render/MEGACraftingUnitModelProvider.java index b47960d0..c6222a24 100644 --- a/common/src/main/java/gripe/_90/megacells/client/render/MEGACraftingUnitModelProvider.java +++ b/common/src/main/java/gripe/_90/megacells/client/render/MEGACraftingUnitModelProvider.java @@ -5,6 +5,8 @@ import java.util.List; import java.util.function.Function; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.client.resources.model.Material; @@ -18,6 +20,7 @@ import gripe._90.megacells.block.MEGACraftingUnitType; import gripe._90.megacells.util.Utils; +@Environment(EnvType.CLIENT) public class MEGACraftingUnitModelProvider extends AbstractCraftingUnitModelProvider { private static final List MATERIALS = new ArrayList<>(); diff --git a/common/src/main/java/gripe/_90/megacells/util/Loaders.java b/common/src/main/java/gripe/_90/megacells/util/Loaders.java new file mode 100644 index 00000000..e8d6e624 --- /dev/null +++ b/common/src/main/java/gripe/_90/megacells/util/Loaders.java @@ -0,0 +1,5 @@ +package gripe._90.megacells.util; + +public enum Loaders { + FABRIC, FORGE +} diff --git a/common/src/main/java/gripe/_90/megacells/util/service/Platform.java b/common/src/main/java/gripe/_90/megacells/util/service/Platform.java index af8fefdd..5e3df11b 100644 --- a/common/src/main/java/gripe/_90/megacells/util/service/Platform.java +++ b/common/src/main/java/gripe/_90/megacells/util/service/Platform.java @@ -3,15 +3,12 @@ import net.minecraft.world.item.CreativeModeTab; import gripe._90.megacells.util.Addons; +import gripe._90.megacells.util.Loaders; public interface Platform { - Loader getLoader(); + Loaders getLoader(); CreativeModeTab getCreativeTab(CreativeModeTab.DisplayItemsGenerator display); - boolean isAddonLoaded(Addons modId); - - enum Loader { - FABRIC, FORGE - } + boolean isAddonLoaded(Addons addon); } diff --git a/fabric/src/main/java/gripe/_90/megacells/util/FabricPlatform.java b/fabric/src/main/java/gripe/_90/megacells/util/FabricPlatform.java index a763afea..7dc446b1 100644 --- a/fabric/src/main/java/gripe/_90/megacells/util/FabricPlatform.java +++ b/fabric/src/main/java/gripe/_90/megacells/util/FabricPlatform.java @@ -10,8 +10,8 @@ public final class FabricPlatform implements Platform { @Override - public Loader getLoader() { - return Loader.FABRIC; + public Loaders getLoader() { + return Loaders.FABRIC; } @Override diff --git a/forge/src/main/java/gripe/_90/megacells/util/forge/ForgePlatform.java b/forge/src/main/java/gripe/_90/megacells/util/forge/ForgePlatform.java index 72c9dd05..415b3d41 100644 --- a/forge/src/main/java/gripe/_90/megacells/util/forge/ForgePlatform.java +++ b/forge/src/main/java/gripe/_90/megacells/util/forge/ForgePlatform.java @@ -8,12 +8,13 @@ import gripe._90.megacells.definition.MEGAItems; import gripe._90.megacells.definition.MEGATranslations; import gripe._90.megacells.util.Addons; +import gripe._90.megacells.util.Loaders; import gripe._90.megacells.util.service.Platform; public final class ForgePlatform implements Platform { @Override - public Loader getLoader() { - return Loader.FORGE; + public Loaders getLoader() { + return Loaders.FORGE; } @Override diff --git a/settings.gradle.kts b/settings.gradle.kts index 35872db6..fa3c3f47 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -13,7 +13,6 @@ dependencyResolutionManagement { plugin("archLoom", "dev.architectury.loom").version("1.3-SNAPSHOT") plugin("architectury", "architectury-plugin").version("3.4-SNAPSHOT") plugin("shadow", "com.github.johnrengelman.shadow").version("8.1.1") - plugin("unifiedPublishing", "me.shedaniel.unified-publishing").version("0.1.+") plugin("spotless", "com.diffplug.spotless").version("6.20.0") val minecraftVersion = "1.20.1"