From 3ea1653663cf56a1905f5d775115b39d240a33c6 Mon Sep 17 00:00:00 2001 From: George Paton Date: Thu, 11 Jun 2026 14:48:59 +1000 Subject: [PATCH 1/3] fix crash when CHANGELOG.md is present at the root of a project. Tested with CF and MR publishing --- .../gtnhgradle/modules/PublishingModule.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/gtnewhorizons/gtnhgradle/modules/PublishingModule.java b/src/main/java/com/gtnewhorizons/gtnhgradle/modules/PublishingModule.java index 4f5a37c0..9ba8eef5 100644 --- a/src/main/java/com/gtnewhorizons/gtnhgradle/modules/PublishingModule.java +++ b/src/main/java/com/gtnewhorizons/gtnhgradle/modules/PublishingModule.java @@ -31,6 +31,7 @@ import java.io.File; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -91,7 +92,7 @@ public void apply(GTNHGradlePlugin.@NotNull GTNHExtension gtnh, @NotNull Project } } - final File changelogFile = new File(ObjectUtils.firstNonNull(System.getenv("CHANGELOG_FILE"), "CHANGELOG.md")); + final String changelog = getChangelog(project); // Modrinth final String mrToken = System.getenv("MODRINTH_TOKEN"); @@ -110,10 +111,9 @@ public void apply(GTNHGradlePlugin.@NotNull GTNHExtension gtnh, @NotNull Project .set(modVersion); mr.getVersionType() .set(modVersion.map(v -> v.endsWith("-pre") ? "beta" : "release")); - if (changelogFile.exists()) { - final String contents = Files.readString(changelogFile.toPath(), StandardCharsets.UTF_8); + if (changelog != null) { mr.getChangelog() - .set(contents); + .set(changelog); } mr.getUploadFile() .set(project.provider(() -> project.property("publishableObfJar"))); @@ -188,9 +188,9 @@ public void apply(GTNHGradlePlugin.@NotNull GTNHExtension gtnh, @NotNull Project task.apiToken = cfToken; task.disableVersionDetection(); task.upload(gtnh.configuration.curseForgeProjectId, obfFile, artifact -> { - if (changelogFile.exists()) { + if (changelog != null) { artifact.changelogType = "markdown"; - artifact.changelog = changelogFile; + artifact.changelog = changelog; } artifact.releaseType = modVersion.map(v -> v.endsWith("-pre") ? "beta" : "release"); artifact.addGameVersion(gtnh.configuration.minecraftVersion, "Forge"); @@ -229,6 +229,19 @@ public void apply(GTNHGradlePlugin.@NotNull GTNHExtension gtnh, @NotNull Project } } + private static String getChangelog(@NotNull Project project) throws Throwable { + String envPath = System.getenv("CHANGELOG_FILE"); + if (envPath != null) { + Path changelogPath = Path.of(envPath); + if (Files.exists(changelogPath)) return Files.readString(changelogPath, StandardCharsets.UTF_8); + } + + Path changelogPath = project.getProjectDir().toPath().resolve("CHANGELOG.md"); + if (Files.exists(changelogPath)) return Files.readString(changelogPath, StandardCharsets.UTF_8); + + return null; + } + private static final Set VALID_MODRINTH_SCOPES = ImmutableSet .of("required", "optional", "incompatible", "embedded"); From 5b8d83851aec887290ce7de0858ce5099643799a Mon Sep 17 00:00:00 2001 From: George Paton Date: Thu, 11 Jun 2026 15:34:28 +1000 Subject: [PATCH 2/3] resolve handles absolute paths for us, and `isRegularFile` should stop issues with dirs being used instead of files --- .../gtnhgradle/modules/PublishingModule.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/gtnewhorizons/gtnhgradle/modules/PublishingModule.java b/src/main/java/com/gtnewhorizons/gtnhgradle/modules/PublishingModule.java index 9ba8eef5..3b0b8675 100644 --- a/src/main/java/com/gtnewhorizons/gtnhgradle/modules/PublishingModule.java +++ b/src/main/java/com/gtnewhorizons/gtnhgradle/modules/PublishingModule.java @@ -230,14 +230,8 @@ public void apply(GTNHGradlePlugin.@NotNull GTNHExtension gtnh, @NotNull Project } private static String getChangelog(@NotNull Project project) throws Throwable { - String envPath = System.getenv("CHANGELOG_FILE"); - if (envPath != null) { - Path changelogPath = Path.of(envPath); - if (Files.exists(changelogPath)) return Files.readString(changelogPath, StandardCharsets.UTF_8); - } - - Path changelogPath = project.getProjectDir().toPath().resolve("CHANGELOG.md"); - if (Files.exists(changelogPath)) return Files.readString(changelogPath, StandardCharsets.UTF_8); + Path changelogPath = project.getProjectDir().toPath().resolve(ObjectUtils.firstNonNull(System.getenv("CHANGELOG_FILE"), "CHANGELOG.md")); + if (Files.isRegularFile(changelogPath)) return Files.readString(changelogPath, StandardCharsets.UTF_8); return null; } From ad23b13abd9e26ea13425d1009183a5161550373 Mon Sep 17 00:00:00 2001 From: George Paton Date: Mon, 15 Jun 2026 10:18:19 +1000 Subject: [PATCH 3/3] run `spotlessApply` (sorry!) --- .../gtnewhorizons/gtnhgradle/modules/PublishingModule.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gtnewhorizons/gtnhgradle/modules/PublishingModule.java b/src/main/java/com/gtnewhorizons/gtnhgradle/modules/PublishingModule.java index 3b0b8675..8a8356d0 100644 --- a/src/main/java/com/gtnewhorizons/gtnhgradle/modules/PublishingModule.java +++ b/src/main/java/com/gtnewhorizons/gtnhgradle/modules/PublishingModule.java @@ -230,7 +230,9 @@ public void apply(GTNHGradlePlugin.@NotNull GTNHExtension gtnh, @NotNull Project } private static String getChangelog(@NotNull Project project) throws Throwable { - Path changelogPath = project.getProjectDir().toPath().resolve(ObjectUtils.firstNonNull(System.getenv("CHANGELOG_FILE"), "CHANGELOG.md")); + Path changelogPath = project.getProjectDir() + .toPath() + .resolve(ObjectUtils.firstNonNull(System.getenv("CHANGELOG_FILE"), "CHANGELOG.md")); if (Files.isRegularFile(changelogPath)) return Files.readString(changelogPath, StandardCharsets.UTF_8); return null;