Skip to content

Commit

Permalink
Create KMP structure
Browse files Browse the repository at this point in the history
  • Loading branch information
vgarciabnz committed Dec 13, 2023
1 parent bef3f68 commit 9cd5390
Show file tree
Hide file tree
Showing 96 changed files with 1,205 additions and 424 deletions.
19 changes: 11 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ jobs:
with:
java-version: 17
distribution: temurin
cache: maven
cache: 'gradle'
- name: Change wrapper permission
run: chmod +x ./gradlew
- name: Test
run: mvn clean install -DskipTests=false --update-snapshots -q
run: ./gradlew clean allTests

artifact:
name: Publish - Nexus
Expand All @@ -28,10 +30,11 @@ jobs:
with:
java-version: 17
distribution: temurin
cache: maven
cache: 'gradle'
- name: Change wrapper permission
run: chmod +x ./gradlew
- name: Release Maven package
uses: samuelmeuli/action-maven-publish@v1
with:
nexus_username: ${{ secrets.SONATYPE_OSSRH_USERNAME }}
nexus_password: ${{ secrets.SONATYPE_OSSRH_PASSWORD }}
maven_profiles: "branch"
run: ./gradlew publishAllPublicationsToSonatypeRepository
env:
OSSRH_USERNAME: ${{ secrets.SONATYPE_OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.SONATYPE_OSSRH_PASSWORD }}
36 changes: 19 additions & 17 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,38 @@ jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
cache: maven
- name: Change wrapper permission
run: chmod +x ./gradlew
- name: Test
run: mvn clean install -DskipTests=false --update-snapshots -q
run: ./gradlew clean allTests

artifact:
name: Publish - Nexus
name: Publish
runs-on: ubuntu-latest
needs: unit-test

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
cache: maven
- name: Remove snapshot
run: mvn -B versions:set -DremoveSnapshot -DgenerateBackupPoms=false
- name: Release Maven package
uses: samuelmeuli/action-maven-publish@v1
with:
nexus_username: ${{ secrets.SONATYPE_OSSRH_USERNAME }}
nexus_password: ${{ secrets.SONATYPE_OSSRH_PASSWORD }}
gpg_private_key: ${{ secrets.PGP_PRIVATE_KEY }}
gpg_passphrase: ${{ secrets.PGP_PASSPHRASE }}
maven_profiles: "master"
cache: 'gradle'
- name: Change wrapper permission
run: chmod +x ./gradlew
- name: Publish to Maven
#run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -PremoveSnapshot
run: ./gradlew assemble -PremoveSnapshot
env:
OSSRH_USERNAME: ${{ secrets.SONATYPE_OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.SONATYPE_OSSRH_PASSWORD }}
SIGNING_PRIVATE_KEY: ${{ secrets.PGP_PRIVATE_KEY }}
SIGNING_PASSWORD: ${{ secrets.PGP_PASSPHRASE }}
24 changes: 0 additions & 24 deletions build.gradle

This file was deleted.

71 changes: 71 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
plugins {
kotlin("multiplatform")
id("maven-publish-conventions")
id("npm-publish-conventions")
}

repositories {
mavenCentral()
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") }
}

group = "org.hisp.dhis.rules"
version = "3.0.0-SNAPSHOT"

val isReleaseVersion = project.hasProperty("removeSnapshot")
if (isReleaseVersion) {
version = (version as String).replace("-SNAPSHOT", "")
}

kotlin {
jvm {
jvmToolchain(17)
withJava()
testRuns.named("test") {
executionTask.configure {
useJUnit()
}
}
}
js {
nodejs()
useEsModules()
binaries.library()
generateTypeScriptDefinitions()
}
val hostOs = System.getProperty("os.name")
val isArm64 = System.getProperty("os.arch") == "aarch64"
val isMingwX64 = hostOs.startsWith("Windows")
val nativeTarget = when {
hostOs == "Mac OS X" && isArm64 -> macosArm64("native")
hostOs == "Mac OS X" && !isArm64 -> macosX64("native")
hostOs == "Linux" && isArm64 -> linuxArm64("native")
hostOs == "Linux" && !isArm64 -> linuxX64("native")
isMingwX64 -> mingwX64("native")
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
}


sourceSets {
val commonMain by getting {
dependencies {
implementation("org.hisp.dhis.lib.expression:expression-parser:1.1.0-SNAPSHOT")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val jvmMain by getting
val jvmTest by getting {
dependencies {
implementation("io.mockk:mockk:1.13.8")
}
}
val jsMain by getting
val jsTest by getting
val nativeMain by getting
val nativeTest by getting
}
}
20 changes: 20 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
plugins {
`kotlin-dsl`
}

val kotlinVersion = "1.9.21"
val dokkaVersion = "1.9.10"
val nexusPluginVersion = "1.3.0"
val npmPluginVersion = "3.4.1"

repositories {
mavenCentral()
gradlePluginPortal()
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
implementation("org.jetbrains.dokka:dokka-gradle-plugin:${dokkaVersion}")
implementation("io.github.gradle-nexus:publish-plugin:${nexusPluginVersion}")
implementation("dev.petuska:npm-publish-gradle-plugin:${npmPluginVersion}")
}
35 changes: 35 additions & 0 deletions buildSrc/src/main/kotlin/Props.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
object Props {
const val DESCRIPTION = "Rule Engine"

const val REPOSITORY_TYPE = "git"
const val REPOSITORY_SYSTEM = "GitHub"
const val REPOSITORY_URL = "https://github.com/dhis2/dhis2-rule-engine.git"

const val ORGANIZATION_NAME = "UiO"
const val ORGANIZATION_URL = "https://dhis2.org"

const val LICENSE_NAME = "BSD-3-Clause"
const val LICENSE_URL = "https://opensource.org/license/bsd-3-clause/"

val DEVELOPERS = listOf(
Developer(
name = "Enrico Colasante",
email = "[email protected]",
organization = "UiO",
organizationUrl = "https://www.uio.no/"
),
Developer(
name = "Zubair Asghar",
email = "[email protected]",
organization = "UiO",
organizationUrl = "https://www.uio.no/"
),
)
}

data class Developer(
val name: String,
val email: String,
val organization: String,
val organizationUrl: String,
)
76 changes: 76 additions & 0 deletions buildSrc/src/main/kotlin/maven-publish-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
plugins {
`maven-publish`
signing
id("io.github.gradle-nexus.publish-plugin")
id("org.jetbrains.dokka")
}

val ossrhUsername: String? = System.getenv("OSSRH_USERNAME")
val ossrhPassword: String? = System.getenv("OSSRH_PASSWORD")
val signingPrivateKey: String? = System.getenv("SIGNING_PRIVATE_KEY")
val signingPassword: String? = System.getenv("SIGNING_PASSWORD")

val isReleaseVersion = (version as String).contains("SNAPSHOT")

val dokkaHtml = tasks.findByName("dokkaHtml")!!

val dokkaHtmlJar = tasks.register<Jar>("dokkaHtmlJar") {
dependsOn(dokkaHtml)
from(dokkaHtml.outputs)
archiveClassifier.set("docs")
}

publishing {
publications.withType<MavenPublication> {
artifact(dokkaHtmlJar)

pom {
name.set("rule-engine")
description.set(Props.DESCRIPTION)

organization {
name.set(Props.ORGANIZATION_NAME)
url.set(Props.ORGANIZATION_URL)
}
developers {
Props.DEVELOPERS.map {
developer {
name.set(it.name)
email.set(it.email)
organization.set(it.organization)
organizationUrl.set(it.organizationUrl)
}
}
}
licenses {
license {
name.set(Props.LICENSE_NAME)
url.set(Props.LICENSE_URL)
}
}
scm {
url.set("lp:dhis2")
}
issueManagement {
system.set(Props.REPOSITORY_SYSTEM)
url.set(Props.REPOSITORY_URL)
}
url.set(Props.REPOSITORY_URL)
}
}
}

nexusPublishing {
this.repositories {
sonatype {
username.set(ossrhUsername)
password.set(ossrhPassword)
}
}
}

signing {
isRequired = isReleaseVersion
useInMemoryPgpKeys(signingPrivateKey, signingPassword)
sign(publishing.publications)
}
52 changes: 52 additions & 0 deletions buildSrc/src/main/kotlin/npm-publish-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import dev.petuska.npm.publish.extension.domain.NpmAccess

plugins {
id("dev.petuska.npm.publish")
}

val npmjsToken: String? = System.getenv("NPMJS_TOKEN")

project.afterEvaluate {
npmPublish {
access.set(NpmAccess.PUBLIC)
packages {
named("js") {
scope.set("dhis2")
readme.set(File("./README.md"))
packageJson {
"module" by "${project.name}.mjs"
"main" by ""
"exports" by {
"import" by "./${project.name}.mjs"
}
"contributors" by Props.DEVELOPERS.map { developer ->
"${developer.name} <${developer.email}>"
}
"description" by Props.DESCRIPTION
"license" by Props.LICENSE_NAME
"repository" by {
"type" by Props.REPOSITORY_TYPE
"url" by Props.REPOSITORY_URL
}
"publishConfig" by {
"access" by "public"
}
}
}
}
registries {
npmjs {
authToken.set(npmjsToken)
}
}
}

tasks.named("assembleJsPackage") {
doLast {
val file = file("${layout.buildDirectory.get()}/packages/js/package.json")
val mainRegex = "\n \"main\": \"\","
val removedMain = file.readText().replace(mainRegex, "")
file.writeText(removedMain)
}
}
}
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 9cd5390

Please sign in to comment.