Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup publishing workflow for lithium #602

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Publish Release

on:
workflow_dispatch:
inputs:
releaseType:
type: choice
description: Release Type
options:
- stable
- beta
- alpha
platform:
type: choice
description: Platform
options:
- both
- fabric
- neoforge

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup Java
run: echo "JAVA_HOME=$JAVA_HOME_21_X64" >> "$GITHUB_ENV"

- name: Loom Cache
uses: actions/cache@v4
with:
path: "**/.gradle/loom-cache"
key: "${{ runner.os }}-gradle-loom-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}"
restore-keys: "${{ runner.os }}-gradle-loom-"
- name: ModDevGradle Cache
uses: actions/cache@v4
with:
path: "**/.gradle/repositories"
key: "${{ runner.os }}-gradle-mdg-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}"
restore-keys: "${{ runner.os }}-gradle-mdg-"

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
gradle-home-cache-cleanup: true
cache-read-only: true

- name: Validate Gradle Wrapper Integrity
uses: gradle/wrapper-validation-action@v2

- name: Build & Publish
env:
RELEASE_WORKFLOW: true
RELEASE_TYPE: ${{ inputs.releaseType }}
PLATFORM: ${{ inputs.platform }}
MODRINTH_API_KEY: ${{ secrets.MODRINTH_API_KEY }}
CURSEFORGE_API_KEY: ${{ secrets.CURSEFORGE_API_KEY }}
run: ./gradlew lithiumPublish
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
INFO:
Use Markdown, whatever is written after the dashed line will be exactly what shows up on modrinth and curseforge

Change logging starts below:
----------
18 changes: 18 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id("java")
id("fabric-loom") version ("1.8.9") apply (false)
id("me.modmuss50.mod-publish-plugin") version ("0.8.1") apply (false)

// Mixin config plugin is a subproject for creating lithium's settings from annotations in each mixin package.
id("net.caffeinemc.mixin-config-plugin") version ("1.0-SNAPSHOT") apply (false)
Expand Down Expand Up @@ -35,6 +36,7 @@ tasks.jar {

subprojects {
apply(plugin = "maven-publish")
apply(plugin = "me.modmuss50.mod-publish-plugin")

java.toolchain.languageVersion = JavaLanguageVersion.of(21)

Expand Down Expand Up @@ -89,3 +91,19 @@ subprojects {
isPreserveFileTimestamps = false
}
}

tasks.create("lithiumPublish") {
when (val platform = providers.environmentVariable("PLATFORM").orNull) {
"both" -> {
dependsOn(tasks.build, ":fabric:publishMods", ":neoforge:publishMods")
}
"fabric", "forge" -> {
dependsOn("${platform}:build", "${platform}:publish", "${platform}:publishMods")
}
else -> {
val isRelease = providers.environmentVariable("RELEASE_WORKFLOW").orNull;
if (isRelease != null && isRelease == "true")
throw IllegalStateException("Environment variable PLATFORM cannot be null when running on CI!")
}
}
}
38 changes: 38 additions & 0 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import me.modmuss50.mpp.ReleaseType

plugins {
id("java")
id("idea")
Expand Down Expand Up @@ -193,4 +195,40 @@ tasks.named<net.caffeinemc.gradle.CreateMixinConfigTask>("fabricCreateMixinConfi

tasks.named("processResources") {
dependsOn("fabricCreateMixinConfig")
}

publishMods {
displayName = "Lithium $MOD_VERSION for Fabric"
version = "mc$MINECRAFT_VERSION-$MOD_VERSION-fabric"
file = tasks.remapJar.get().archiveFile
changelog = rootProject.file("CHANGELOG.md").readText().split("----------")[1].trim()
type = getReleaseType()
modLoaders.add("fabric")
modLoaders.add("quilt")

modrinth {
accessToken = providers.environmentVariable("CURSEFORGE_API_KEY")
projectId = "360438"
minecraftVersions.add(MINECRAFT_VERSION)
}

modrinth {
accessToken = providers.environmentVariable("MODRINTH_API_KEY")
projectId = "gvQqBUqZ"
minecraftVersions.add(MINECRAFT_VERSION)
}
}

fun getReleaseType(): ReleaseType {
return when (val releaseType = providers.environmentVariable("RELEASE_TYPE").orNull) {
"alpha"-> ReleaseType.ALPHA
"beta" -> ReleaseType.BETA
"stable" -> ReleaseType.STABLE
else -> {
if (releaseType != null)
throw IllegalArgumentException("Release type must be alpha, beta or stable!")

ReleaseType.STABLE
}
}
}
37 changes: 37 additions & 0 deletions neoforge/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import me.modmuss50.mpp.ReleaseType

plugins {
id("idea")
id("net.neoforged.moddev") version "2.0.42-beta"
Expand Down Expand Up @@ -181,4 +183,39 @@ tasks.named<net.caffeinemc.gradle.CreateMixinConfigTask>("neoforgeCreateMixinCon

tasks.named("processResources") {
dependsOn("neoforgeCreateMixinConfig")
}

publishMods {
displayName = "Lithium $MOD_VERSION for Neoforge"
version = "mc$MINECRAFT_VERSION-$MOD_VERSION-neoforge"
file = tasks.jar.get().archiveFile
changelog = rootProject.file("CHANGELOG.md").readText().split("----------")[1].trim()
type = getReleaseType()
modLoaders.add("neoforge")

modrinth {
accessToken = providers.environmentVariable("CURSEFORGE_API_KEY")
projectId = "360438"
IThundxr marked this conversation as resolved.
Show resolved Hide resolved
minecraftVersions.add(MINECRAFT_VERSION)
}

modrinth {
accessToken = providers.environmentVariable("MODRINTH_API_KEY")
projectId = "gvQqBUqZ"
minecraftVersions.add(MINECRAFT_VERSION)
}
}

fun getReleaseType(): ReleaseType {
return when (val releaseType = providers.environmentVariable("RELEASE_TYPE").orNull) {
"alpha"-> ReleaseType.ALPHA
"beta" -> ReleaseType.BETA
"stable" -> ReleaseType.STABLE
else -> {
if (releaseType != null)
throw IllegalArgumentException("Release type must be alpha, beta or stable!")

ReleaseType.STABLE
}
}
}