Skip to content

Commit 0f94f51

Browse files
authored
Fix changelog race in Modrinth/CurseForge (#32)
1 parent 72e066d commit 0f94f51

File tree

1 file changed

+41
-36
lines changed

1 file changed

+41
-36
lines changed

build.gradle

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ plugins {
2323
id 'maven-publish'
2424
id 'org.jetbrains.gradle.plugin.idea-ext' version '1.1.7'
2525
id 'com.gtnewhorizons.retrofuturagradle' version '1.3.19'
26-
id 'net.darkhax.curseforgegradle' version '1.0.7' apply false
26+
id 'net.darkhax.curseforgegradle' version '1.0.14' apply false
2727
id 'com.modrinth.minotaur' version '2.8.0' apply false
2828
id 'com.diffplug.spotless' version '6.13.0' apply false
2929
id 'com.palantir.git-version' version '3.0.0' apply false
@@ -712,7 +712,8 @@ idea {
712712

713713

714714
// Deployment
715-
715+
def final modrinthApiKey = providers.environmentVariable('MODRINTH_API_KEY')
716+
def final cfApiKey = providers.environmentVariable('CURSEFORGE_API_KEY')
716717
final boolean isCIEnv = providers.environmentVariable('CI').getOrElse('false').toBoolean()
717718

718719
if (isCIEnv || deploymentDebug.toBoolean()) {
@@ -749,58 +750,62 @@ tasks.register('generateChangelog') {
749750
changelog = "Changes since ${lastTag}:\n${{("\n" + changelog).replaceAll("\n", "\n* ")}}"
750751
}
751752
def f = getFile('build/changelog.md')
752-
f.write(changelog ?: 'There have been no changes.', 'UTF-8')
753+
changelog = changelog ?: 'There have been no changes.'
754+
f.write(changelog, 'UTF-8')
755+
756+
// Set changelog for Modrinth
757+
if (modrinthApiKey.isPresent() || deploymentDebug.toBoolean()) {
758+
modrinth.changelog.set(changelog)
759+
}
753760
}
754761
}
755762

756-
// Curseforge
757-
def final cfApiKey = providers.environmentVariable('CURSEFORGE_API_KEY')
758763
if (cfApiKey.isPresent() || deploymentDebug.toBoolean()) {
759764
apply plugin: 'net.darkhax.curseforgegradle'
760765
//noinspection UnnecessaryQualifiedReference
761766
tasks.register('curseforge', net.darkhax.curseforgegradle.TaskPublishCurseForge) {
767+
disableVersionDetection()
768+
debugMode = deploymentDebug.toBoolean()
762769
apiToken = cfApiKey.getOrElse('debug_token')
763770

764-
def mainFile = upload(curseForgeProjectId, reobfJar)
765-
def changelogFile = getChangelog()
766-
def changelogRaw = changelogFile.exists() ? changelogFile.getText('UTF-8') : ""
767-
768-
mainFile.displayName = "${modName}: ${modVersion}"
769-
mainFile.releaseType = getReleaseType()
770-
mainFile.changelog = changelogRaw
771-
mainFile.changelogType = 'markdown'
772-
mainFile.addModLoader 'Forge'
773-
mainFile.addJavaVersion "Java 8"
774-
mainFile.addGameVersion minecraftVersion
775-
776-
if (curseForgeRelations.size() != 0) {
777-
String[] deps = curseForgeRelations.split(';')
778-
deps.each { dep ->
779-
if (dep.size() == 0) {
780-
return
781-
}
782-
String[] parts = dep.split(':')
783-
String type = parts[0], slug = parts[1]
784-
if(!(type in ['requiredDependency', 'embeddedLibrary', 'optionalDependency', 'tool', 'incompatible'])) {
785-
throw new Exception('Invalid Curseforge dependency type: ' + type)
771+
doFirst {
772+
def mainFile = upload(curseForgeProjectId, reobfJar)
773+
def changelogFile = getChangelog()
774+
def changelogRaw = changelogFile.exists() ? changelogFile.getText('UTF-8') : ""
775+
776+
mainFile.displayName = "${modName}: ${modVersion}"
777+
mainFile.releaseType = getReleaseType()
778+
mainFile.changelog = changelogRaw
779+
mainFile.changelogType = 'markdown'
780+
mainFile.addModLoader 'Forge'
781+
mainFile.addJavaVersion "Java 8"
782+
mainFile.addGameVersion minecraftVersion
783+
784+
if (curseForgeRelations.size() != 0) {
785+
String[] deps = curseForgeRelations.split(';')
786+
deps.each { dep ->
787+
if (dep.size() == 0) {
788+
return
789+
}
790+
String[] parts = dep.split(':')
791+
String type = parts[0], slug = parts[1]
792+
if (!(type in ['requiredDependency', 'embeddedLibrary', 'optionalDependency', 'tool', 'incompatible'])) {
793+
throw new Exception('Invalid Curseforge dependency type: ' + type)
794+
}
795+
mainFile.addRelation(slug, type)
786796
}
787-
mainFile.addRelation(slug, type)
788797
}
789-
}
790798

791-
for (artifact in getSecondaryArtifacts()) {
792-
def additionalFile = mainFile.withAdditionalFile(artifact)
793-
additionalFile.changelog = changelogRaw
799+
for (artifact in getSecondaryArtifacts()) {
800+
def additionalFile = mainFile.withAdditionalFile(artifact)
801+
additionalFile.changelog = changelogRaw
802+
}
794803
}
795-
disableVersionDetection()
796-
debugMode = deploymentDebug.toBoolean()
797804
}
798805
tasks.curseforge.dependsOn(build)
799806
tasks.curseforge.dependsOn('generateChangelog')
800807
}
801808

802-
// Modrinth
803-
def final modrinthApiKey = providers.environmentVariable('MODRINTH_API_KEY')
804809
if (modrinthApiKey.isPresent() || deploymentDebug.toBoolean()) {
805810
apply plugin: 'com.modrinth.minotaur'
806811
def final changelogFile = getChangelog()

0 commit comments

Comments
 (0)