From ec2374ab16a595632eaa94bae6187f0df1a28f8a Mon Sep 17 00:00:00 2001 From: Geert Mulders Date: Sun, 15 Dec 2024 21:12:17 +0100 Subject: [PATCH 01/15] Try to get publishing working Signed-off-by: Geert Mulders --- .github/workflows/publish-release.yml | 49 ++++++++++++ CHANGELOG.md | 5 ++ measure/build.gradle.kts | 76 ++++++++++++------- .../com/alliander/open/measure/Measure.kt | 5 +- 4 files changed, 106 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/publish-release.yml create mode 100644 CHANGELOG.md diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml new file mode 100644 index 0000000..aa95ea4 --- /dev/null +++ b/.github/workflows/publish-release.yml @@ -0,0 +1,49 @@ +name: Publish Release + +on: + push: + tags: + - '**' + +jobs: + publish: + + runs-on: ubuntu-latest + if: github.repository == 'alliander-opensource/measure' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install JDK + uses: actions/setup-java@v4 + with: + distribution: zulu + java-version: 17 + + - name: Get release notes + run: | + echo "RELEASE_NOTES<> $GITHUB_ENV + echo "$(awk '/^## ${{ github.ref_name }}/{flag=1;next}/^## /{flag=0}flag' CHANGELOG.md)" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + + - name: Set version for tag + run: | + echo "ORG_GRADLE_PROJECT_VERSION_NAME=${{ github.ref_name }}" >> $GITHUB_ENV + + - uses: gradle/actions/setup-gradle@v4 + + - name: Publish + run: ./gradlew :measure:publishToMavenCentral + env: + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_PRIVATE_KEY }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_PASSPHRASE }} + +# - name: Create Release +# uses: softprops/action-gh-release@v2 +# with: +# token: ${{ secrets.GITHUB_TOKEN }} +# body: ${{ env.RELEASE_NOTES }} +# if: ${{ env.RELEASE_NOTES != '' }} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..2e4ef52 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# Change Log + +## 1.3.0 *(2024-12-15)* + +- First open source release diff --git a/measure/build.gradle.kts b/measure/build.gradle.kts index e09062f..fe9ef27 100644 --- a/measure/build.gradle.kts +++ b/measure/build.gradle.kts @@ -2,9 +2,12 @@ // // SPDX-License-Identifier: MPL-2.0 +import com.vanniktech.maven.publish.SonatypeHost +import org.jetbrains.dokka.gradle.DokkaTask + plugins { // Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin. - id("org.jetbrains.kotlin.jvm") + kotlin("jvm") // Apply the java-library plugin for API and implementation separation. `java-library` @@ -12,8 +15,7 @@ plugins { // Apply dokka plugin to allow extraction of ducumentation from KDoc comments id("org.jetbrains.dokka") version "1.4.20" - // Make sure we can publish to maven - `maven-publish` + id("com.vanniktech.maven.publish") version "0.30.0" } group = "com.alliander" @@ -30,47 +32,65 @@ dependencies { // Use the Kotlin JDK 8 standard library. implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") - testImplementation("io.kotest:kotest-runner-junit5:4.3.2") - testImplementation("io.kotest:kotest-assertions-core:4.3.2") - testImplementation("io.kotest:kotest-property:4.3.2") + testImplementation("io.kotest:kotest-runner-junit5:5.9.1") + testImplementation("io.kotest:kotest-assertions-core:5.9.1") + testImplementation("io.kotest:kotest-property:5.9.1") +} + +kotlin { + jvmToolchain(17) } java { - toolchain { - languageVersion.set(JavaLanguageVersion.of("17")) - } + // We add both the sources and the javadoc jar. + withSourcesJar() + withJavadocJar() } -tasks.withType().configureEach { - kotlinOptions { - jvmTarget = "17" - } +// This task is added by Gradle when we use java.withJavadocJar() +val javadocJar = tasks.named("javadocJar") { + from(tasks.named("dokkaJavadoc")) } tasks.withType { useJUnitPlatform() } -tasks.withType().configureEach { +tasks.withType().configureEach { outputDirectory.set(buildDir.resolve("dokka")) } -publishing { - publications { - create("maven") { - artifactId = "open.measure" - from(components["kotlin"]) - } - } +mavenPublishing { + // Publishing to https://s01.oss.sonatype.org + publishToMavenCentral(SonatypeHost.S01) + signAllPublications() + coordinates("com.alliander", "measure", "1.3.0-SNAPSHOT") + + pom { + name.set("Measure") + description.set("Measure is a Kotlin library for working with units of measurement that are - for example - used in the power system sector.") + url.set("https://github.com/alliander-opensource/measure") - repositories { - maven { - name = "AllianderNexus" - url = uri("https://nexus.apps.ocp-01.prd.ahcaws.com/repository/maven-releases/") - credentials { - username = System.getenv("ALLIANDER_NEXUS_USERNAME") - password = System.getenv("ALLIANDER_NEXUS_PASSWORD") + licenses { + license { + name.set("Mozilla Public License Version 2.0") + url.set("https://www.mozilla.org/en-US/MPL/2.0/") + } + } + developers { + developer { + id.set("dvberkel") + name.set("Daan van Berkel") + email.set("daan.v.berkel.1980@gmail.com") + } + developer { + id.set("gmulders") + name.set("Geert Mulders") + email.set("gmulders@gmail.com") } } + scm { + url.set("https://github.com/alliander-opensource/measure") + } } } diff --git a/measure/src/main/kotlin/com/alliander/open/measure/Measure.kt b/measure/src/main/kotlin/com/alliander/open/measure/Measure.kt index c25a09e..3147128 100644 --- a/measure/src/main/kotlin/com/alliander/open/measure/Measure.kt +++ b/measure/src/main/kotlin/com/alliander/open/measure/Measure.kt @@ -13,6 +13,10 @@ operator fun Double.times(units: U): Measure = Measure(this.toBig operator fun Float.times(units: U): Measure = Measure(this.toBigDecimal(), units) operator fun BigDecimal.times(units: U): Measure = Measure(this, units) +/** + * [Units] is the base class for a Unit, e.g. [Power] or [Current]. The reason for calling it "Units" is that "Unit" + * was taken in Kotlin. + */ open class Units(val suffix: String, val ratio: BigDecimal = BigDecimal.ONE) { override fun equals(other: Any?): Boolean { if (this === other) return true @@ -107,7 +111,6 @@ data class Measure(val amount: BigDecimal, val units: U) : Comparable * - In case the dividend or the factor is zero, the dividend is returned as is. * - In case the factor is negative, it is assessed as if it were positive. */ - fun roundToMultiple(factor: Measure, roundingMode: RoundingMode): Measure { if (this.isZero() || factor.isZero()) { return this From 67bf8567099b436bed8e6979fe49bbc074442f4e Mon Sep 17 00:00:00 2001 From: Geert Mulders Date: Sun, 15 Dec 2024 21:15:47 +0100 Subject: [PATCH 02/15] License stuff Signed-off-by: Geert Mulders --- .github/workflows/publish-release.yml | 4 ++++ CHANGELOG.md | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index aa95ea4..0422726 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2022 Free Software Foundation Europe e.V. +# +# SPDX-License-Identifier: CC0-1.0 + name: Publish Release on: diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e4ef52..11754e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ + + # Change Log ## 1.3.0 *(2024-12-15)* From 1b039ea1c0e8f9b33cd6d53afc64eee65addf710 Mon Sep 17 00:00:00 2001 From: Geert Mulders Date: Sun, 15 Dec 2024 21:19:39 +0100 Subject: [PATCH 03/15] Update Dokka Signed-off-by: Geert Mulders --- measure/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/measure/build.gradle.kts b/measure/build.gradle.kts index fe9ef27..1e42605 100644 --- a/measure/build.gradle.kts +++ b/measure/build.gradle.kts @@ -13,7 +13,7 @@ plugins { `java-library` // Apply dokka plugin to allow extraction of ducumentation from KDoc comments - id("org.jetbrains.dokka") version "1.4.20" + id("org.jetbrains.dokka") version "1.9.20" id("com.vanniktech.maven.publish") version "0.30.0" } From ca9904fa036d124a729652695f2d0a9449225c5d Mon Sep 17 00:00:00 2001 From: Geert Mulders Date: Sun, 15 Dec 2024 21:41:27 +0100 Subject: [PATCH 04/15] DokkaHtml? Signed-off-by: Geert Mulders --- measure/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/measure/build.gradle.kts b/measure/build.gradle.kts index 1e42605..a5bf6f9 100644 --- a/measure/build.gradle.kts +++ b/measure/build.gradle.kts @@ -49,7 +49,7 @@ java { // This task is added by Gradle when we use java.withJavadocJar() val javadocJar = tasks.named("javadocJar") { - from(tasks.named("dokkaJavadoc")) + from(tasks.named("dokkaHtml")) } tasks.withType { From b3577c607c294d9348d5787ec6e391492410de2e Mon Sep 17 00:00:00 2001 From: Geert Mulders Date: Sun, 15 Dec 2024 21:46:37 +0100 Subject: [PATCH 05/15] Duplicate javadoc Signed-off-by: Geert Mulders --- measure/build.gradle.kts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/measure/build.gradle.kts b/measure/build.gradle.kts index a5bf6f9..9eb3ccd 100644 --- a/measure/build.gradle.kts +++ b/measure/build.gradle.kts @@ -44,13 +44,13 @@ kotlin { java { // We add both the sources and the javadoc jar. withSourcesJar() - withJavadocJar() +// withJavadocJar() } -// This task is added by Gradle when we use java.withJavadocJar() -val javadocJar = tasks.named("javadocJar") { - from(tasks.named("dokkaHtml")) -} +//// This task is added by Gradle when we use java.withJavadocJar() +//val javadocJar = tasks.named("javadocJar") { +// from(tasks.named("dokkaHtml")) +//} tasks.withType { useJUnitPlatform() From 07698d0b8f31576e45975cee51d0a4a369001621 Mon Sep 17 00:00:00 2001 From: Geert Mulders Date: Sun, 15 Dec 2024 22:07:35 +0100 Subject: [PATCH 06/15] Use the CentralPortal Signed-off-by: Geert Mulders --- measure/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/measure/build.gradle.kts b/measure/build.gradle.kts index 9eb3ccd..c655704 100644 --- a/measure/build.gradle.kts +++ b/measure/build.gradle.kts @@ -62,7 +62,7 @@ tasks.withType().configureEach { mavenPublishing { // Publishing to https://s01.oss.sonatype.org - publishToMavenCentral(SonatypeHost.S01) + publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) signAllPublications() coordinates("com.alliander", "measure", "1.3.0-SNAPSHOT") From 2292fa565e6cd03b8fa61025ceb21ea9f21229fb Mon Sep 17 00:00:00 2001 From: Geert Mulders Date: Sun, 15 Dec 2024 22:18:46 +0100 Subject: [PATCH 07/15] No snapshotting Signed-off-by: Geert Mulders --- measure/build.gradle.kts | 1 - 1 file changed, 1 deletion(-) diff --git a/measure/build.gradle.kts b/measure/build.gradle.kts index c655704..34707b4 100644 --- a/measure/build.gradle.kts +++ b/measure/build.gradle.kts @@ -64,7 +64,6 @@ mavenPublishing { // Publishing to https://s01.oss.sonatype.org publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) signAllPublications() - coordinates("com.alliander", "measure", "1.3.0-SNAPSHOT") pom { name.set("Measure") From 294d2134335c2ea0fe2d3c556f94678e5fdd3b19 Mon Sep 17 00:00:00 2001 From: Geert Mulders Date: Sun, 15 Dec 2024 22:18:59 +0100 Subject: [PATCH 08/15] v 1.3 Signed-off-by: Geert Mulders --- measure/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/measure/build.gradle.kts b/measure/build.gradle.kts index 34707b4..641ab46 100644 --- a/measure/build.gradle.kts +++ b/measure/build.gradle.kts @@ -19,7 +19,7 @@ plugins { } group = "com.alliander" -version = "1.2" +version = "1.3" repositories { mavenCentral() From f4a0cbcb7a623027c7495ee5a29d0045e2c5c304 Mon Sep 17 00:00:00 2001 From: Geert Mulders Date: Thu, 9 Jan 2025 12:06:12 +0100 Subject: [PATCH 09/15] Improve documentation for releasing Signed-off-by: Geert Mulders --- RELEASING.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 RELEASING.md diff --git a/RELEASING.md b/RELEASING.md new file mode 100644 index 0000000..320b969 --- /dev/null +++ b/RELEASING.md @@ -0,0 +1,17 @@ +# Releasing procedure + +After adding new features or bugfixes you might want to release the changes so that they can be used. To do this, we +follow a number of steps to make sure that every release is of a high quality. + +1. Every PR to main the CHANGELOG.md is updated with the changes, this will be reviewed as well. +2. Before starting the actual release we must make sure that the version number is correct in the CHANGELOG.md. We + follow [semantic versioning](https://semver.org/). +3. Merge the last changes to main and create a new tag on main. The tag should be the version number without a 'v'. E.g. + `1.3.5`. +4. A github action will be triggered, the release is build, signed and then pushed to maven central. +5. Maven central will validate the release. If the release passes, it can be published manually. For this someone has to + login in maven central and push the "publish" button. +6. The release in github will be automatically created including the release notes. +7. After everything is done, it is nice to add a new header in the CHANGELOG.md with the next version number. Also + update the version number in the build.gradle.kts. (Note that the version that is used will be taken from the tagname + NOT the version in the build.gradle.kts.) \ No newline at end of file From 783395479c1607f00628f10f729e1aa472da2b7e Mon Sep 17 00:00:00 2001 From: Geert Mulders Date: Thu, 9 Jan 2025 12:46:38 +0100 Subject: [PATCH 10/15] Improve documentation for releasing Signed-off-by: Geert Mulders --- CONTRIBUTING.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8de5678..1657c05 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,9 +13,9 @@ Contribution does not necessarily mean committing code to the repository. We recognize different levels of contributions as shown below in increasing order of dedication: 1. Test and use the libray. Give feedback on the user experience or suggest new features. -3. Report bugs. -4. Improve the documentation -5. Contributing to the Kotlin code +2. Report bugs. +3. Improve the documentation +4. Contributing to the Kotlin code ## Community Guidelines This project follows the following [Code of Conduct][code-of-conduct]. @@ -28,10 +28,10 @@ Documentation is a very important part of a project. If people don't know how to Contribute to the documentation on the [documentation page][project:documentation]. -[code-of-conduct]: https://github.com/Alliander/project/blob/master/CODE_OF_CONDUCT.md -[project:issues]: https://github.com/Alliander/project/issues -[project:discussion]: https://github.com/Alliander/project/discussions -[project:documentation]: https://github.com/Alliander/project/wiki +[code-of-conduct]: https://github.com/alliander-opensource/measure/blob/main/CODE_OF_CONDUCT.md +[project:issues]: https://github.com/alliander-opensource/project/issues +[project:discussion]: https://github.com/alliander-opensource/project/discussions +[project:documentation]: https://github.com/alliander-opensource/project/wiki ## Signing the Developer Certificate of Origin (DCO) @@ -72,6 +72,7 @@ The process for a code change and pull request you should follow: "feature-###" or "fix-###". For more information see the Git branching guideline. 1. Make changes, compile, and test thoroughly. Ensure any install or build dependencies are removed before the end of the layer when doing a build. Code style should match existing style and conventions, and changes should be focused on the topic the pull request will be addressed. For more information see the style guide. 1. Push commits to your fork. +1. Update the CHANGELOG.md with the changes. 1. Create a Github pull request from your topic branch. 1. Pull requests will be reviewed by one of the maintainers who may discuss, offer constructive feedback, request changes, or approve the work. For more information see the Code review guideline. From aefb805c68b3b09779044553c9abb426d732c081 Mon Sep 17 00:00:00 2001 From: Geert Mulders Date: Thu, 9 Jan 2025 12:47:10 +0100 Subject: [PATCH 11/15] Create automatic github release Signed-off-by: Geert Mulders --- .github/workflows/publish-release.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 0422726..0a0f03b 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -45,9 +45,9 @@ jobs: ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_PRIVATE_KEY }} ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_PASSPHRASE }} -# - name: Create Release -# uses: softprops/action-gh-release@v2 -# with: -# token: ${{ secrets.GITHUB_TOKEN }} -# body: ${{ env.RELEASE_NOTES }} -# if: ${{ env.RELEASE_NOTES != '' }} \ No newline at end of file + - name: Create Release + uses: softprops/action-gh-release@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + body: ${{ env.RELEASE_NOTES }} + if: ${{ env.RELEASE_NOTES != '' }} From 209e103dd6d11c27c34cb40008b662940d5e8bd7 Mon Sep 17 00:00:00 2001 From: Geert Mulders Date: Thu, 9 Jan 2025 12:47:32 +0100 Subject: [PATCH 12/15] Cleanup build.gradle.kts Signed-off-by: Geert Mulders --- measure/build.gradle.kts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/measure/build.gradle.kts b/measure/build.gradle.kts index 641ab46..3bf1f3d 100644 --- a/measure/build.gradle.kts +++ b/measure/build.gradle.kts @@ -19,7 +19,7 @@ plugins { } group = "com.alliander" -version = "1.3" +version = "1.3.0" repositories { mavenCentral() @@ -44,14 +44,8 @@ kotlin { java { // We add both the sources and the javadoc jar. withSourcesJar() -// withJavadocJar() } -//// This task is added by Gradle when we use java.withJavadocJar() -//val javadocJar = tasks.named("javadocJar") { -// from(tasks.named("dokkaHtml")) -//} - tasks.withType { useJUnitPlatform() } From 3c41395e2e8960b6e3e71600645b77c26992d18a Mon Sep 17 00:00:00 2001 From: Geert Mulders Date: Thu, 9 Jan 2025 12:51:37 +0100 Subject: [PATCH 13/15] Add placeholder for next version Signed-off-by: Geert Mulders --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11754e1..5166d70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ SPDX-License-Identifier: MPL-2.0 # Change Log +## 1.3.1 *(tbd)* + +- No changes yet (remove this line on the first change) + ## 1.3.0 *(2024-12-15)* - First open source release From 4f58cc76dc5538d59277e6e09d4cad0fc07dcba5 Mon Sep 17 00:00:00 2001 From: Geert Mulders Date: Thu, 9 Jan 2025 12:54:20 +0100 Subject: [PATCH 14/15] Add copyright header Signed-off-by: Geert Mulders --- RELEASING.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/RELEASING.md b/RELEASING.md index 320b969..084c8e0 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -1,3 +1,9 @@ + + # Releasing procedure After adding new features or bugfixes you might want to release the changes so that they can be used. To do this, we From 4c8da746fb17f21e24b033aa00b191f3df796c22 Mon Sep 17 00:00:00 2001 From: Geert Mulders Date: Fri, 10 Jan 2025 11:48:35 +0100 Subject: [PATCH 15/15] Update comment for the java doc and add two main contributors Signed-off-by: Geert Mulders --- measure/build.gradle.kts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/measure/build.gradle.kts b/measure/build.gradle.kts index 3bf1f3d..f45d608 100644 --- a/measure/build.gradle.kts +++ b/measure/build.gradle.kts @@ -42,7 +42,7 @@ kotlin { } java { - // We add both the sources and the javadoc jar. + // Add a task that will package the sources of the main SourceSet in a JAR with classifier `sources`. withSourcesJar() } @@ -81,6 +81,14 @@ mavenPublishing { name.set("Geert Mulders") email.set("gmulders@gmail.com") } + developer { + id.set("cflist") + name.set("Coen van der List") + } + developer { + id.set("BaukjeD") + name.set("Baukje Debets") + } } scm { url.set("https://github.com/alliander-opensource/measure")