diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fabf2b7..0b18673 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,7 +85,7 @@ jobs: # Publish snapshot packages. These jobs will only be triggered when the CI is executed on main. publish_jvm_snapshot_package: name: Publish JVM snapshot package - if: github.ref == 'refs/heads/main' + if: contains(fromJSON('["refs/heads/main"]'), github.ref) needs: ci uses: ./.github/workflows/publish-jvm.yml permissions: @@ -93,10 +93,12 @@ jobs: packages: write with: snapshot: true + branch: ${{ github.ref_name }} + secrets: inherit publish_android_snapshot_package: name: Publish Android snapshot package - if: github.ref == 'refs/heads/main' + if: contains(fromJSON('["refs/heads/main"]'), github.ref) needs: ci uses: ./.github/workflows/publish-android.yml permissions: @@ -104,3 +106,5 @@ jobs: packages: write with: snapshot: true + branch: ${{ github.ref_name }} + secrets: inherit diff --git a/.github/workflows/publish-android.yml b/.github/workflows/publish-android.yml index 1dd37a4..d3effc7 100644 --- a/.github/workflows/publish-android.yml +++ b/.github/workflows/publish-android.yml @@ -19,7 +19,7 @@ env: jobs: publish_android_package: - name: Publish Android Package to Github Packages + name: Publish Android package runs-on: ubuntu-latest permissions: contents: read @@ -70,7 +70,21 @@ jobs: echo "PUB_MODE=-PSNAPSHOT" >> $GITHUB_ENV fi - - name: Gradle Publish Android Package - run: ./gradlew publishAndroidReleasePublicationToGithubPackagesRepository -Pandroid=true ${{ env.PUB_MODE }} + - name: Gradle Publish Android Package to GitHub packages repository + run: ./gradlew publishAndroidReleasePublicationToGithubPackagesRepository -PremotePublication=true -Pandroid=true ${{ env.PUB_MODE }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ORG_GPG_KEY_ID: ${{ secrets.ORG_GPG_KEY_ID }} + ORG_GPG_SUBKEY_ID: ${{ secrets.ORG_GPG_SUBKEY_ID }} + ORG_GPG_PRIVATE_KEY: ${{ secrets.ORG_GPG_PRIVATE_KEY }} + ORG_GPG_PASSPHRASE: ${{ secrets.ORG_GPG_PASSPHRASE }} + + - name: Gradle Publish Android Package to Maven Central repository + run: ./gradlew publishAndroidReleasePublicationToMavenCentralRepository -PremotePublication=true -Pandroid=true ${{ env.PUB_MODE }} + env: + ORG_OSSRH_USERNAME: ${{ secrets.ORG_OSSRH_USERNAME }} + ORG_OSSRH_PASSWORD: ${{ secrets.ORG_OSSRH_PASSWORD }} + ORG_GPG_KEY_ID: ${{ secrets.ORG_GPG_KEY_ID }} + ORG_GPG_SUBKEY_ID: ${{ secrets.ORG_GPG_SUBKEY_ID }} + ORG_GPG_PRIVATE_KEY: ${{ secrets.ORG_GPG_PRIVATE_KEY }} + ORG_GPG_PASSPHRASE: ${{ secrets.ORG_GPG_PASSPHRASE }} diff --git a/.github/workflows/publish-jvm.yml b/.github/workflows/publish-jvm.yml index 3fbb1cb..b2378a7 100644 --- a/.github/workflows/publish-jvm.yml +++ b/.github/workflows/publish-jvm.yml @@ -175,7 +175,22 @@ jobs: echo "PUB_MODE=-PSNAPSHOT" >> $GITHUB_ENV fi - - name: Gradle Publish JVM Package - run: ./gradlew publishJvmPublicationToGithubPackagesRepository -PgithubPublish=true ${{ env.PUB_MODE }} + - name: Gradle Publish JVM Package to GitHub packages repository + run: ./gradlew publishJvmPublicationToGithubPackagesRepository -PremotePublication=true ${{ env.PUB_MODE }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ORG_GPG_KEY_ID: ${{ secrets.ORG_GPG_KEY_ID }} + ORG_GPG_SUBKEY_ID: ${{ secrets.ORG_GPG_SUBKEY_ID }} + ORG_GPG_PRIVATE_KEY: ${{ secrets.ORG_GPG_PRIVATE_KEY }} + ORG_GPG_PASSPHRASE: ${{ secrets.ORG_GPG_PASSPHRASE }} + + + - name: Gradle Publish JVM Package to Maven Central repository + run: ./gradlew publishJvmPublicationToMavenCentralRepository -PremotePublication=true ${{ env.PUB_MODE }} + env: + ORG_OSSRH_USERNAME: ${{ secrets.ORG_OSSRH_USERNAME }} + ORG_OSSRH_PASSWORD: ${{ secrets.ORG_OSSRH_PASSWORD }} + ORG_GPG_KEY_ID: ${{ secrets.ORG_GPG_KEY_ID }} + ORG_GPG_SUBKEY_ID: ${{ secrets.ORG_GPG_SUBKEY_ID }} + ORG_GPG_PRIVATE_KEY: ${{ secrets.ORG_GPG_PRIVATE_KEY }} + ORG_GPG_PASSPHRASE: ${{ secrets.ORG_GPG_PASSPHRASE }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cb57c91..bca02dc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -78,6 +78,7 @@ jobs: permissions: contents: read packages: write + secrets: inherit publish-android: name: Publish Android package @@ -89,6 +90,7 @@ jobs: permissions: contents: read packages: write + secrets: inherit publish-dokka: name: Publish documentation diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index 683709d..9de1441 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -51,16 +51,11 @@ tasks { register(example, JavaExec::class) { dependsOn("CompileZenohJNI") description = "Run the $example example" - mainClass.set("io.zenoh.${example}") + mainClass.set("io.zenoh.$example") classpath(sourceSets["main"].runtimeClasspath) val zenohPaths = "../zenoh-jni/target/release" val defaultJvmArgs = arrayListOf("-Djava.library.path=$zenohPaths") - val loggerLvl = project.findProperty("zenoh.logger")?.toString() - if (loggerLvl != null) { - jvmArgs(defaultJvmArgs + "-Dzenoh.logger=$loggerLvl") - } else { - jvmArgs(defaultJvmArgs) - } + jvmArgs(defaultJvmArgs) } } } diff --git a/zenoh-java/build.gradle.kts b/zenoh-java/build.gradle.kts index d97ff9e..5ad5203 100644 --- a/zenoh-java/build.gradle.kts +++ b/zenoh-java/build.gradle.kts @@ -20,11 +20,15 @@ plugins { id("com.adarshr.test-logger") id("org.jetbrains.dokka") `maven-publish` + signing } val androidEnabled = project.findProperty("android")?.toString()?.toBoolean() == true val release = project.findProperty("release")?.toString()?.toBoolean() == true -val githubPublish = project.findProperty("githubPublish")?.toString()?.toBoolean() == true + +// If the publication is meant to be done on a remote repository (GitHub packages or Maven central). +// Modifying this property will affect the release workflows! +val isRemotePublication = project.findProperty("remotePublication")?.toString()?.toBoolean() == true var buildMode = if (release) BuildMode.RELEASE else BuildMode.DEBUG @@ -74,7 +78,7 @@ kotlin { } } val jvmMain by getting { - if (githubPublish) { + if (isRemotePublication) { // The line below is intended to load the native libraries that are crosscompiled on GitHub actions when publishing a JVM package. resources.srcDir("../jni-libs").include("*/**") } else { @@ -89,7 +93,39 @@ kotlin { publishing { publications.withType { + groupId = "org.eclipse.zenoh" + artifactId = "zenoh-java" version = project.version.toString() + if (project.hasProperty("SNAPSHOT")) "-SNAPSHOT" else "" + + pom { + name.set("Zenoh Java") + description.set("The Eclipse Zenoh: Zero Overhead Pub/sub, Store/Query and Compute.") + url.set("https://zenoh.io/") + + licenses { + license { + name.set("Eclipse Public License 2.0 OR Apache License 2.0") + url.set("http://www.eclipse.org/legal/epl-2.0") + } + } + developers { + developer { + id.set("ZettaScale") + name.set("ZettaScale Zenoh Team") + email.set("zenoh@zettascale.tech") + } + developer { + id.set("DariusIMP") + name.set("Darius Maitia") + email.set("darius@zettascale.tech") + } + } + scm { + connection.set("scm:git:https://github.com/eclipse-zenoh/zenoh-java.git") + developerConnection.set("scm:git:https://github.com/eclipse-zenoh/zenoh-java.git") + url.set("https://github.com/eclipse-zenoh/zenoh-java") + } + } } repositories { @@ -101,10 +137,32 @@ kotlin { password = System.getenv("GITHUB_TOKEN") } } + maven { + name = "MavenCentral" + url = uri(if (project.hasProperty("SNAPSHOT")) + "https://oss.sonatype.org/content/repositories/snapshots/" + else + "https://oss.sonatype.org/service/local/staging/deploy/maven2/" + ) + credentials { + username = System.getenv("ORG_OSSRH_USERNAME") + password = System.getenv("ORG_OSSRH_PASSWORD") + } + } } } } +signing { + isRequired = isRemotePublication + useInMemoryPgpKeys(System.getenv("ORG_GPG_SUBKEY_ID"), System.getenv("ORG_GPG_PRIVATE_KEY"), System.getenv("ORG_GPG_PASSPHRASE")) + sign(publishing.publications) +} + +tasks.withType().configureEach { + dependsOn(tasks.withType()) +} + tasks.withType { doFirst { // The line below is added for the Android Unit tests which are equivalent to the JVM tests. @@ -125,7 +183,7 @@ tasks.named("compileKotlinJvm") { tasks.register("buildZenohJni") { doLast { - if (!githubPublish) { + if (!isRemotePublication) { // This is intended for local publications. For publications done through GitHub workflows, // the zenoh-jni build is achieved and loaded differently from the CI buildZenohJNI(buildMode)