Skip to content

Commit 9bfc8dd

Browse files
committedJul 19, 2021
Add auto-updating of CHANGELOG and update it
Fixes #253
1 parent e5987c6 commit 9bfc8dd

File tree

9 files changed

+502
-77
lines changed

9 files changed

+502
-77
lines changed
 

‎CHANGELOG.md

+406-54
Large diffs are not rendered by default.

‎build.gradle.kts

+9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ plugins {
1616
id("org.jetbrains.kotlinx.jupyter.dependencies")
1717
id("ru.ileasile.kotlin.publisher")
1818
id("ru.ileasile.kotlin.doc")
19+
id("org.hildan.github.changelog")
1920
}
2021

2122
extra["isMainProject"] = true
@@ -28,6 +29,8 @@ val slf4jVersion: String by project
2829
val logbackVersion: String by project
2930

3031
val docsRepo: String by project
32+
val githubRepoUser: String by project
33+
val githubRepoName: String by project
3134

3235
val taskOptions = project.options()
3336
val deploy: Configuration by configurations.creating
@@ -231,6 +234,12 @@ tasks.publishDocs {
231234
email.set("robot@jetbrains.com")
232235
}
233236

237+
changelog {
238+
githubUser = githubRepoUser
239+
githubRepository = githubRepoName
240+
excludeLabels = listOf("wontfix", "duplicate", "no-changelog", "question")
241+
}
242+
234243
kotlinPublications {
235244
packageGroup = "org.jetbrains.kotlinx"
236245

‎gradle.properties

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ stableKotlinLanguageLevel=1.5
77
jvmTarget=1.8
88

99
shadowJarVersion=7.0.0
10+
changelogPluginVersion=1.7.0
1011
kotlinxSerializationVersion=1.1.0
1112
ktlintGradleVersion=10.0.0
1213
ktlintVersion=0.40.0
@@ -19,6 +20,8 @@ artifactsPath=build/artifacts
1920

2021
baseVersion=0.10.0
2122

23+
githubRepoUser=Kotlin
24+
githubRepoName=kotlin-jupyter
2225
projectRepoUrl=https://github.com/Kotlin/kotlin-jupyter
2326
docsRepo=git@github.com:ileasile/kotlin-jupyter-docs.git
2427
pushRepoUrl=git@github.com:Kotlin/kotlin-jupyter.git

‎kotlin-jupyter-plugin/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ plugins {
22
id("org.jlleitschuh.gradle.ktlint")
33
`java-gradle-plugin`
44
`kotlin-dsl`
5+
kotlin("plugin.serialization")
56
}
67

78
repositories {

‎kotlin-jupyter-plugin/settings.gradle.kts

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pluginManagement {
2525

2626
val ktlintGradleVersion = rootProperties["ktlintGradleVersion"] as String
2727
val publishPluginVersion = rootProperties["publishPluginVersion"] as String
28+
val stableKotlinVersion = rootProperties["stableKotlinVersion"] as String
2829

2930
repositories {
3031
gradlePluginPortal()
@@ -39,6 +40,7 @@ pluginManagement {
3940
}
4041

4142
plugins {
43+
kotlin("plugin.serialization") version stableKotlinVersion
4244
id("org.jlleitschuh.gradle.ktlint") version ktlintGradleVersion
4345
id("ru.ileasile.kotlin.publisher") version publishPluginVersion
4446
}

‎kotlin-jupyter-plugin/src/main/kotlin/org/jetbrains/kotlinx/jupyter/build/util.kt

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ fun writeJson(json: Map<String, Any>, path: Path) {
2525

2626
fun Path.deleteDir() = toFile().deleteRecursively()
2727

28+
fun <T> Project.prop(name: String): T {
29+
@Suppress("UNCHECKED_CAST")
30+
return property(name) as T
31+
}
32+
2833
fun Project.stringPropOrEmpty(name: String) = rootProject.findProperty(name) as String? ?: ""
2934

3035
interface AllOptions : BuildOptions, InstallOptions, DistribOptions

‎kotlin-jupyter-plugin/src/main/kotlin/org/jetbrains/kotlinx/jupyter/build/versionUpdating.kt

+74-22
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,50 @@
11
package org.jetbrains.kotlinx.jupyter.build
22

3+
import kotlinx.serialization.Serializable
34
import kotlinx.serialization.json.Json
45
import kotlinx.serialization.json.JsonArray
6+
import kotlinx.serialization.json.JsonElement
57
import kotlinx.serialization.json.JsonObject
68
import kotlinx.serialization.json.JsonPrimitive
79
import kotlinx.serialization.json.encodeToJsonElement
10+
import kotlinx.serialization.json.int
11+
import org.gradle.api.Project
812
import org.gradle.process.ExecResult
913
import org.gradle.process.ExecSpec
1014
import org.gradle.tooling.BuildException
11-
import java.io.File
12-
import java.io.OutputStream
1315
import org.http4k.core.Method
1416
import org.http4k.core.Request
15-
import org.jetbrains.kotlinx.jupyter.common.jsonObject
17+
import org.http4k.core.Response
18+
import org.jetbrains.kotlinx.jupyter.common.ResponseWrapper
1619
import org.jetbrains.kotlinx.jupyter.common.httpRequest
20+
import org.jetbrains.kotlinx.jupyter.common.jsonObject
1721
import org.jetbrains.kotlinx.jupyter.common.text
1822
import org.jetbrains.kotlinx.jupyter.common.withBasicAuth
1923
import org.jetbrains.kotlinx.jupyter.common.withJson
24+
import java.io.File
25+
import java.io.OutputStream
26+
27+
private val Project.libName get() = prop<String>("jupyter.lib.name")
28+
private val Project.libParamName get() = prop<String>("jupyter.lib.param.name")
29+
private val Project.libParamValue get() = prop<String>("jupyter.lib.param.value")
30+
31+
private val Project.prGithubUser get() = prop<String>("jupyter.github.user")
32+
private val Project.prGithubToken get() = prop<String>("jupyter.github.token")
33+
34+
private val Project.githubRepoOwner get() = prop<String>("githubRepoUser")
35+
private val Project.githubRepoName get() = prop<String>("githubRepoName")
36+
37+
@Serializable
38+
class NewPrData(
39+
val title: String,
40+
val head: String,
41+
val base: String,
42+
)
43+
44+
@Serializable
45+
class SetLabelsData(
46+
val labels: List<String>,
47+
)
2048

2149
fun ProjectWithInstallOptions.prepareKotlinVersionUpdateTasks() {
2250
tasks.register("updateKotlinVersion") {
@@ -49,9 +77,9 @@ fun ProjectWithInstallOptions.prepareKotlinVersionUpdateTasks() {
4977

5078
val updateLibraryParamTask = tasks.register("updateLibraryParam") {
5179
doLast {
52-
val libName = project.property("jupyter.lib.name") as String
53-
val paramName = project.property("jupyter.lib.param.name") as String
54-
val paramValue = project.property("jupyter.lib.param.value") as String
80+
val libName = project.libName
81+
val paramName = project.libParamName
82+
val paramValue = project.libParamValue
5583

5684
updateLibBranchName = "update-$libName-$paramName-$paramValue"
5785
updateLibraryParam(libName, paramName, paramValue)
@@ -79,8 +107,8 @@ fun ProjectWithInstallOptions.prepareKotlinVersionUpdateTasks() {
79107
execGit("commit", "-m", "[AUTO] Update library version")
80108

81109
val repoUrl = rootProject.property("pushRepoUrl") as String
82-
execGit("push", "--force", "-u", repoUrl, getCurrentBranch() + ":" + updateLibBranchName!!) {
83-
this.standardOutput = object: OutputStream() {
110+
execGit("push", "--force", "-u", repoUrl, getCurrentBranch() + ":refs/heads/" + updateLibBranchName!!) {
111+
this.standardOutput = object : OutputStream() {
84112
override fun write(b: Int) { }
85113
}
86114
}
@@ -93,24 +121,48 @@ fun ProjectWithInstallOptions.prepareKotlinVersionUpdateTasks() {
93121
dependsOn(pushChangesTask)
94122

95123
doLast {
96-
val user = rootProject.property("jupyter.github.user") as String
97-
val password = rootProject.property("jupyter.github.token") as String
98-
fun githubRequest(method: Method, request: String, json: Map<String, String>? = null): Int {
99-
val response = httpRequest(Request(method, "https://api.github.com/$request")
100-
.withJson(Json.encodeToJsonElement(json))
101-
.withBasicAuth(user, password)
124+
val user = rootProject.prGithubUser
125+
val password = rootProject.prGithubToken
126+
fun githubRequest(
127+
method: Method,
128+
request: String,
129+
json: JsonElement,
130+
onFailure: (Response) -> Unit,
131+
): ResponseWrapper {
132+
val response = httpRequest(
133+
Request(method, "https://api.github.com/$request")
134+
.withJson(json)
135+
.withBasicAuth(user, password)
102136
)
103137
println(response.text)
104-
return response.status.code
138+
if (!response.status.successful) {
139+
onFailure(response)
140+
}
141+
return response
105142
}
106143

107-
val code = githubRequest(Method.POST, "repos/Kotlin/kotlin-jupyter/pulls", mapOf(
108-
"title" to "Update library versions",
109-
"head" to updateLibBranchName!!,
110-
"base" to "master"
111-
))
112-
if(code != 200 && code != 201) {
113-
throw BuildException("Creating PR failed with code $code", null)
144+
val fullRepo = "${rootProject.githubRepoOwner}/${rootProject.githubRepoName}"
145+
val prResponse = githubRequest(
146+
Method.POST, "repos/$fullRepo/pulls",
147+
Json.encodeToJsonElement(
148+
NewPrData(
149+
title = "Update `${rootProject.libName}` library to `${rootProject.libParamValue}`",
150+
head = updateLibBranchName!!,
151+
base = "master"
152+
)
153+
)
154+
) { response ->
155+
throw BuildException("Creating PR failed with code ${response.status.code}", null)
156+
}
157+
158+
val prNumber = (prResponse.jsonObject["number"] as JsonPrimitive).int
159+
githubRequest(
160+
Method.POST, "repos/$fullRepo/issues/$prNumber/labels",
161+
Json.encodeToJsonElement(
162+
SetLabelsData(listOf("no-changelog", "library-descriptors"))
163+
)
164+
) { response ->
165+
throw BuildException("Cannot setup labels for created PR: ${response.text}", null)
114166
}
115167
}
116168
}

‎kotlin-jupyter-plugin/src/main/kotlin/org/jetbrains/kotlinx/jupyter/plugin/options.kt

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ fun Project.options(): AllOptions {
4646

4747
project.extra.set("localPublicationsRepo", artifactsDir.resolve("maven"))
4848

49-
5049
pythonVersion = detectVersion(baseVersion, artifactsDir, versionFileName)
5150
val mavenVersion = pythonVersion.toMavenVersion()
5251
project.version = mavenVersion

‎settings.gradle.kts

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pluginManagement {
77
val ktlintGradleVersion: String by settings
88
val jupyterApiVersion: String by settings
99
val publishPluginVersion: String by settings
10+
val changelogPluginVersion: String by settings
1011

1112
repositories {
1213
mavenLocal()
@@ -53,6 +54,7 @@ pluginManagement {
5354
id("org.jetbrains.kotlinx.jupyter.dependencies")
5455
id("ru.ileasile.kotlin.publisher") version publishPluginVersion
5556
id("ru.ileasile.kotlin.doc") version publishPluginVersion
57+
id("org.hildan.github.changelog") version changelogPluginVersion
5658
}
5759
}
5860

0 commit comments

Comments
 (0)
Please sign in to comment.