Move changelog task to standalone file
This commit is contained in:
parent
01978548c6
commit
51e5652475
2 changed files with 42 additions and 34 deletions
|
@ -0,0 +1,39 @@
|
||||||
|
package com.wbrawner.releasehelper
|
||||||
|
|
||||||
|
import org.gradle.api.DefaultTask
|
||||||
|
import org.gradle.api.file.RegularFileProperty
|
||||||
|
import org.gradle.api.model.ObjectFactory
|
||||||
|
import org.gradle.api.tasks.OutputFile
|
||||||
|
import org.gradle.api.tasks.TaskAction
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val CHANGELOG_PATH = "src/play/play/release-notes/en-US/default.txt"
|
||||||
|
|
||||||
|
abstract class ChangelogTask @Inject constructor(objectFactory: ObjectFactory) : DefaultTask() {
|
||||||
|
@get:OutputFile
|
||||||
|
val changelogFile: RegularFileProperty = objectFactory.fileProperty()
|
||||||
|
|
||||||
|
init {
|
||||||
|
changelogFile.set(project.layout.projectDirectory.file(CHANGELOG_PATH))
|
||||||
|
}
|
||||||
|
|
||||||
|
@TaskAction
|
||||||
|
fun execute() {
|
||||||
|
val latestTag = "git describe --tags --abbrev=0".execute()
|
||||||
|
val changelog = "git log --format=\"%B\" ${latestTag.first().trim()}..".execute()
|
||||||
|
logger.info("Latest tag: $latestTag")
|
||||||
|
logger.info("Changelog: ${changelog.joinToString("\n")}")
|
||||||
|
changelogFile.get().asFile.writer().use { writer ->
|
||||||
|
writer.write(
|
||||||
|
changelog.joinToString("\n") { it.trim('"') }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun String.execute(): List<String> = ProcessBuilder()
|
||||||
|
.command(this.split(" "))
|
||||||
|
.redirectOutput(ProcessBuilder.Redirect.PIPE)
|
||||||
|
.start()
|
||||||
|
.inputReader()
|
||||||
|
.readLines()
|
||||||
|
}
|
|
@ -2,46 +2,15 @@ package com.wbrawner.releasehelper
|
||||||
|
|
||||||
import org.gradle.api.Plugin
|
import org.gradle.api.Plugin
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.tasks.Exec
|
|
||||||
import org.gradle.kotlin.dsl.extra
|
import org.gradle.kotlin.dsl.extra
|
||||||
import org.gradle.kotlin.dsl.provideDelegate
|
import org.gradle.kotlin.dsl.provideDelegate
|
||||||
import java.io.ByteArrayOutputStream
|
import org.gradle.kotlin.dsl.register
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
|
|
||||||
class ReleaseHelperPlugin : Plugin<Project> {
|
class ReleaseHelperPlugin : Plugin<Project> {
|
||||||
override fun apply(target: Project) {
|
override fun apply(target: Project) {
|
||||||
target.tasks.register("getLatestTag", Exec::class.java) {
|
target.tasks.register<ChangelogTask>("changelog")
|
||||||
val latestTag = ByteArrayOutputStream()
|
|
||||||
standardOutput = latestTag
|
|
||||||
commandLine("git describe --tags --abbrev=0".split(" "))
|
|
||||||
doLast {
|
|
||||||
target.project.extra["latestTag"] = latestTag.toString().trim()
|
|
||||||
logger.info("Latest tag: ${target.project.extra["latestTag"]}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
target.tasks.register("changelog") {
|
|
||||||
val changelogFile = File(target.projectDir, "src/play/play/release-notes/en-US/default.txt")
|
|
||||||
inputs.property("tag", target.provider {
|
|
||||||
target.project.extra["latestTag"]
|
|
||||||
})
|
|
||||||
outputs.file(changelogFile)
|
|
||||||
dependsOn("getLatestTag")
|
|
||||||
doLast {
|
|
||||||
val latestTag: String by target.project.extra
|
|
||||||
val changelog = ByteArrayOutputStream()
|
|
||||||
target.exec {
|
|
||||||
standardOutput = changelog
|
|
||||||
commandLine = "git log --format=\"%B\" ${latestTag.trim()}..".split(" ")
|
|
||||||
}
|
|
||||||
changelogFile.writeText(
|
|
||||||
changelog.toString()
|
|
||||||
.split("\n")
|
|
||||||
.mapNotNull { it.trim('"').ifBlank { null } }
|
|
||||||
.joinToString("\n") { "- $it" }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
target.tasks.register("majorRelease") {
|
target.tasks.register("majorRelease") {
|
||||||
dependsOn("changelog", "getLatestTag")
|
dependsOn("changelog", "getLatestTag")
|
||||||
|
|
Loading…
Reference in a new issue