Skip to content

Commit

Permalink
Update workflows, switch to mc-publish over unifiedPublishing
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Aug 2, 2023
1 parent 13bf340 commit 2416305
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 159 deletions.
26 changes: 6 additions & 20 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,20 @@ on:

jobs:
build:
if: "! contains(toJSON(github.event.commits.*.message), '[ci skip]')"
runs-on: ubuntu-latest
steps:
- 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@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
run: ./gradlew build
68 changes: 50 additions & 18 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: 'Release'

name: Release
on:
release:
types: [published]
Expand All @@ -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
131 changes: 24 additions & 107 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Jar> {
Expand All @@ -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

Expand Down Expand Up @@ -158,35 +144,27 @@ subprojects {
prettier().config(mapOf("parser" to "json"))
}
}

publishing {
publications {
create<MavenPublication>("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

Expand Down Expand Up @@ -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")
}
}
}
}
}
}
}
5 changes: 2 additions & 3 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
architectury {
val platforms: List<String> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,6 +20,7 @@
import gripe._90.megacells.block.MEGACraftingUnitType;
import gripe._90.megacells.util.Utils;

@Environment(EnvType.CLIENT)
public class MEGACraftingUnitModelProvider extends AbstractCraftingUnitModelProvider<MEGACraftingUnitType> {
private static final List<Material> MATERIALS = new ArrayList<>();

Expand Down
5 changes: 5 additions & 0 deletions common/src/main/java/gripe/_90/megacells/util/Loaders.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package gripe._90.megacells.util;

public enum Loaders {
FABRIC, FORGE
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

public final class FabricPlatform implements Platform {
@Override
public Loader getLoader() {
return Loader.FABRIC;
public Loaders getLoader() {
return Loaders.FABRIC;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 2416305

Please sign in to comment.