From 095382d5e2cac5efe9e1935a8b459c5379e72aff Mon Sep 17 00:00:00 2001 From: Peter Trifanov Date: Sun, 28 Feb 2021 14:03:31 +0300 Subject: [PATCH] Prepare release to Maven Central ### What's done: * Renamed project to kotlin-multiplatform-diff * Bump gradle version from 6.8.2 to 6.8.3, made gradlew executable, increased gradle memory limits * Bump kotlin version form 1.4.30 to 1.4.31 * Bump junit-jupiter-engine version from 5.0.0 to 5.7.1 * Introduced buildSrc * Added reckon plugin * Added RELEASING.md * Added release.yml * Added PublishingConfiguration.kt --- .github/workflows/release.yml | 68 ++++++++++ README.md | 11 +- RELEASING.md | 3 + build.gradle.kts | 29 ++--- buildSrc/build.gradle.kts | 15 +++ .../petertrr/PublishingConfiguration.kt | 120 ++++++++++++++++++ .../petertrr/VersioningConfiguration.kt | 16 +++ gradle.properties | 3 +- gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 0 settings.gradle.kts | 2 +- 11 files changed, 244 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 RELEASING.md create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/src/main/kotlin/io/github/petertrr/PublishingConfiguration.kt create mode 100644 buildSrc/src/main/kotlin/io/github/petertrr/VersioningConfiguration.kt mode change 100644 => 100755 gradlew diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..86f3c29 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,68 @@ +name: Create release + +on: + push: + tags: + - 'v*' +env: + GPG_SEC: ${{ secrets.PGP_SEC }} + GPG_PASSWORD: ${{ secrets.PGP_PASSWORD }} + OSSRH_USERNAME: ${{ secrets.SONATYPE_USER }} + OSSRH_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + +jobs: + release_linux: + name: Build release on main platform (Linux) + runs-on: ubuntu-20.04 + steps: + - name: Checkout + uses: actions/checkout@v2.3.3 + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 1.11 + - uses: burrunan/gradle-cache-action@v1 + name: Gradle release with caches caching + with: + arguments: publishToSonatype closeSonatypeStagingRepository + gradle-version: wrapper + - name: Create Github Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: false + release_macos: + name: Build release on MacOS + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v2.3.3 + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 1.11 + - uses: burrunan/gradle-cache-action@v1 + name: Gradle release with caches caching + with: + arguments: publishToSonatype closeSonatypeStagingRepository + gradle-version: wrapper + release_windows: + name: Build release on Windows + runs-on: windows-latest + steps: + - name: Checkout + uses: actions/checkout@v2.3.3 + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 1.11 + - uses: burrunan/gradle-cache-action@v1 + name: Gradle release with caches caching + with: + arguments: publishToSonatype closeSonatypeStagingRepository + gradle-version: wrapper \ No newline at end of file diff --git a/README.md b/README.md index 2bb1b5c..82e891d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -# kotlin-diff-utils -![Build and test](https://github.com/petertrr/kotlin-diff-utils/workflows/Build%20and%20test/badge.svg) -[![License](https://img.shields.io/github/license/petertrr/kotlin-diff-utils)](https://github.com/petertrr/kotlin-diff-utils/blob/main/LICENSE) -[![codecov](https://codecov.io/gh/petertrr/kotlin-diff-utils/branch/main/graph/badge.svg)](https://codecov.io/gh/petertrr/kotlin-diff-utils) +# kotlin-multiplatform-diff +![Build and test](https://github.com/petertrr/kotlin-multiplatform-diff/workflows/Build%20and%20test/badge.svg) +[![License](https://img.shields.io/github/license/petertrr/kotlin-multiplatform-diff)](https://github.com/petertrr/kotlin-multiplatform-diff/blob/main/LICENSE) +[![codecov](https://codecov.io/gh/petertrr/kotlin-multiplatform-diff/branch/main/graph/badge.svg)](https://codecov.io/gh/petertrr/kotlin-multiplatform-diff) This is a port of [java-diff-utils](https://github.com/java-diff-utils/java-diff-utils) to kotlin with multiplatform support. All credit for the implementation goes to original authors. @@ -18,4 +18,5 @@ Currently, artifacts for the following platforms are supported: * JVM * JS (both browser and Node.js) * LinuxX64 -* MingwX64 \ No newline at end of file +* MingwX64 +* MacosX64 \ No newline at end of file diff --git a/RELEASING.md b/RELEASING.md new file mode 100644 index 0000000..6cf0bc7 --- /dev/null +++ b/RELEASING.md @@ -0,0 +1,3 @@ +1. Push a new git tag of a format 'v*', e.g. v1.0.0 +2. Github Actions workflow will start, building release and pushing it to maven central. It will then create a github release. +3. Update github release with release notes. \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index ee4775d..4ff6336 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,14 +1,16 @@ -import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.getCurrentOperatingSystem +import io.github.petertrr.configurePublishing +import io.github.petertrr.configureVersioning import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest plugins { - kotlin("multiplatform") version "1.4.30" + kotlin("multiplatform") version "1.4.31" jacoco - id("maven-publish") + id("com.github.ben-manes.versions") version "0.38.0" } +configureVersioning() group = "io.github.petertrr" -version = "0.1.0-SNAPSHOT" +description = "A multiplatform Kotlin library for calculating text differences" repositories { mavenCentral() @@ -18,17 +20,14 @@ kotlin { explicitApi() jvm() - js(IR) { + js(BOTH) { browser() nodejs() } // setup native compilation - val os = getCurrentOperatingSystem() - val hostTarget = when { - os.isLinux -> linuxX64() - os.isWindows -> mingwX64() - else -> throw GradleException("Host OS '${os.name}' is not supported in Kotlin/Native $project.") - } + linuxX64() + mingwX64() + macosX64() sourceSets { val commonTest by getting { @@ -41,7 +40,7 @@ kotlin { val jvmTest by getting { dependencies { implementation(kotlin("test-junit5")) - implementation("org.junit.jupiter:junit-jupiter-engine:5.0.0") + implementation("org.junit.jupiter:junit-jupiter-engine:5.7.1") } } val jsTest by getting { @@ -52,11 +51,7 @@ kotlin { } } -publishing { - repositories { - mavenLocal() - } -} +configurePublishing() tasks.withType { useJUnitPlatform() diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..17a4e05 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,15 @@ +plugins { + `kotlin-dsl` +} + +repositories { + gradlePluginPortal() + mavenCentral() + jcenter() +} + +dependencies { + implementation("org.ajoberstar.reckon:reckon-gradle:0.13.0") + implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.4.20") + implementation("io.github.gradle-nexus:publish-plugin:1.0.0") +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/io/github/petertrr/PublishingConfiguration.kt b/buildSrc/src/main/kotlin/io/github/petertrr/PublishingConfiguration.kt new file mode 100644 index 0000000..a164308 --- /dev/null +++ b/buildSrc/src/main/kotlin/io/github/petertrr/PublishingConfiguration.kt @@ -0,0 +1,120 @@ +package io.github.petertrr + +import org.gradle.api.Project +import io.github.gradlenexus.publishplugin.NexusPublishPlugin +import io.github.gradlenexus.publishplugin.NexusPublishExtension +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.api.publish.maven.plugins.MavenPublishPlugin +import org.gradle.api.publish.maven.tasks.AbstractPublishToMaven +import org.gradle.api.tasks.bundling.Jar +import org.gradle.kotlin.dsl.* +import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform +import org.gradle.plugins.signing.SigningExtension +import org.gradle.plugins.signing.SigningPlugin + +fun Project.configurePublishing() { + apply() + apply() + apply() + + // If present, set properties from env variables. If any are absent, release will fail. + System.getenv("OSSRH_USERNAME")?.let { + extra.set("sonatypeUsername", it) + } + System.getenv("OSSRH_PASSWORD")?.let { + extra.set("sonatypePassword", it) + } + System.getenv("GPG_SEC")?.let { + extra.set("signingKey", it) + } + System.getenv("GPG_PASSWORD")?.let { + extra.set("signingPassword", it) + } + + configurePublications() + // https://kotlinlang.org/docs/mpp-publish-lib.html#avoid-duplicate-publications + val publicationsFromMainHost = listOf("jvm", "js", "kotlinMultiplatform") + configure { + publications { + matching { it.name in publicationsFromMainHost }.all { + val targetPublication = this@all + tasks.withType() + .matching { it.publication == targetPublication } + .configureEach { + onlyIf { + // main publishing CI job is executed on Linux host + DefaultNativePlatform.getCurrentOperatingSystem().isLinux + } + } + } + } + } + + if (hasProperty("signingKey")) { + configureSigning() + } + if (hasProperty("sonatypeUsername")) { + configureNexusPublishing() + } +} + +private fun Project.configurePublications() { + val dokkaJar = tasks.create("dokkaJar") { + group = "documentation" + archiveClassifier.set("javadoc") + from(tasks.findByName("dokkaHtml")) + } + configure { + repositories { + mavenLocal() + } + publications.withType().forEach { publication -> + publication.artifact(dokkaJar) + publication.pom { + name.set(project.name) + description.set(project.description ?: project.name) + url.set("https://github.com/petertrr/kotlin-multiplatform-diff") + licenses { + license { + name.set("The Apache Software License, Version 2.0") + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") + distribution.set("repo") + } + } + developers { + developer { + id.set("petertrr") + name.set("Petr Trifanov") + email.set("peter.trifanov@mail.ru") + } + } + scm { + url.set("https://github.com/petertrr/kotlin-multiplatform-diff") + connection.set("scm:git:git://github.com/petertrr/kotlin-multiplatform-diff.git") + } + } + } + } +} + +private fun Project.configureSigning() { + configure { + useInMemoryPgpKeys(property("signingKey") as String?, property("signingPassword") as String?) + logger.lifecycle("The following publications are getting signed: ${extensions.getByType().publications.map { it.name }}") + sign(*extensions.getByType().publications.toTypedArray()) + } +} + +private fun Project.configureNexusPublishing() { + configure { + repositories { + sonatype { //only for users registered in Sonatype after 24 Feb 2021 + nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) + snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) + username.set(property("sonatypeUsername") as String) + password.set(property("sonatypePassword") as String) + } + } + } +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/io/github/petertrr/VersioningConfiguration.kt b/buildSrc/src/main/kotlin/io/github/petertrr/VersioningConfiguration.kt new file mode 100644 index 0000000..6dc51cf --- /dev/null +++ b/buildSrc/src/main/kotlin/io/github/petertrr/VersioningConfiguration.kt @@ -0,0 +1,16 @@ +package io.github.petertrr + +import org.ajoberstar.reckon.gradle.ReckonExtension +import org.ajoberstar.reckon.gradle.ReckonPlugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.configure + +fun Project.configureVersioning() { + apply() + + configure { + scopeFromProp() + stageFromProp("alpha", "rc", "final") // version string will be based on last commit; when checking out a tag, that tag will be used + } +} diff --git a/gradle.properties b/gradle.properties index 29e08e8..5c4eaf8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1,2 @@ -kotlin.code.style=official \ No newline at end of file +kotlin.code.style=official +org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2a56324..442d913 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/settings.gradle.kts b/settings.gradle.kts index d0fd497..d79ee3c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1 +1 @@ -rootProject.name = "kotlin-diff-utils" +rootProject.name = "kotlin-multiplatform-diff"