Skip to content

Commit

Permalink
Create publishing (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
geertmulders authored Feb 1, 2025
1 parent 2734c78 commit 7ef28d0
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 39 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# SPDX-FileCopyrightText: 2022 Free Software Foundation Europe e.V. <https://fsfe.org>
#
# SPDX-License-Identifier: CC0-1.0

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<<EOF" >> $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 != '' }}
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!--
SPDX-FileCopyrightText: 2021-2022 Alliander N.V.
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
15 changes: 8 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand All @@ -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)

Expand Down Expand Up @@ -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.
Expand Down
23 changes: 23 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
SPDX-FileCopyrightText: 2021-2022 Alliander N.V.
SPDX-License-Identifier: MPL-2.0
-->

# 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.)
83 changes: 52 additions & 31 deletions measure/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
//
// 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`

// 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"

// Make sure we can publish to maven
`maven-publish`
id("com.vanniktech.maven.publish") version "0.30.0"
}

group = "com.alliander"
version = "1.2"
version = "1.3.0"

repositories {
mavenCentral()
Expand All @@ -30,47 +32,66 @@ 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")
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of("17"))
}
kotlin {
jvmToolchain(17)
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "17"
}
java {
// Add a task that will package the sources of the main SourceSet in a JAR with classifier `sources`.
withSourcesJar()
}

tasks.withType<Test> {
useJUnitPlatform()
}

tasks.withType<org.jetbrains.dokka.gradle.DokkaTask>().configureEach {
tasks.withType<DokkaTask>().configureEach {
outputDirectory.set(buildDir.resolve("dokka"))
}

publishing {
publications {
create<MavenPublication>("maven") {
artifactId = "open.measure"
from(components["kotlin"])
}
}
mavenPublishing {
// Publishing to https://s01.oss.sonatype.org
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
signAllPublications()

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")
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")

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("[email protected]")
}
developer {
id.set("gmulders")
name.set("Geert Mulders")
email.set("[email protected]")
}
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")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ operator fun <U : Units> Double.times(units: U): Measure<U> = Measure(this.toBig
operator fun <U : Units> Float.times(units: U): Measure<U> = Measure(this.toBigDecimal(), units)
operator fun <U : Units> BigDecimal.times(units: U): Measure<U> = 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
Expand Down Expand Up @@ -107,7 +111,6 @@ data class Measure<U : Units>(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<U>, roundingMode: RoundingMode): Measure<U> {
if (this.isZero() || factor.isZero()) {
return this
Expand Down

0 comments on commit 7ef28d0

Please sign in to comment.