Skip to content

Commit bfab752

Browse files
committed
Move Compose relnote generator to a gradle task
1 parent e32761b commit bfab752

File tree

2 files changed

+48
-29
lines changed

2 files changed

+48
-29
lines changed

plugins/compose/build.gradle.kts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
plugins {
2+
kotlin("jvm")
3+
}
4+
5+
sourceSets {
6+
"main" { projectDefault() }
7+
}
8+
9+
dependencies {
10+
implementation(project(":kotlin-stdlib"))
11+
}
12+
13+
tasks.register("composeReleaseNotes", JavaExec::class.java) {
14+
classpath(sourceSets.main.map { it.runtimeClasspath })
15+
16+
description = "Generate Compose plugin release notes"
17+
mainClass = "GenerateReleaseNotesKt"
18+
}
19+
20+
description = "Compose compiler plugin"

plugins/compose/generate-release-notes.kts renamed to plugins/compose/src/GenerateReleaseNotes.kt

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
#!/usr/bin/env kotlin
2-
31
/*
42
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
53
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
64
*/
75

6+
import java.lang.System
87
import java.util.concurrent.TimeUnit
98
import kotlin.system.exitProcess
109

11-
fun getCommits(fromRevision: String, toRevision: String, path: String?): List<Commit> {
12-
val cmd = "git rev-list --format=medium $fromRevision..$toRevision ${path ?: "."}"
10+
fun getCommits(fromRevision: String, toRevision: String): List<Commit> {
11+
val cmd = "git rev-list --format=medium $fromRevision..$toRevision ."
1312
val process = ProcessBuilder(*(cmd.split(" ")).toTypedArray())
1413
.redirectOutput(ProcessBuilder.Redirect.PIPE)
1514
.redirectError(ProcessBuilder.Redirect.INHERIT)
@@ -20,7 +19,7 @@ fun getCommits(fromRevision: String, toRevision: String, path: String?): List<Co
2019
return commits.mapNotNull { commit ->
2120
val sanitizedCommit = commit.removePrefix("commit ").padEnd(2, '\n')
2221
val commitGroups = parseCommit.find(sanitizedCommit)?.groupValues ?: return@mapNotNull null
23-
if (commitGroups?.size != 4) {
22+
if (commitGroups.size != 4) {
2423
// group 1: commit hash
2524
// group 2: commit message
2625
// group 3: title
@@ -55,7 +54,6 @@ data class Commit(
5554
)
5655

5756
fun commitToGitHubUrl(commit: String) = "https://github.com/JetBrains/kotlin/commit/$commit"
58-
fun changeIdToGerritUrl(changeId: String) = "https://android-review.googlesource.com/q/$changeId"
5957
fun issueToBuganizerUrl(issue: String): String = "https://issuetracker.google.com/issues/$issue"
6058

6159
fun Commit.asReleaseNote(): String {
@@ -66,33 +64,34 @@ fun Commit.asReleaseNote(): String {
6664
return "- $link $text"
6765
}
6866

69-
if (args.isEmpty()) {
70-
println(
71-
"""
72-
Usage: <from-tag> <to-tag> [<path>]
67+
fun main(vararg args: String) {
68+
if (args.isEmpty()) {
69+
println(
70+
"""
71+
Usage: ./gradlew composeReleaseNotes --args="<from-tag> <to-tag>:"
7372
7473
For example, to generate release notes for v2.0.0-RC2:
75-
<script> v2.0.0-RC1 v2.0.0-RC2
74+
./gradlew composeReleaseNotes --args="v2.0.0-RC1 v2.0.0-RC2"
7675
""".trimIndent()
77-
)
78-
exitProcess(1)
79-
}
76+
)
77+
exitProcess(1)
78+
}
8079

81-
val ignoreRelnotes = listOf("n/a")
80+
val ignoreRelnotes = listOf("n/a")
8281

83-
val fromRevision = args[0]
84-
val toRevision = args[1]
85-
val path = args.getOrNull(2)
82+
val fromRevision = args[0]
83+
val toRevision = args[1]
8684

87-
val (fixes, features) = getCommits(fromRevision, toRevision, path)
88-
.filter {
89-
(it.relnote != null && !ignoreRelnotes.contains(it.relnote.toLowerCase())) ||
90-
it.issues.isNotEmpty()
91-
}
92-
.partition { it.issues.isNotEmpty() }
85+
val (fixes, features) = getCommits(fromRevision, toRevision)
86+
.filter {
87+
(it.relnote != null && !ignoreRelnotes.contains(it.relnote.lowercase())) ||
88+
it.issues.isNotEmpty()
89+
}
90+
.partition { it.issues.isNotEmpty() }
9391

94-
println("### Compose compiler")
95-
println("#### New features")
96-
features.forEach { println(it.asReleaseNote()) }
97-
println("#### Fixes")
98-
fixes.forEach { println(it.asReleaseNote()) }
92+
println("### Compose compiler")
93+
println("#### New features")
94+
features.forEach { println(it.asReleaseNote()) }
95+
println("#### Fixes")
96+
fixes.forEach { println(it.asReleaseNote()) }
97+
}

0 commit comments

Comments
 (0)