Skip to content

Commit

Permalink
Publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Dec 13, 2024
1 parent 5739aa6 commit 0593967
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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
- forge

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-${{ 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-${{ 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 exactly be 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", ":forge: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"
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
}
}
}

0 comments on commit 0593967

Please sign in to comment.