From 5df5e3e3a5ae3c7652eb55058e6363062bbef826 Mon Sep 17 00:00:00 2001 From: ssttkkl Date: Thu, 14 Dec 2023 01:53:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E7=89=88=E6=9C=AC=E5=8F=B7?= =?UTF-8?q?=200.6.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-entry-fatjar.yml | 3 +- .github/workflows/dokka-gfm.yml | 3 +- .github/workflows/gradle-publish.yml | 73 +++++++++++-------- .github/workflows/kover-report.yml | 8 +- .../buildlogic/KmpLibConventionPlugin.kt | 11 +-- .../MavenPublishConventionPlugin.kt | 9 ++- build.gradle.kts | 2 +- gradle.properties | 2 +- gradle/libs.versions.toml | 4 +- mahjong-utils-entry/build.gradle.kts | 38 +++++++--- 10 files changed, 94 insertions(+), 59 deletions(-) diff --git a/.github/workflows/build-entry-fatjar.yml b/.github/workflows/build-entry-fatjar.yml index 54a4b6c..07a600b 100644 --- a/.github/workflows/build-entry-fatjar.yml +++ b/.github/workflows/build-entry-fatjar.yml @@ -1,6 +1,7 @@ name: Build WebApi FatJar on: - push: + release: + types: [published] workflow_dispatch: jobs: diff --git a/.github/workflows/dokka-gfm.yml b/.github/workflows/dokka-gfm.yml index 0dfcb24..bfb6dd2 100644 --- a/.github/workflows/dokka-gfm.yml +++ b/.github/workflows/dokka-gfm.yml @@ -1,7 +1,8 @@ name: Build DokkaGfm Documents on: - push: + pull_request: + branches: [main] workflow_dispatch: jobs: diff --git a/.github/workflows/gradle-publish.yml b/.github/workflows/gradle-publish.yml index fa34ff0..6d7998c 100644 --- a/.github/workflows/gradle-publish.yml +++ b/.github/workflows/gradle-publish.yml @@ -9,61 +9,72 @@ name: Publish KMP with Gradle on: release: - types: [created] + types: [published] jobs: - build: + publish: + strategy: + matrix: + os: [ macos-latest, windows-latest, ubuntu-latest ] - runs-on: macos-latest + runs-on: ${{ matrix.os }} permissions: contents: read packages: write + env: + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} + OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} + SIGNING_KEY_ID: ${{ secrets.SIGNING_KEYID }} + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} + SIGNING_SECRET_KEY_RING_FILE: secret_ring.gpg + steps: - uses: actions/checkout@v3 - - name: Set up JDK 11 + + - name: Setup Java JDK uses: actions/setup-java@v3 with: - java-version: '11' - distribution: 'temurin' - server-id: github # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file + distribution: temurin + java-version: 17 + cache: 'gradle' + + - name: Cache Kotlin/Native compiler + id: cache-konan + uses: actions/cache@v3 + with: + path: ~/.konan + key: ${{ runner.os }}-konan - uses: actions/setup-node@v4 - - name: Set up Node.js 22-v8-canary + name: Set up Node.js with: - node-version: '22-v8-canary' + node-version: '21-v8-canary' + registry-url: 'https://registry.npmjs.org' - name: Decode secret_ring.gpg env: SIGNING_SECRET_KEY_RING_BASE64: ${{ secrets.SIGNING_SECRET_KEY_RING_BASE64 }} run: | - echo $SIGNING_SECRET_KEY_RING_BASE64 | base64 --decode > secret_ring.gpg - - - name: Write local.properties - uses: christian-draeger/write-properties@1.1.0 - with: - path: local.properties - # The property keys you want to write. Accepts an array. - property: | - 'ossrhUsername' - 'ossrhPassword' - 'signing.keyId' - 'signing.password' - 'signing.secretKeyRingFile' - # The property values you want to write (same order as the keys). Accepts an array. - value: | - ${{ secrets.OSSRH_USERNAME }} - ${{ secrets.OSSRH_PASSWORD }} - ${{ secrets.SIGNING_KEYID }} - ${{ secrets.SIGNING_PASSWORD }} - 'secret_ring.gpg' + echo $SIGNING_SECRET_KEY_RING_BASE64 | base64 --decode > $SIGNING_SECRET_KEY_RING_FILE - name: Publish mahjong-utils + if: ${{ matrix.os == 'macos-latest' }} + run: | + ./gradlew :mahjong-utils:publishAllPublicationsToSonatypeRepository + + - name: Publish mahjong-utils (linuxX64 only) + if: ${{ matrix.os == 'ubuntu-latest' }} + run: | + ./gradlew :mahjong-utils:publishLinuxX64PublicationToSonatypeRepository + + - name: Publish mahjong-utils (mingwX64 only) + if: ${{ matrix.os == 'windows-latest' }} run: | - ./gradlew :mahjong-utils:publish + ./gradlew :mahjong-utils:publishMingwX64PublicationToSonatypeRepository - name: Publish mahjong-utils-entry for JS/WASM + if: ${{ matrix.os == 'macos-latest' }} run: | ./gradlew :mahjong-utils-entry:publishJsPackageToNpmjsRegistry ./gradlew :mahjong-utils-entry:publishWasmJsPackageToNpmjsRegistry diff --git a/.github/workflows/kover-report.yml b/.github/workflows/kover-report.yml index 41e263a..4a06539 100644 --- a/.github/workflows/kover-report.yml +++ b/.github/workflows/kover-report.yml @@ -19,8 +19,12 @@ jobs: java-version: 17 cache: 'gradle' - - name: Set up Gradle - uses: gradle/gradle-build-action@v2 + - name: Cache Kotlin/Native compiler + id: cache-konan + uses: actions/cache@v3 + with: + path: ~/.konan + key: ${{ runner.os }}-konan - name: Generate Kover Report run: ./gradlew koverXmlReport diff --git a/build-logic/convention/src/main/kotlin/mahjongutils/buildlogic/KmpLibConventionPlugin.kt b/build-logic/convention/src/main/kotlin/mahjongutils/buildlogic/KmpLibConventionPlugin.kt index 00560f3..6aededd 100644 --- a/build-logic/convention/src/main/kotlin/mahjongutils/buildlogic/KmpLibConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/mahjongutils/buildlogic/KmpLibConventionPlugin.kt @@ -18,6 +18,7 @@ class KmpLibConventionPlugin : Plugin { } configure { + applyDefaultHierarchyTemplate() jvmToolchain(11) jvm { @@ -47,21 +48,21 @@ class KmpLibConventionPlugin : Plugin { when { hostOs == "Mac OS X" -> { if (isAarch64) { - macosArm64("native") + macosArm64() } else { - macosX64("native") + macosX64() } } hostOs == "Linux" -> { if (isAarch64) { - linuxArm64("native") + linuxArm64() } else { - linuxX64("native") + linuxX64() } } - isMingwX64 -> mingwX64("native") + isMingwX64 -> mingwX64() else -> throw GradleException("Host OS is not supported in Kotlin/Native.") } diff --git a/build-logic/convention/src/main/kotlin/mahjongutils/buildlogic/MavenPublishConventionPlugin.kt b/build-logic/convention/src/main/kotlin/mahjongutils/buildlogic/MavenPublishConventionPlugin.kt index 362a539..79f7c3b 100644 --- a/build-logic/convention/src/main/kotlin/mahjongutils/buildlogic/MavenPublishConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/mahjongutils/buildlogic/MavenPublishConventionPlugin.kt @@ -47,8 +47,11 @@ class MavenPublishConventionPlugin : Plugin { extra["gprToken"] = System.getenv("GPR_TOKEN") } - val secretKeyRingFile = Path(extra["signing.secretKeyRingFile"].toString()) - extra["signing.secretKeyRingFile"] = rootProject.file(secretKeyRingFile) + val secretKeyRingFile = extra["signing.secretKeyRingFile"]?.toString()?.let { + rootProject.file(it) + }?.also { + extra["signing.secretKeyRingFile"] = it.absoluteFile + } val javadocJar by tasks.registering(Jar::class) { archiveClassifier.set("javadoc") @@ -114,7 +117,7 @@ class MavenPublishConventionPlugin : Plugin { } } - if (secretKeyRingFile.exists()) { + if (secretKeyRingFile?.exists() == true) { // Signing artifacts. Signing.* extra properties values will be used extensions.configure { sign(extensions.getByType().publications) diff --git a/build.gradle.kts b/build.gradle.kts index bbda12f..c43295e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,7 +22,7 @@ tasks.wrapper { rootProject.plugins.withType { rootProject.the().apply { - nodeVersion = "21.0.0-v8-canary20231024d0ddc81258" + nodeVersion = "21.0.0-v8-canary20231019bd785be450" nodeDownloadBaseUrl = "https://nodejs.org/download/v8-canary" } } diff --git a/gradle.properties b/gradle.properties index 5927a9c..6f12617 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ kotlin.code.style=official group=io.github.ssttkkl -version=0.6.0 +version=0.6.1 org.gradle.jvmargs=-Xmx8g -Xms1g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2384f98..bb5d99b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -kotlin = "1.9.20" +kotlin = "1.9.21" kotlinx-coroutines = "1.8.0-RC" kotlinx-serialization = "1.6.2" ktor = "2.3.6" @@ -21,7 +21,7 @@ kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } kotlinx-kover = { id = "org.jetbrains.kotlinx.kover", version = "0.7.3" } -devPetsuka-npmPublish = { id = "dev.petuska.npm.publish", version = "3.2.0" } +devPetsuka-npmPublish = { id = "dev.petuska.npm.publish", version = "3.4.1" } jetbrains-dokka = { id = "org.jetbrains.dokka", version = "1.9.10" } ktor = { id = "io.ktor.plugin", version.ref = "ktor" } diff --git a/mahjong-utils-entry/build.gradle.kts b/mahjong-utils-entry/build.gradle.kts index 70e38a0..7bbf3c9 100644 --- a/mahjong-utils-entry/build.gradle.kts +++ b/mahjong-utils-entry/build.gradle.kts @@ -16,18 +16,6 @@ kotlin { binaries.library() useCommonJs() } - compilations["main"].packageJson { - name = "mahjong-utils-entry" - customField( - "author", mapOf( - "name" to "ssttkkl", - "email" to "huang.wen.long@hotmail.com" - ) - ) - customField( - "license", "MIT" - ) - } } wasmJs { browser { @@ -53,6 +41,10 @@ kotlin { } } + afterEvaluate { + tasks.getByName("assembleWasmJsPackage").dependsOn("compileProductionLibraryKotlinWasmJsOptimize") + } + val hostOs = System.getProperty("os.name") val isMingwX64 = hostOs.startsWith("Windows") val nativeTarget = targets.filterIsInstance().firstOrNull() @@ -98,6 +90,28 @@ kotlin { } npmPublish { + packages { + get("js").apply { + packageJson { + name = "mahjong-utils-entry" + author { + name = "ssttkkl" + email = "huang.wen.long@hotmail.com" + } + license = "MIT" + } + } + get("wasmJs").apply { + packageJson { + name = "mahjong-utils-entry-wasm" + author { + name = "ssttkkl" + email = "huang.wen.long@hotmail.com" + } + license = "MIT" + } + } + } registries { register("npmjs") { uri.set("https://registry.npmjs.org")