Skip to content

Commit 9479b25

Browse files
committed
Add changelog to github release notes
So we don't have to manually add the release notes to the github release after it is published. I added a custom task to read in the full changelog, and parse out the entry for the latest version. The result is written out to a resources file that I pointed the github release config to. The jreleaser docs don't seem to be 100% clear on whether the changelog is actually what ends up in the release notes, but it would make sense to me, and the text in https://jreleaser.org/guide/latest/reference/release/github.html#_release_notes suggests it.
1 parent cd42c8d commit 9479b25

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

build.gradle

+23-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
1717
import org.gradle.api.tasks.testing.logging.TestLogEvent
1818

19+
import java.util.regex.Pattern
1920

2021
buildscript {
2122
repositories {
@@ -272,6 +273,27 @@ runtime {
272273
tasks["assembleDist"].dependsOn("publish")
273274
tasks["assembleDist"].dependsOn("runtimeZip")
274275

276+
// Generate a changelog that only includes the changes for the latest version
277+
// which Jreleaser will add to the release notes of the github release.
278+
def releaseChangelogFile = project.layout.buildDirectory.file("resources/RELEASE_CHANGELOG.md").get().asFile
279+
tasks.register("createReleaseChangelog") {
280+
dependsOn processResources
281+
282+
doLast {
283+
def changelog = project.file("CHANGELOG.md").text
284+
// Copy the text in between the first two version headers
285+
def matcher = Pattern.compile("^## \\d+\\.\\d+\\.\\d+", Pattern.MULTILINE).matcher(changelog)
286+
def getIndex = {
287+
matcher.find()
288+
return matcher.start()
289+
}
290+
def result = changelog.substring(getIndex(), getIndex()).trim()
291+
releaseChangelogFile.write(result)
292+
}
293+
}
294+
295+
tasks.jreleaserRelease.dependsOn(tasks.createReleaseChangelog)
296+
275297
jreleaser {
276298
dryrun = false
277299

@@ -290,7 +312,7 @@ jreleaser {
290312
tagName = '{{projectVersion}}'
291313
releaseName = 'Smithy Language Server v{{{projectVersion}}}'
292314
changelog {
293-
enabled = false
315+
external = releaseChangelogFile.absolutePath
294316
}
295317
commitAuthor {
296318
name = "smithy-automation"

0 commit comments

Comments
 (0)