Skip to content

Commit

Permalink
ci: allow uploading individual files to CurseForge
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsocha committed Nov 5, 2023
1 parent 3681007 commit 675fb09
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
docker run
--env CURSEFORGE_API_TOKEN=${{ secrets.CURSEFORGE_API_TOKEN }}
luckyblock
./gradlew :tools:uploadToCurseForge
./gradlew :tools:cli --args="upload-to-curseforge ../dist/${releaseName}-${releaseVersion}"
7 changes: 1 addition & 6 deletions tools/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,9 @@ application {
mainClass.set("mod.lucky.tools.MainKt")
}

tasks.register<JavaExec>("uploadToCurseForge") {
tasks.register<JavaExec>("cli") {
classpath = fileTree("$rootDir/tools/build/install/tools/lib")
mainClass.set("mod.lucky.tools.MainKt")
args = listOf(
"upload-to-curseforge",
"--inputDistFolder",
"../dist"
)
dependsOn("installDist")
}

Expand Down
29 changes: 14 additions & 15 deletions tools/src/main/kotlin/uploadToCurseForge/LuckyBlockDist.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,19 @@ data class LuckyBlockDist(
val jarFile: File,
)

fun readLuckyBlockDists(distFolder: File): List<LuckyBlockDist> {
return distFolder.listFiles()!!.mapNotNull { distVersionFolder ->
val loader = when {
distVersionFolder.isDirectory && distVersionFolder.name.startsWith("lucky-block-forge") ->
LuckyBlockLoader.FORGE
distVersionFolder.isDirectory && distVersionFolder.name.startsWith("lucky-block-fabric") ->
LuckyBlockLoader.FABRIC
else -> null
}
if (loader != null) {
val metaText = distVersionFolder.resolve("meta.yaml").readText()
val meta = Yaml.default.decodeFromString<ProjectDistMeta>(metaText)
val jarFile = distVersionFolder.resolve("${distVersionFolder.name}.jar")
LuckyBlockDist(loader=loader, meta=meta, jarFile=jarFile)
} else null
fun readLuckyBlockDist(distFolder: File): LuckyBlockDist {
val distFolderName = distFolder.relativeTo(distFolder.parentFile).name
val loader = when {
distFolder.isDirectory && distFolderName.startsWith("lucky-block-forge") ->
LuckyBlockLoader.FORGE
distFolder.isDirectory && distFolderName.startsWith("lucky-block-fabric") ->
LuckyBlockLoader.FABRIC
else -> throw Exception("Invalid folder name $distFolderName")
}

val metaText = distFolder.resolve("meta.yaml").readText()
val meta = Yaml.default.decodeFromString<ProjectDistMeta>(metaText)
val jarFile = distFolder.resolve("${distFolder.name}.jar")

return LuckyBlockDist(loader=loader, meta=meta, jarFile=jarFile)
}
23 changes: 10 additions & 13 deletions tools/src/main/kotlin/uploadToCurseForge/UploadToCurseForge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import kotlinx.cli.*
import kotlinx.coroutines.runBlocking
import java.io.File
import io.github.cdimascio.dotenv.dotenv
import io.github.g00fy2.versioncompare.Version as ComparableVersion

fun findCompatibleGameVersions(
gameVersions: List<CurseForgeGameVersion>,
Expand Down Expand Up @@ -45,23 +44,21 @@ fun uploadToCurseForge(
curseForgeClient: CurseForgeClient,
inputDistFolder: File
) = runBlocking {
val luckyBlockDists = readLuckyBlockDists(inputDistFolder).sortedBy { ComparableVersion(it.meta.version) }
val luckyBlockDist = readLuckyBlockDist(inputDistFolder)
val gameVersions = curseForgeClient.getGameVersions()

luckyBlockDists.forEach { luckyBlockDist ->
val compatibleGameVersions = findCompatibleGameVersions(gameVersions, luckyBlockDist)
val uploadMeta = CurseForgeUploadMetadata(
changelog = "",
displayName = luckyBlockDist.jarFile.nameWithoutExtension,
gameVersions = compatibleGameVersions.map { it.id },
releaseType = "release",
)
curseForgeClient.uploadDist(luckyBlockDist.jarFile, uploadMeta)
}
val compatibleGameVersions = findCompatibleGameVersions(gameVersions, luckyBlockDist)
val uploadMeta = CurseForgeUploadMetadata(
changelog = "",
displayName = luckyBlockDist.jarFile.nameWithoutExtension,
gameVersions = compatibleGameVersions.map { it.id },
releaseType = "release",
)
curseForgeClient.uploadDist(luckyBlockDist.jarFile, uploadMeta)
}

class UploadToCurseForge: Subcommand("upload-to-curseforge", "Upload mod files to CurseForge") {
val inputDistFolder by option(ArgType.String, description = "Folder containing mod files").default("./dist")
private val inputDistFolder by argument(ArgType.String, description = "Folder containing mod distrubution file")

override fun execute() = runBlocking {
val dotenv = dotenv {
Expand Down

0 comments on commit 675fb09

Please sign in to comment.