Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Changelog and fix Gradle plugin sources publication #311

Merged
merged 2 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
460 changes: 406 additions & 54 deletions CHANGELOG.md

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ plugins {
id("org.jetbrains.kotlinx.jupyter.dependencies")
id("ru.ileasile.kotlin.publisher")
id("ru.ileasile.kotlin.doc")
id("org.hildan.github.changelog")
}

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

val docsRepo: String by project
val githubRepoUser: String by project
val githubRepoName: String by project

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

changelog {
githubUser = githubRepoUser
githubRepository = githubRepoName
excludeLabels = listOf("wontfix", "duplicate", "no-changelog", "question")
}

kotlinPublications {
packageGroup = "org.jetbrains.kotlinx"

Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ stableKotlinLanguageLevel=1.5
jvmTarget=1.8

shadowJarVersion=7.0.0
changelogPluginVersion=1.7.0
kotlinxSerializationVersion=1.1.0
ktlintGradleVersion=10.0.0
ktlintVersion=0.40.0
Expand All @@ -19,6 +20,8 @@ artifactsPath=build/artifacts

baseVersion=0.10.0

githubRepoUser=Kotlin
githubRepoName=kotlin-jupyter
projectRepoUrl=https://github.com/Kotlin/kotlin-jupyter
docsRepo=git@github.com:ileasile/kotlin-jupyter-docs.git
pushRepoUrl=git@github.com:Kotlin/kotlin-jupyter.git
Expand Down
16 changes: 5 additions & 11 deletions jupyter-lib/kotlin-jupyter-api-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ val saveVersion by tasks.registering {
}
}

java {
withSourcesJar()
withJavadocJar()
}

tasks {
processResources {
dependsOn(saveVersion)
Expand All @@ -59,11 +64,6 @@ tasks {
events("passed", "skipped", "failed")
}
}

register<Jar>("sourceJar") {
archiveClassifier.set("sources")
from(sourceSets.named("main").get().allSource)
}
}

val pluginName = "apiGradlePlugin"
Expand Down Expand Up @@ -97,12 +97,6 @@ pluginBundle {
}

publishing {
publications {
withType<MavenPublication> {
artifact(tasks["sourceJar"])
}
}

repositories {
(rootProject.findProperty("localPublicationsRepo") as? java.nio.file.Path)?.let {
maven {
Expand Down
1 change: 1 addition & 0 deletions kotlin-jupyter-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id("org.jlleitschuh.gradle.ktlint")
`java-gradle-plugin`
`kotlin-dsl`
kotlin("plugin.serialization")
}

repositories {
Expand Down
2 changes: 2 additions & 0 deletions kotlin-jupyter-plugin/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pluginManagement {

val ktlintGradleVersion = rootProperties["ktlintGradleVersion"] as String
val publishPluginVersion = rootProperties["publishPluginVersion"] as String
val stableKotlinVersion = rootProperties["stableKotlinVersion"] as String

repositories {
gradlePluginPortal()
Expand All @@ -39,6 +40,7 @@ pluginManagement {
}

plugins {
kotlin("plugin.serialization") version stableKotlinVersion
id("org.jlleitschuh.gradle.ktlint") version ktlintGradleVersion
id("ru.ileasile.kotlin.publisher") version publishPluginVersion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ fun writeJson(json: Map<String, Any>, path: Path) {

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

fun <T> Project.prop(name: String): T {
@Suppress("UNCHECKED_CAST")
return property(name) as T
}

fun Project.stringPropOrEmpty(name: String) = rootProject.findProperty(name) as String? ?: ""

interface AllOptions : BuildOptions, InstallOptions, DistribOptions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,50 @@
package org.jetbrains.kotlinx.jupyter.build

import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.encodeToJsonElement
import kotlinx.serialization.json.int
import org.gradle.api.Project
import org.gradle.process.ExecResult
import org.gradle.process.ExecSpec
import org.gradle.tooling.BuildException
import java.io.File
import java.io.OutputStream
import org.http4k.core.Method
import org.http4k.core.Request
import org.jetbrains.kotlinx.jupyter.common.jsonObject
import org.http4k.core.Response
import org.jetbrains.kotlinx.jupyter.common.ResponseWrapper
import org.jetbrains.kotlinx.jupyter.common.httpRequest
import org.jetbrains.kotlinx.jupyter.common.jsonObject
import org.jetbrains.kotlinx.jupyter.common.text
import org.jetbrains.kotlinx.jupyter.common.withBasicAuth
import org.jetbrains.kotlinx.jupyter.common.withJson
import java.io.File
import java.io.OutputStream

private val Project.libName get() = prop<String>("jupyter.lib.name")
private val Project.libParamName get() = prop<String>("jupyter.lib.param.name")
private val Project.libParamValue get() = prop<String>("jupyter.lib.param.value")

private val Project.prGithubUser get() = prop<String>("jupyter.github.user")
private val Project.prGithubToken get() = prop<String>("jupyter.github.token")

private val Project.githubRepoOwner get() = prop<String>("githubRepoUser")
private val Project.githubRepoName get() = prop<String>("githubRepoName")

@Serializable
class NewPrData(
val title: String,
val head: String,
val base: String,
)

@Serializable
class SetLabelsData(
val labels: List<String>,
)

fun ProjectWithInstallOptions.prepareKotlinVersionUpdateTasks() {
tasks.register("updateKotlinVersion") {
Expand Down Expand Up @@ -49,9 +77,9 @@ fun ProjectWithInstallOptions.prepareKotlinVersionUpdateTasks() {

val updateLibraryParamTask = tasks.register("updateLibraryParam") {
doLast {
val libName = project.property("jupyter.lib.name") as String
val paramName = project.property("jupyter.lib.param.name") as String
val paramValue = project.property("jupyter.lib.param.value") as String
val libName = project.libName
val paramName = project.libParamName
val paramValue = project.libParamValue

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

val repoUrl = rootProject.property("pushRepoUrl") as String
execGit("push", "--force", "-u", repoUrl, getCurrentBranch() + ":" + updateLibBranchName!!) {
this.standardOutput = object: OutputStream() {
execGit("push", "--force", "-u", repoUrl, getCurrentBranch() + ":refs/heads/" + updateLibBranchName!!) {
this.standardOutput = object : OutputStream() {
override fun write(b: Int) { }
}
}
Expand All @@ -93,24 +121,48 @@ fun ProjectWithInstallOptions.prepareKotlinVersionUpdateTasks() {
dependsOn(pushChangesTask)

doLast {
val user = rootProject.property("jupyter.github.user") as String
val password = rootProject.property("jupyter.github.token") as String
fun githubRequest(method: Method, request: String, json: Map<String, String>? = null): Int {
val response = httpRequest(Request(method, "https://api.github.com/$request")
.withJson(Json.encodeToJsonElement(json))
.withBasicAuth(user, password)
val user = rootProject.prGithubUser
val password = rootProject.prGithubToken
fun githubRequest(
method: Method,
request: String,
json: JsonElement,
onFailure: (Response) -> Unit,
): ResponseWrapper {
val response = httpRequest(
Request(method, "https://api.github.com/$request")
.withJson(json)
.withBasicAuth(user, password)
)
println(response.text)
return response.status.code
if (!response.status.successful) {
onFailure(response)
}
return response
}

val code = githubRequest(Method.POST, "repos/Kotlin/kotlin-jupyter/pulls", mapOf(
"title" to "Update library versions",
"head" to updateLibBranchName!!,
"base" to "master"
))
if(code != 200 && code != 201) {
throw BuildException("Creating PR failed with code $code", null)
val fullRepo = "${rootProject.githubRepoOwner}/${rootProject.githubRepoName}"
val prResponse = githubRequest(
Method.POST, "repos/$fullRepo/pulls",
Json.encodeToJsonElement(
NewPrData(
title = "Update `${rootProject.libName}` library to `${rootProject.libParamValue}`",
head = updateLibBranchName!!,
base = "master"
)
)
) { response ->
throw BuildException("Creating PR failed with code ${response.status.code}", null)
}

val prNumber = (prResponse.jsonObject["number"] as JsonPrimitive).int
githubRequest(
Method.POST, "repos/$fullRepo/issues/$prNumber/labels",
Json.encodeToJsonElement(
SetLabelsData(listOf("no-changelog", "library-descriptors"))
)
) { response ->
throw BuildException("Cannot setup labels for created PR: ${response.text}", null)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ fun Project.options(): AllOptions {

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


pythonVersion = detectVersion(baseVersion, artifactsDir, versionFileName)
val mavenVersion = pythonVersion.toMavenVersion()
project.version = mavenVersion
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pluginManagement {
val ktlintGradleVersion: String by settings
val jupyterApiVersion: String by settings
val publishPluginVersion: String by settings
val changelogPluginVersion: String by settings

repositories {
mavenLocal()
Expand Down Expand Up @@ -53,6 +54,7 @@ pluginManagement {
id("org.jetbrains.kotlinx.jupyter.dependencies")
id("ru.ileasile.kotlin.publisher") version publishPluginVersion
id("ru.ileasile.kotlin.doc") version publishPluginVersion
id("org.hildan.github.changelog") version changelogPluginVersion
}
}

Expand Down