Skip to content

Commit f80643c

Browse files
committed
Publications alignment
Setting up remote publications to github packages and to maven central
1 parent cc010be commit f80643c

File tree

6 files changed

+105
-17
lines changed

6 files changed

+105
-17
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,26 @@ jobs:
8585
# Publish snapshot packages. These jobs will only be triggered when the CI is executed on main.
8686
publish_jvm_snapshot_package:
8787
name: Publish JVM snapshot package
88-
if: github.ref == 'refs/heads/main'
88+
if: contains(fromJSON('["refs/heads/main"]'), github.ref)
8989
needs: ci
9090
uses: ./.github/workflows/publish-jvm.yml
9191
permissions:
9292
contents: read
9393
packages: write
9494
with:
9595
snapshot: true
96+
branch: ${{ github.ref_name }}
97+
secrets: inherit
9698

9799
publish_android_snapshot_package:
98100
name: Publish Android snapshot package
99-
if: github.ref == 'refs/heads/main'
101+
if: contains(fromJSON('["refs/heads/main"]'), github.ref)
100102
needs: ci
101103
uses: ./.github/workflows/publish-android.yml
102104
permissions:
103105
contents: read
104106
packages: write
105107
with:
106108
snapshot: true
109+
branch: ${{ github.ref_name }}
110+
secrets: inherit

.github/workflows/publish-android.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ env:
1919

2020
jobs:
2121
publish_android_package:
22-
name: Publish Android Package to Github Packages
22+
name: Publish Android package
2323
runs-on: ubuntu-latest
2424
permissions:
2525
contents: read
@@ -70,7 +70,21 @@ jobs:
7070
echo "PUB_MODE=-PSNAPSHOT" >> $GITHUB_ENV
7171
fi
7272
73-
- name: Gradle Publish Android Package
74-
run: ./gradlew publishAndroidReleasePublicationToGithubPackagesRepository -Pandroid=true ${{ env.PUB_MODE }}
73+
- name: Gradle Publish Android Package to GitHub packages repository
74+
run: ./gradlew publishAndroidReleasePublicationToGithubPackagesRepository -PremotePublication=true -Pandroid=true ${{ env.PUB_MODE }}
7575
env:
7676
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
ORG_GPG_KEY_ID: ${{ secrets.ORG_GPG_KEY_ID }}
78+
ORG_GPG_SUBKEY_ID: ${{ secrets.ORG_GPG_SUBKEY_ID }}
79+
ORG_GPG_PRIVATE_KEY: ${{ secrets.ORG_GPG_PRIVATE_KEY }}
80+
ORG_GPG_PASSPHRASE: ${{ secrets.ORG_GPG_PASSPHRASE }}
81+
82+
- name: Gradle Publish Android Package to Maven Central repository
83+
run: ./gradlew publishAndroidReleasePublicationToMavenCentralRepository -PremotePublication=true -Pandroid=true ${{ env.PUB_MODE }}
84+
env:
85+
ORG_OSSRH_USERNAME: ${{ secrets.ORG_OSSRH_USERNAME }}
86+
ORG_OSSRH_PASSWORD: ${{ secrets.ORG_OSSRH_PASSWORD }}
87+
ORG_GPG_KEY_ID: ${{ secrets.ORG_GPG_KEY_ID }}
88+
ORG_GPG_SUBKEY_ID: ${{ secrets.ORG_GPG_SUBKEY_ID }}
89+
ORG_GPG_PRIVATE_KEY: ${{ secrets.ORG_GPG_PRIVATE_KEY }}
90+
ORG_GPG_PASSPHRASE: ${{ secrets.ORG_GPG_PASSPHRASE }}

.github/workflows/publish-jvm.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,22 @@ jobs:
175175
echo "PUB_MODE=-PSNAPSHOT" >> $GITHUB_ENV
176176
fi
177177
178-
- name: Gradle Publish JVM Package
179-
run: ./gradlew publishJvmPublicationToGithubPackagesRepository -PgithubPublish=true ${{ env.PUB_MODE }}
178+
- name: Gradle Publish JVM Package to GitHub packages repository
179+
run: ./gradlew publishJvmPublicationToGithubPackagesRepository -PremotePublication=true ${{ env.PUB_MODE }}
180180
env:
181181
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
182+
ORG_GPG_KEY_ID: ${{ secrets.ORG_GPG_KEY_ID }}
183+
ORG_GPG_SUBKEY_ID: ${{ secrets.ORG_GPG_SUBKEY_ID }}
184+
ORG_GPG_PRIVATE_KEY: ${{ secrets.ORG_GPG_PRIVATE_KEY }}
185+
ORG_GPG_PASSPHRASE: ${{ secrets.ORG_GPG_PASSPHRASE }}
186+
187+
188+
- name: Gradle Publish JVM Package to Maven Central repository
189+
run: ./gradlew publishJvmPublicationToMavenCentralRepository -PremotePublication=true ${{ env.PUB_MODE }}
190+
env:
191+
ORG_OSSRH_USERNAME: ${{ secrets.ORG_OSSRH_USERNAME }}
192+
ORG_OSSRH_PASSWORD: ${{ secrets.ORG_OSSRH_PASSWORD }}
193+
ORG_GPG_KEY_ID: ${{ secrets.ORG_GPG_KEY_ID }}
194+
ORG_GPG_SUBKEY_ID: ${{ secrets.ORG_GPG_SUBKEY_ID }}
195+
ORG_GPG_PRIVATE_KEY: ${{ secrets.ORG_GPG_PRIVATE_KEY }}
196+
ORG_GPG_PASSPHRASE: ${{ secrets.ORG_GPG_PASSPHRASE }}

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ jobs:
7878
permissions:
7979
contents: read
8080
packages: write
81+
secrets: inherit
8182

8283
publish-android:
8384
name: Publish Android package
@@ -89,6 +90,7 @@ jobs:
8990
permissions:
9091
contents: read
9192
packages: write
93+
secrets: inherit
9294

9395
publish-dokka:
9496
name: Publish documentation

examples/build.gradle.kts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,11 @@ tasks {
5151
register(example, JavaExec::class) {
5252
dependsOn("CompileZenohJNI")
5353
description = "Run the $example example"
54-
mainClass.set("io.zenoh.${example}")
54+
mainClass.set("io.zenoh.$example")
5555
classpath(sourceSets["main"].runtimeClasspath)
5656
val zenohPaths = "../zenoh-jni/target/release"
5757
val defaultJvmArgs = arrayListOf("-Djava.library.path=$zenohPaths")
58-
val loggerLvl = project.findProperty("zenoh.logger")?.toString()
59-
if (loggerLvl != null) {
60-
jvmArgs(defaultJvmArgs + "-Dzenoh.logger=$loggerLvl")
61-
} else {
62-
jvmArgs(defaultJvmArgs)
63-
}
58+
jvmArgs(defaultJvmArgs)
6459
}
6560
}
6661
}

zenoh-java/build.gradle.kts

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ plugins {
2020
id("com.adarshr.test-logger")
2121
id("org.jetbrains.dokka")
2222
`maven-publish`
23+
signing
2324
}
2425

2526
val androidEnabled = project.findProperty("android")?.toString()?.toBoolean() == true
2627
val release = project.findProperty("release")?.toString()?.toBoolean() == true
27-
val githubPublish = project.findProperty("githubPublish")?.toString()?.toBoolean() == true
28+
29+
// If the publication is meant to be done on a remote repository (GitHub packages or Maven central).
30+
// Modifying this property will affect the release workflows!
31+
val isRemotePublication = project.findProperty("remotePublication")?.toString()?.toBoolean() == true
2832

2933
var buildMode = if (release) BuildMode.RELEASE else BuildMode.DEBUG
3034

@@ -74,7 +78,7 @@ kotlin {
7478
}
7579
}
7680
val jvmMain by getting {
77-
if (githubPublish) {
81+
if (isRemotePublication) {
7882
// The line below is intended to load the native libraries that are crosscompiled on GitHub actions when publishing a JVM package.
7983
resources.srcDir("../jni-libs").include("*/**")
8084
} else {
@@ -89,7 +93,39 @@ kotlin {
8993

9094
publishing {
9195
publications.withType<MavenPublication> {
96+
groupId = "org.eclipse.zenoh"
97+
artifactId = "zenoh-java"
9298
version = project.version.toString() + if (project.hasProperty("SNAPSHOT")) "-SNAPSHOT" else ""
99+
100+
pom {
101+
name.set("Zenoh Java")
102+
description.set("The Eclipse Zenoh: Zero Overhead Pub/sub, Store/Query and Compute.")
103+
url.set("https://zenoh.io/")
104+
105+
licenses {
106+
license {
107+
name.set("Eclipse Public License 2.0 OR Apache License 2.0")
108+
url.set("http://www.eclipse.org/legal/epl-2.0")
109+
}
110+
}
111+
developers {
112+
developer {
113+
id.set("ZettaScale")
114+
name.set("ZettaScale Zenoh Team")
115+
email.set("[email protected]")
116+
}
117+
developer {
118+
id.set("DariusIMP")
119+
name.set("Darius Maitia")
120+
email.set("[email protected]")
121+
}
122+
}
123+
scm {
124+
connection.set("scm:git:https://github.com/eclipse-zenoh/zenoh-java.git")
125+
developerConnection.set("scm:git:https://github.com/eclipse-zenoh/zenoh-java.git")
126+
url.set("https://github.com/eclipse-zenoh/zenoh-java")
127+
}
128+
}
93129
}
94130

95131
repositories {
@@ -101,10 +137,32 @@ kotlin {
101137
password = System.getenv("GITHUB_TOKEN")
102138
}
103139
}
140+
maven {
141+
name = "MavenCentral"
142+
url = uri(if (project.hasProperty("SNAPSHOT"))
143+
"https://oss.sonatype.org/content/repositories/snapshots/"
144+
else
145+
"https://oss.sonatype.org/service/local/staging/deploy/maven2/"
146+
)
147+
credentials {
148+
username = System.getenv("ORG_OSSRH_USERNAME")
149+
password = System.getenv("ORG_OSSRH_PASSWORD")
150+
}
151+
}
104152
}
105153
}
106154
}
107155

156+
signing {
157+
isRequired = isRemotePublication
158+
useInMemoryPgpKeys(System.getenv("ORG_GPG_SUBKEY_ID"), System.getenv("ORG_GPG_PRIVATE_KEY"), System.getenv("ORG_GPG_PASSPHRASE"))
159+
sign(publishing.publications)
160+
}
161+
162+
tasks.withType<PublishToMavenRepository>().configureEach {
163+
dependsOn(tasks.withType<Sign>())
164+
}
165+
108166
tasks.withType<Test> {
109167
doFirst {
110168
// The line below is added for the Android Unit tests which are equivalent to the JVM tests.
@@ -125,7 +183,7 @@ tasks.named("compileKotlinJvm") {
125183

126184
tasks.register("buildZenohJni") {
127185
doLast {
128-
if (!githubPublish) {
186+
if (!isRemotePublication) {
129187
// This is intended for local publications. For publications done through GitHub workflows,
130188
// the zenoh-jni build is achieved and loaded differently from the CI
131189
buildZenohJNI(buildMode)

0 commit comments

Comments
 (0)