Skip to content

Commit df6c892

Browse files
committed
Update changelog code for configuration cache
1 parent 2f40181 commit df6c892

File tree

2 files changed

+72
-17
lines changed

2 files changed

+72
-17
lines changed

Changelog/build.gradle.kts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,41 @@ import se.bjurr.gitchangelog.plugin.gradle.GitChangelogTask
22

33
plugins {
44
// https://plugins.gradle.org/plugin/se.bjurr.gitchangelog.git-changelog-gradle-plugin
5-
id("se.bjurr.gitchangelog.git-changelog-gradle-plugin") version("2.1.2")
5+
id("se.bjurr.gitchangelog.git-changelog-gradle-plugin") version("3.0.6")
66
}
77

88
// gradle.properties
99
val specificationVersion: String by extra
1010
val changelogUntaggedName = "Current release $specificationVersion"
1111

1212
tasks.register<GitChangelogTask>("makeChangelog") {
13-
fromRepo = projectDir.absolutePath.toString()
14-
file = file("changelog.html")
15-
untaggedName = changelogUntaggedName
16-
fromRevision = "HEAD~30"
17-
toRevision = "HEAD"
18-
templateContent = file("changelog.mustache").readText()
13+
val output = layout.buildDirectory.file("changelog.html")
14+
15+
fromRepo.set(project.rootProject.rootDir.absolutePath)
16+
file.set(output.get().asFile)
17+
untaggedName.set(changelogUntaggedName)
18+
fromRevision.set("HEAD~30")
19+
toRevision.set("HEAD")
20+
templateContent.set(file("changelog.mustache").readText())
21+
22+
// Register output for configuration cache
23+
outputs.file(output)
1924
}
2025

2126
tasks.register<GitChangelogTask>("makeMarkdownChangelog") {
22-
fromRepo = projectDir.absolutePath.toString()
23-
file = file("changelog.md")
24-
untaggedName = changelogUntaggedName
25-
fromRevision = System.getenv("GIT_PREVIOUS_SUCCESSFUL_COMMIT") ?: "HEAD~10"
26-
toRevision = "HEAD"
27-
templateContent = file("changelog-markdown.mustache").readText()
27+
val output = layout.buildDirectory.file("changelog.md")
28+
29+
fromRepo.set(project.rootProject.rootDir.absolutePath)
30+
file.set(output.get().asFile)
31+
untaggedName.set(changelogUntaggedName)
32+
fromRevision.set(System.getenv("GIT_PREVIOUS_SUCCESSFUL_COMMIT") ?: "HEAD~10")
33+
toRevision.set("HEAD")
34+
templateContent.set(file("changelog-markdown.mustache").readText())
35+
36+
// Register output for configuration cache
37+
outputs.file(output)
2838
}
2939

3040
tasks.withType<GitChangelogTask> {
31-
notCompatibleWithConfigurationCache("invocation of 'Task.project' at execution time is unsupported")
41+
outputs.upToDateWhen { false } // Always run
3242
}

NeoForge/build.gradle.kts

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import me.modmuss50.mpp.PublishModTask
2+
import me.modmuss50.mpp.platforms.curseforge.Curseforge
23
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
34
import org.gradle.api.tasks.testing.logging.TestLogEvent
45
import org.slf4j.event.Level
@@ -149,6 +150,47 @@ val sourcesJarTask = tasks.named<Jar>("sourcesJar") {
149150
archiveClassifier.set("sources")
150151
}
151152

153+
154+
abstract class ReadChangelog : DefaultTask() {
155+
@get:InputFile
156+
abstract val inputFile: RegularFileProperty
157+
158+
@get:OutputFile
159+
abstract val outputFile: RegularFileProperty
160+
161+
@TaskAction
162+
fun read() {
163+
val text = inputFile.get().asFile.readText()
164+
outputFile.get().asFile.writeText(text)
165+
}
166+
}
167+
168+
val changelogHtmlFile: Provider<RegularFile> =
169+
project(":Changelog").layout.buildDirectory.file("changelog.html")
170+
171+
val changelogHtmlTask = tasks.register<ReadChangelog>("readChangelogHtml") {
172+
dependsOn(":Changelog:makeChangelog")
173+
inputFile.set(changelogHtmlFile)
174+
outputFile.set(layout.buildDirectory.file("intermediates/changelog.html"))
175+
}
176+
177+
val changelogHtmlContent: Provider<String> = changelogHtmlTask.flatMap {
178+
it.outputFile.map { f -> f.asFile.readText() }
179+
}
180+
181+
val changelogMdFile: Provider<RegularFile> =
182+
project(":Changelog").layout.buildDirectory.file("changelog.md")
183+
184+
val changelogMdTask = tasks.register<ReadChangelog>("readChangelogMd") {
185+
dependsOn(":Changelog:makeMarkdownChangelog")
186+
inputFile.set(changelogMdFile)
187+
outputFile.set(layout.buildDirectory.file("intermediates/changelog.md"))
188+
}
189+
190+
val changelogMdContent: Provider<String> = changelogMdTask.flatMap {
191+
it.outputFile.map { f -> f.asFile.readText() }
192+
}
193+
152194
publishMods {
153195
file.set(tasks.jar.get().archiveFile)
154196
type = BETA
@@ -159,7 +201,7 @@ publishMods {
159201
curseforge {
160202
projectId = curseProjectId
161203
accessToken.set(curseforgeApikey ?: "0")
162-
changelog.set(provider { file("../Changelog/changelog.html").readText() })
204+
changelog.set(changelogHtmlContent)
163205
changelogType = "html"
164206
minecraftVersionRange {
165207
start = minecraftVersionRangeStart
@@ -171,15 +213,18 @@ publishMods {
171213
modrinth {
172214
projectId = modrinthId
173215
accessToken = modrinthToken
174-
changelog.set(provider { file("../Changelog/changelog.md").readText() })
216+
changelog.set(changelogMdContent)
175217
minecraftVersionRange {
176218
start = minecraftVersionRangeStart
177219
end = minecraftVersion
178220
}
179221
}
222+
223+
dryRun = true
180224
}
225+
181226
tasks.withType<PublishModTask> {
182-
dependsOn(tasks.jar, ":Changelog:makeChangelog", ":Changelog:makeMarkdownChangelog")
227+
dependsOn(tasks.jar, changelogHtmlTask, changelogMdTask)
183228
}
184229

185230
tasks.named<Test>("test") {

0 commit comments

Comments
 (0)