Android / Gradle - how to create a new Changelog with just the last release notes (useful for Fabric releases)
/**
* Read the changelog and write in resultFileName the first changelog
*
* TODO: create reusable gradle plugin.
* @param changelogFile
* @param versionIndicator
* @param resultFileName
* @return name of the new changelog, if any error then name of initial changelogFile
*/
task generateLastChangelog() {
description 'Create CHANGELOG-LAST.md with the last changelog reported on CHANGELOG.md'
group = 'Reporting'
def changelogFile = "CHANGELOG.md"
def resultFileName = "CHANGELOG-LAST.md"
def versionIndicator = "##"
def message = ""
def readEnabled = false
def changelogLines = new File(changelogFile).readLines()
for (line in changelogLines) {
if (line.startsWith(versionIndicator)) {
if (readEnabled) {
// second changelog
break
}
readEnabled = true
}
if (readEnabled && !line.isEmpty()) {
message += "$line\n"
}
}
if (message.isEmpty()) {
return changelogFile
} else {
def tempChangelog = new File(resultFileName)
tempChangelog.write message
return resultFileName
}
}