Skip to content

Commit

Permalink
Publish Fabric jars to CF/Modrinth
Browse files Browse the repository at this point in the history
Like all publishing code, we'll only find out if it works when we run
it!
  • Loading branch information
SquidDev committed Mar 15, 2023
1 parent 986c65f commit 2661829
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 49 deletions.
2 changes: 2 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ dependencies {
implementation(libs.kotlin.plugin)
implementation(libs.spotless)

implementation(libs.curseForgeGradle)
implementation(libs.fabric.loom)
implementation(libs.forgeGradle)
implementation(libs.librarian)
implementation(libs.minotaur)
implementation(libs.quiltflower)
implementation(libs.vanillaGradle)
}
Expand Down
59 changes: 59 additions & 0 deletions buildSrc/src/main/kotlin/cc-tweaked.mod-publishing.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SPDX-FileCopyrightText: 2023 The CC: Tweaked Developers
//
// SPDX-License-Identifier: MPL-2.0

import net.darkhax.curseforgegradle.TaskPublishCurseForge
import cc.tweaked.gradle.setProvider

plugins {
id("net.darkhax.curseforgegradle")
id("com.modrinth.minotaur")
id("cc-tweaked.publishing")
}

abstract class ModPublishingExtension {
abstract val output: Property<AbstractArchiveTask>

init {
output.finalizeValueOnRead()
}
}

val modPublishing = project.extensions.create("modPublishing", ModPublishingExtension::class.java)

val isUnstable = project.properties["isUnstable"] == "true"
val modVersion: String by extra
val mcVersion: String by extra

val publishCurseForge by tasks.registering(TaskPublishCurseForge::class) {
group = PublishingPlugin.PUBLISH_TASK_GROUP
description = "Upload artifacts to CurseForge"

apiToken = findProperty("curseForgeApiKey") ?: ""
enabled = apiToken != ""

val mainFile = upload("282001", modPublishing.output.get().archiveFile)
dependsOn(modPublishing.output) // See https://github.com/Darkhax/CurseForgeGradle/pull/7.
mainFile.changelog =
"Release notes can be found on the [GitHub repository](https://github.com/cc-tweaked/CC-Tweaked/releases/tag/v$mcVersion-$modVersion)."
mainFile.changelogType = "markdown"
mainFile.releaseType = if (isUnstable) "alpha" else "release"
mainFile.gameVersions.add(mcVersion)
}

tasks.publish { dependsOn(publishCurseForge) }

modrinth {
token.set(findProperty("modrinthApiKey") as String? ?: "")
projectId.set("gu7yAYhd")
versionNumber.set("$mcVersion-$modVersion")
versionName.set(modVersion)
versionType.set(if (isUnstable) "alpha" else "release")
uploadFile.setProvider(modPublishing.output)
gameVersions.add(mcVersion)
changelog.set("Release notes can be found on the [GitHub repository](https://github.com/cc-tweaked/CC-Tweaked/releases/tag/v$mcVersion-$modVersion).")

syncBodyFrom.set(provider { file("doc/mod-page.md").readText() })
}

tasks.publish { dependsOn(tasks.modrinth) }
5 changes: 5 additions & 0 deletions buildSrc/src/main/kotlin/cc/tweaked/gradle/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package cc.tweaked.gradle

import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.JavaExec
import org.gradle.process.BaseExecSpec
import org.gradle.process.JavaExecSpec
Expand Down Expand Up @@ -119,3 +121,6 @@ class CloseScope : AutoCloseable {
}
}
}

/** Proxy method to avoid overload ambiguity. */
fun <T> Property<T>.setProvider(provider: Provider<out T>) = set(provider)
2 changes: 0 additions & 2 deletions doc/mod-page.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ SPDX-License-Identifier: MPL-2.0
# ![CC: Tweaked](https://tweaked.cc/logo.png)
CC: Tweaked is a mod for Minecraft which adds programmable computers, turtles and more to the game. A fork of the much-beloved [ComputerCraft], it continues its legacy with better performance, stability, and a wealth of new features.

**Fabric support is added by the [CC: Restitched][ccrestitched] project**

## Testimonials

> I'm not sure what that is [...] I don't know where that came from.
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ slf4j-simple = { module = "org.slf4j:slf4j-simple", version.ref = "slf4j" }
# Build tools
cctJavadoc = { module = "cc.tweaked:cct-javadoc", version.ref = "cctJavadoc" }
checkstyle = { module = "com.puppycrawl.tools:checkstyle", version.ref = "checkstyle" }
curseForgeGradle = { module = "net.darkhax.curseforgegradle:CurseForgeGradle", version.ref = "curseForgeGradle" }
errorProne-annotations = { module = "com.google.errorprone:error_prone_annotations", version.ref = "errorProne-core" }
errorProne-api = { module = "com.google.errorprone:error_prone_check_api", version.ref = "errorProne-core" }
errorProne-core = { module = "com.google.errorprone:error_prone_core", version.ref = "errorProne-core" }
Expand All @@ -124,19 +125,18 @@ fabric-loom = { module = "net.fabricmc:fabric-loom", version.ref = "fabric-loom"
forgeGradle = { module = "net.minecraftforge.gradle:ForgeGradle", version.ref = "forgeGradle" }
kotlin-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
librarian = { module = "org.parchmentmc:librarian", version.ref = "librarian" }
minotaur = { module = "com.modrinth.minotaur:Minotaur", version.ref = "minotaur" }
nullAway = { module = "com.uber.nullaway:nullaway", version.ref = "nullAway" }
quiltflower = { module = "io.github.juuxel:loom-quiltflower", version.ref = "quiltflower" }
spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version.ref = "spotless" }
vanillaGradle = { module = "org.spongepowered:vanillagradle", version.ref = "vanillaGradle" }

[plugins]
curseForgeGradle = { id = "net.darkhax.curseforgegradle", version.ref = "curseForgeGradle" }
forgeGradle = { id = "net.minecraftforge.gradle", version.ref = "forgeGradle" }
githubRelease = { id = "com.github.breadmoirai.github-release", version.ref = "githubRelease" }
ideaExt = { id = "org.jetbrains.gradle.plugin.idea-ext", version.ref = "ideaExt" }
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
librarian = { id = "org.parchmentmc.librarian.forgegradle", version.ref = "librarian" }
minotaur = { id = "com.modrinth.minotaur", version.ref = "minotaur" }
mixinGradle = { id = "org.spongepowered.mixin", version.ref = "mixinGradle" }
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }
taskTree = { id = "com.dorongold.task-tree", version.ref = "taskTree" }
Expand Down
2 changes: 0 additions & 2 deletions projects/fabric-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ plugins {
id("cc-tweaked.publishing")
}

val mcVersion: String by extra

java {
withJavadocJar()
}
Expand Down
7 changes: 5 additions & 2 deletions projects/fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import java.util.*
plugins {
id("cc-tweaked.fabric")
id("cc-tweaked.gametest")
id("cc-tweaked.publishing")
id("cc-tweaked.mod-publishing")
}

val modVersion: String by extra
val mcVersion: String by extra

val allProjects = listOf(":core-api", ":core", ":fabric-api").map { evaluationDependsOn(it) }
cct {
Expand Down Expand Up @@ -231,6 +230,10 @@ tasks.register("checkClient") {
dependsOn(runGametestClient, runGametestClientWithSodium, runGametestClientWithIris)
}

modPublishing {
output.set(tasks.remapJar)
}

tasks.withType(GenerateModuleMetadata::class).configureEach { isEnabled = false }
publishing {
publications {
Expand Down
44 changes: 3 additions & 41 deletions projects/forge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,18 @@
// SPDX-License-Identifier: MPL-2.0

import cc.tweaked.gradle.*
import net.darkhax.curseforgegradle.TaskPublishCurseForge
import net.minecraftforge.gradle.common.util.RunConfig

plugins {
// Build
id("cc-tweaked.forge")
id("cc-tweaked.gametest")
alias(libs.plugins.mixinGradle)
alias(libs.plugins.shadow)
// Publishing
alias(libs.plugins.curseForgeGradle)
alias(libs.plugins.minotaur)

id("cc-tweaked.illuaminate")
id("cc-tweaked.publishing")
id("cc-tweaked")
id("cc-tweaked.mod-publishing")
}

val isUnstable = project.properties["isUnstable"] == "true"
val modVersion: String by extra
val mcVersion: String by extra

val allProjects = listOf(":core-api", ":core", ":forge-api").map { evaluationDependsOn(it) }
cct {
Expand Down Expand Up @@ -293,39 +284,10 @@ tasks.register("checkClient") {

// Upload tasks

val publishCurseForge by tasks.registering(TaskPublishCurseForge::class) {
group = PublishingPlugin.PUBLISH_TASK_GROUP
description = "Upload artifacts to CurseForge"

apiToken = findProperty("curseForgeApiKey") ?: ""
enabled = apiToken != ""

val mainFile = upload("282001", tasks.shadowJar.get().archiveFile)
dependsOn(tasks.shadowJar) // Ughr.
mainFile.changelog =
"Release notes can be found on the [GitHub repository](https://github.com/cc-tweaked/CC-Tweaked/releases/tag/v$mcVersion-$modVersion)."
mainFile.changelogType = "markdown"
mainFile.releaseType = if (isUnstable) "alpha" else "release"
mainFile.gameVersions.add(mcVersion)
}

tasks.publish { dependsOn(publishCurseForge) }

modrinth {
token.set(findProperty("modrinthApiKey") as String? ?: "")
projectId.set("gu7yAYhd")
versionNumber.set("$mcVersion-$modVersion")
versionName.set(modVersion)
versionType.set(if (isUnstable) "alpha" else "release")
uploadFile.set(tasks.shadowJar as Any)
gameVersions.add(mcVersion)
changelog.set("Release notes can be found on the [GitHub repository](https://github.com/cc-tweaked/CC-Tweaked/releases/tag/v$mcVersion-$modVersion).")

syncBodyFrom.set(provider { file("doc/mod-page.md").readText() })
modPublishing {
output.set(tasks.shadowJar)
}

tasks.publish { dependsOn(tasks.modrinth) }

// Don't publish the slim jar
for (cfg in listOf(configurations.apiElements, configurations.runtimeElements)) {
cfg.configure { artifacts.removeIf { it.classifier == "slim" } }
Expand Down

0 comments on commit 2661829

Please sign in to comment.