From 207368ad2d8d4acbced8fbbcd92d120f062a5547 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Wed, 26 Apr 2023 11:27:48 +0900 Subject: [PATCH 1/5] ci: add build, test and deployment to maven --- .github/workflows/build-test.yml | 45 +++++++++++ .github/workflows/tag.yml | 40 +++++++++ ...a.sdk.kotlin-common-conventions.gradle.kts | 14 ++++ ....sdk.kotlin-library-conventions.gradle.kts | 2 + crypto/build.gradle.kts | 80 ++++++++++++++++++ tx/build.gradle.kts | 81 +++++++++++++++++++ 6 files changed, 262 insertions(+) create mode 100644 .github/workflows/build-test.yml create mode 100644 .github/workflows/tag.yml diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml new file mode 100644 index 0000000..e220124 --- /dev/null +++ b/.github/workflows/build-test.yml @@ -0,0 +1,45 @@ +name: Build project +on: + pull_request: +jobs: + build: + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 8 + + - name: Gradle Cache + uses: burrunan/gradle-cache-action@v1 + + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + + - name: Execute Gradle build + run: ./gradlew build + + - name: Run Test + run: ./gradlew test + + - name: Run Coverage + run: ./gradlew jacocoTestReport + - name: Run ss + run: | + pwd + cd ${{ github.workspace }} + echo "/app/build/reports/jacoco/test/" + ls ${{ github.workspace }}/app/build/reports/jacoco/test/ + +# - name: Add coverage to PR +# id: jacoco +# uses: madrapps/jacoco-report@v1.3 +# with: +# paths: ${{ github.workspace }}/app/build/reports/jacoco/test/jacocoTestReport.xml +# token: ${{ secrets.GITHUB_TOKEN }} +# min-coverage-overall: 10 +# min-coverage-changed-files: 10 diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml new file mode 100644 index 0000000..0583026 --- /dev/null +++ b/.github/workflows/tag.yml @@ -0,0 +1,40 @@ +name: Publish package to Maven Central Repository +on: + push: + # Sequence of patterns matched against refs/tags + tags: + - "v[0-9]+.[0-9]+.[0-9]+" # Push events to matching v*, i.e. v1.0, v20.15.10 +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Java + uses: actions/setup-java@v3 + with: + java-version: 8 + distribution: temurin + + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3 + + - name: Import signing key + id: import_gpg + uses: crazy-max/ghaction-import-gpg@v5.2.0 + with: + gpg_private_key: ${{ secrets.OSSRH_SIGNING_KEY }} + passphrase: ${{ secrets.OSSRH_PHRASE }} + + - name: List keys + run: gpg -K + + - name: Publish to maven + env: + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} + OSSRH_PW: ${{ secrets.OSSRH_PW }} + ORG_GRADLE_PROJECT_signingKey: ${{ secrets.OSSRH_SIGNING_KEY }} + ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.OSSRH_PASSPHRASE }} + RELEASE_VERSION: ${{ github.ref_name }} + run: | + echo $RELEASE_VERSION + ./gradlew publish -DVERSION=$RELEASE_VERSION diff --git a/buildSrc/src/main/kotlin/network.finschia.sdk.kotlin-common-conventions.gradle.kts b/buildSrc/src/main/kotlin/network.finschia.sdk.kotlin-common-conventions.gradle.kts index 37f2f84..f50a777 100644 --- a/buildSrc/src/main/kotlin/network.finschia.sdk.kotlin-common-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/network.finschia.sdk.kotlin-common-conventions.gradle.kts @@ -1,11 +1,13 @@ plugins { // Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin. id("org.jetbrains.kotlin.jvm") + jacoco } repositories { // Use Maven Central for resolving dependencies. mavenCentral() + gradlePluginPortal() } dependencies { @@ -30,3 +32,15 @@ tasks.test { // Use JUnit Platform for unit tests. useJUnitPlatform() } + +tasks.jacocoTestReport { + dependsOn(tasks.test) // tests are required to run before generating the report +} + +tasks.jacocoTestReport { + reports { + xml.required.set(true) + csv.required.set(true) + html.outputLocation.set(layout.buildDirectory.dir("jacocoHtml")) + } +} diff --git a/buildSrc/src/main/kotlin/network.finschia.sdk.kotlin-library-conventions.gradle.kts b/buildSrc/src/main/kotlin/network.finschia.sdk.kotlin-library-conventions.gradle.kts index 3e297aa..16a4a2d 100644 --- a/buildSrc/src/main/kotlin/network.finschia.sdk.kotlin-library-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/network.finschia.sdk.kotlin-library-conventions.gradle.kts @@ -8,4 +8,6 @@ plugins { // Apply the java-library plugin for API and implementation separation. `java-library` + `maven-publish` + signing } diff --git a/crypto/build.gradle.kts b/crypto/build.gradle.kts index 226526d..2fbeab6 100644 --- a/crypto/build.gradle.kts +++ b/crypto/build.gradle.kts @@ -2,6 +2,7 @@ plugins { id("network.finschia.sdk.kotlin-library-conventions") } +// Dependency versions val guavaVersion = "28.1-jre" val commonsIOVersion = "2.6" val bouncycastleVersion = "1.64" @@ -34,5 +35,84 @@ dependencies { testImplementation("org.junit.jupiter:junit-jupiter-api:$jupiterVersion") testImplementation("org.junit.jupiter:junit-jupiter-params:$jupiterVersion") testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$jupiterVersion") +} + +java{ + withJavadocJar() + withSourcesJar() +} + +tasks.javadoc { + if (JavaVersion.current().isJava9Compatible) { + (options as StandardJavadocDocletOptions).addBooleanOption("html5", true) + } +} + +// Maven artifact +val groupIdVal = "io.github.finschia" +val artifactIdVal = "finschia-kt-crypto" +val versionVal: String? = System.getProperty("VERSION") + +// Maven pom info +val pomName = "finschia" +val pomDesc = artifactIdVal +val pomUrl = "https://github.com/Finschia/finschia-kt" +val pomScmConnection = "scm:git:git://github.com/Finschia/finschia-kt.git" +val pomDeveloperConnection = "scm:git:ssh://github.com/Finschia/finschia-kt.git" +val pomScmUrl = "https://github.com/Finschia/finschia-kt" + +// Maven account +val ossrhUserName = System.getenv("OSSRH_USERNAME") +val ossrhPassword = System.getenv("OSSRH_PW") + +publishing { + publications { + create("mavenJava") { + groupId = groupIdVal + artifactId = artifactIdVal + version = versionVal?.substring(1) // without v + + from(components["java"]) + pom { + name.set(pomName) + description.set(pomDesc) + url.set(pomUrl) + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") + } + } + developers { + developer { + id.set("dev") + name.set("dev") + email.set("dev@finschia.org") + } + } + scm { + connection.set(pomScmConnection) + developerConnection.set(pomDeveloperConnection) + url.set(pomScmUrl) + } + } + } + } + repositories { + maven { + name = "OSSRH" + url = uri("https://s01.oss.sonatype.org/content/repositories/releases/") + credentials { + username = ossrhUserName + password = ossrhPassword + } + } + } +} +signing { + val signingKey: String? by project + val signingPassword: String? by project + useInMemoryPgpKeys(signingKey, signingPassword) + sign(publishing.publications["mavenJava"]) } diff --git a/tx/build.gradle.kts b/tx/build.gradle.kts index 80c5c17..11e2b4b 100644 --- a/tx/build.gradle.kts +++ b/tx/build.gradle.kts @@ -3,6 +3,7 @@ plugins { kotlin("plugin.serialization") version "1.5.30" } +// Dependency versions val bitcoinjVersion = "0.15.6" val kotlinxVersion = "1.2.0" @@ -13,3 +14,83 @@ dependencies { implementation("org.bitcoinj:bitcoinj-core:$bitcoinjVersion") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxVersion") } + +java{ + withJavadocJar() + withSourcesJar() +} + +tasks.javadoc { + if (JavaVersion.current().isJava9Compatible) { + (options as StandardJavadocDocletOptions).addBooleanOption("html5", true) + } +} + +// Maven artifact +val groupIdVal = "io.github.finschia" +val artifactIdVal = "finschia-kt-tx" +val versionVal: String? = System.getProperty("VERSION") + +// Maven pom info +val pomName = "finschia" +val pomDesc = artifactIdVal +val pomUrl = "https://github.com/Finschia/finschia-kt" +val pomScmConnection = "scm:git:git://github.com/Finschia/finschia-kt.git" +val pomDeveloperConnection = "scm:git:ssh://github.com/Finschia/finschia-kt.git" +val pomScmUrl = "https://github.com/Finschia/finschia-kt" + +// Maven account +val ossrhUserName = System.getenv("OSSRH_USERNAME") +val ossrhPassword = System.getenv("OSSRH_PW") + +publishing { + publications { + create("mavenJava") { + groupId = groupIdVal + artifactId = artifactIdVal + version = versionVal?.substring(1) // without v + + from(components["java"]) + pom { + name.set(pomName) + description.set(pomDesc) + url.set(pomUrl) + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") + } + } + developers { + developer { + id.set("dev") + name.set("dev") + email.set("dev@finschia.org") + } + } + scm { + connection.set(pomScmConnection) + developerConnection.set(pomDeveloperConnection) + url.set(pomScmUrl) + } + } + } + } + repositories { + maven { + name = "OSSRH" + url = uri("https://s01.oss.sonatype.org/content/repositories/releases/") + credentials { + username = ossrhUserName + password = ossrhPassword + } + } + } +} + +signing { + val signingKey: String? by project + val signingPassword: String? by project + useInMemoryPgpKeys(signingKey, signingPassword) + sign(publishing.publications["mavenJava"]) +} From 583c1fe3d7b5591b1a91e490a5c6d9ffcb994d9c Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Wed, 26 Apr 2023 11:41:08 +0900 Subject: [PATCH 2/5] chore: update changelog --- .github/workflows/build-test.yml | 18 ------------------ CHANGELOG.md | 1 + 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index e220124..b317a77 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -25,21 +25,3 @@ jobs: - name: Run Test run: ./gradlew test - - - name: Run Coverage - run: ./gradlew jacocoTestReport - - name: Run ss - run: | - pwd - cd ${{ github.workspace }} - echo "/app/build/reports/jacoco/test/" - ls ${{ github.workspace }}/app/build/reports/jacoco/test/ - -# - name: Add coverage to PR -# id: jacoco -# uses: madrapps/jacoco-report@v1.3 -# with: -# paths: ${{ github.workspace }}/app/build/reports/jacoco/test/jacocoTestReport.xml -# token: ${{ secrets.GITHUB_TOKEN }} -# min-coverage-overall: 10 -# min-coverage-changed-files: 10 diff --git a/CHANGELOG.md b/CHANGELOG.md index c6c44e2..b8bbe89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Changed * [\#6](https://github.com/Finschia/finschia-kt/pull/6) Rename package 'ln.v2' -> 'sdk' +* (ci) [\#11](https://github.com/Finschia/finschia-kt/pull/11) Add ci/cd to publish to maven ### Deprecated From 9cf052a660fabcaed9ba0eb8e96ce665ffe21732 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Thu, 27 Apr 2023 11:54:48 +0900 Subject: [PATCH 3/5] chore: move maven definition to publishing block --- crypto/build.gradle.kts | 32 ++++++++++++++++---------------- tx/build.gradle.kts | 33 ++++++++++++++++----------------- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/crypto/build.gradle.kts b/crypto/build.gradle.kts index 2fbeab6..be7da2e 100644 --- a/crypto/build.gradle.kts +++ b/crypto/build.gradle.kts @@ -37,7 +37,7 @@ dependencies { testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$jupiterVersion") } -java{ +java { withJavadocJar() withSourcesJar() } @@ -48,24 +48,24 @@ tasks.javadoc { } } -// Maven artifact -val groupIdVal = "io.github.finschia" -val artifactIdVal = "finschia-kt-crypto" -val versionVal: String? = System.getProperty("VERSION") +publishing { + // Maven artifact + val groupIdVal = "io.github.finschia" + val artifactIdVal = "finschia-kt-crypto" + val versionVal: String? = System.getProperty("VERSION") -// Maven pom info -val pomName = "finschia" -val pomDesc = artifactIdVal -val pomUrl = "https://github.com/Finschia/finschia-kt" -val pomScmConnection = "scm:git:git://github.com/Finschia/finschia-kt.git" -val pomDeveloperConnection = "scm:git:ssh://github.com/Finschia/finschia-kt.git" -val pomScmUrl = "https://github.com/Finschia/finschia-kt" + // Maven pom info + val pomName = "finschia" + val pomDesc = artifactIdVal + val pomUrl = "https://github.com/Finschia/finschia-kt" + val pomScmConnection = "scm:git:git://github.com/Finschia/finschia-kt.git" + val pomDeveloperConnection = "scm:git:ssh://github.com/Finschia/finschia-kt.git" + val pomScmUrl = "https://github.com/Finschia/finschia-kt" -// Maven account -val ossrhUserName = System.getenv("OSSRH_USERNAME") -val ossrhPassword = System.getenv("OSSRH_PW") + // Maven account + val ossrhUserName = System.getenv("OSSRH_USERNAME") + val ossrhPassword = System.getenv("OSSRH_PW") -publishing { publications { create("mavenJava") { groupId = groupIdVal diff --git a/tx/build.gradle.kts b/tx/build.gradle.kts index 11e2b4b..2d1760d 100644 --- a/tx/build.gradle.kts +++ b/tx/build.gradle.kts @@ -15,7 +15,7 @@ dependencies { implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxVersion") } -java{ +java { withJavadocJar() withSourcesJar() } @@ -25,25 +25,24 @@ tasks.javadoc { (options as StandardJavadocDocletOptions).addBooleanOption("html5", true) } } +publishing { + // Maven artifact + val groupIdVal = "io.github.finschia" + val artifactIdVal = "finschia-kt-tx" + val versionVal: String? = System.getProperty("VERSION") -// Maven artifact -val groupIdVal = "io.github.finschia" -val artifactIdVal = "finschia-kt-tx" -val versionVal: String? = System.getProperty("VERSION") - -// Maven pom info -val pomName = "finschia" -val pomDesc = artifactIdVal -val pomUrl = "https://github.com/Finschia/finschia-kt" -val pomScmConnection = "scm:git:git://github.com/Finschia/finschia-kt.git" -val pomDeveloperConnection = "scm:git:ssh://github.com/Finschia/finschia-kt.git" -val pomScmUrl = "https://github.com/Finschia/finschia-kt" + // Maven pom info + val pomName = "finschia" + val pomDesc = artifactIdVal + val pomUrl = "https://github.com/Finschia/finschia-kt" + val pomScmConnection = "scm:git:git://github.com/Finschia/finschia-kt.git" + val pomDeveloperConnection = "scm:git:ssh://github.com/Finschia/finschia-kt.git" + val pomScmUrl = "https://github.com/Finschia/finschia-kt" -// Maven account -val ossrhUserName = System.getenv("OSSRH_USERNAME") -val ossrhPassword = System.getenv("OSSRH_PW") + // Maven account + val ossrhUserName = System.getenv("OSSRH_USERNAME") + val ossrhPassword = System.getenv("OSSRH_PW") -publishing { publications { create("mavenJava") { groupId = groupIdVal From 3c2893c11b7c66d1bd83bb6296aeeaea2de9c171 Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Thu, 27 Apr 2023 13:45:27 +0900 Subject: [PATCH 4/5] chore: change regex for tag to include tags like v1.0, v1.0.0-rc1 --- .github/workflows/tag.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index 0583026..abc0f6d 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -3,7 +3,7 @@ on: push: # Sequence of patterns matched against refs/tags tags: - - "v[0-9]+.[0-9]+.[0-9]+" # Push events to matching v*, i.e. v1.0, v20.15.10 + - "v[0-9]+(.[0-9]+)?.[0-9]+(-rc[0-9]+)?" # Matching i.e. v1.0, v20.15.10, v1.0-rc1, v1.0.0-rc2 jobs: publish: runs-on: ubuntu-latest From 537840a5f0969aeaaab9edd89289c314032d53de Mon Sep 17 00:00:00 2001 From: "jaeseung.bae" Date: Thu, 27 Apr 2023 14:41:14 +0900 Subject: [PATCH 5/5] chore: correct regex for semantic versioning --- .github/workflows/tag.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index abc0f6d..48ee151 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -3,7 +3,8 @@ on: push: # Sequence of patterns matched against refs/tags tags: - - "v[0-9]+(.[0-9]+)?.[0-9]+(-rc[0-9]+)?" # Matching i.e. v1.0, v20.15.10, v1.0-rc1, v1.0.0-rc2 + - "v[0-9]+.[0-9]+.[0-9]+" # Matching i.e. v1.0.0, v20.15.10 + - "v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+" # Matching i.e. v1.0.0-rc1, v20.15.10-rc0 jobs: publish: runs-on: ubuntu-latest