Skip to content

Commit 17a66a7

Browse files
committed
sonatype publishing
1 parent a309b06 commit 17a66a7

2 files changed

Lines changed: 80 additions & 28 deletions

File tree

.github/workflows/publish-release-from-tag.yml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,30 @@ jobs:
136136
env:
137137
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
138138
- name: Publish to Sonatype
139-
run: |
140-
echo "TODO!"
139+
run: |-
140+
if [ -z "$SONATYPE_USERNAME" ]; then
141+
echo "Error: SONATYPE_USERNAME is not set"
142+
exit 1
143+
fi
144+
if [ -z "$SONATYPE_PASSWORD" ]; then
145+
echo "Error: SONATYPE_PASSWORD is not set"
146+
exit 1
147+
fi
148+
if [ -z "$GPG_SIGNING_KEY" ]; then
149+
echo "Error: GPG_SIGNING_KEY is not set"
150+
exit 1
151+
fi
152+
if [ -z "$GPG_SIGNING_PASSWORD" ]; then
153+
echo "Error: GPG_SIGNING_PASSWORD is not set"
154+
exit 1
155+
fi
156+
echo "All required credentials are set"
157+
export -- GPG_SIGNING_KEY_ID
158+
printenv -- GPG_SIGNING_KEY | gpg --batch --passphrase-fd 3 --import 3<<< "$GPG_SIGNING_PASSWORD"
159+
GPG_SIGNING_KEY_ID="$(gpg --with-colons --list-keys | awk -F : -- '/^pub:/ { getline; print "0x" substr($10, length($10) - 7) }')"
160+
./gradlew publishAndReleaseToMavenCentral --stacktrace -PmavenCentralUsername="$SONATYPE_USERNAME" -PmavenCentralPassword="$SONATYPE_PASSWORD" --no-configuration-cache
161+
env:
162+
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
163+
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
164+
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
165+
GPG_SIGNING_PASSWORD: ${{ secrets.GPG_SIGNING_PASSWORD }}

build.gradle

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
plugins {
22
id 'java-library'
33
id 'maven-publish'
4+
id 'signing'
45
id 'com.diffplug.spotless' version '6.25.0'
56
id 'io.freefair.lombok' version '9.0.0-rc2'
7+
id 'com.vanniktech.maven.publish' version '0.28.0'
68
id 'idea'
79
id 'eclipse'
810
}
@@ -29,8 +31,6 @@ java {
2931
languageVersion = JavaLanguageVersion.of(17)
3032
vendor = JvmVendorSpec.ADOPTIUM // eclipse JVM
3133
}
32-
withJavadocJar()
33-
withSourcesJar()
3434
}
3535

3636
tasks.withType(JavaCompile).configureEach {
@@ -224,32 +224,59 @@ jar {
224224
}
225225
}
226226

227-
publishing {
228-
publications {
229-
maven(MavenPublication) {
230-
from components.java
231-
232-
pom {
233-
name = 'Braintrust Java SDK'
234-
description = 'OpenTelemetry-based Braintrust SDK for Java'
235-
url = 'https://github.com/braintrustdata/braintrust-x-java'
236-
237-
licenses {
238-
license {
239-
name = 'MIT License'
240-
url = 'https://opensource.org/licenses/MIT'
241-
}
242-
}
243-
244-
developers {
245-
developer {
246-
id = 'braintrust'
247-
name = 'Braintrust Team'
248-
email = 'support@braintrust.dev'
249-
}
250-
}
227+
import com.vanniktech.maven.publish.JavadocJar
228+
import com.vanniktech.maven.publish.JavaLibrary
229+
import com.vanniktech.maven.publish.SonatypeHost
230+
231+
def signingKey = System.getenv("GPG_SIGNING_KEY")
232+
def signingKeyId = System.getenv("GPG_SIGNING_KEY_ID")
233+
def signingPassword = System.getenv("GPG_SIGNING_PASSWORD")
234+
235+
if (signingKey != null && signingKeyId != null && signingPassword != null) {
236+
ext["signingInMemoryKey"] = signingKey
237+
ext["signingInMemoryKeyId"] = signingKeyId
238+
ext["signingInMemoryKeyPassword"] = signingPassword
239+
}
240+
241+
mavenPublishing {
242+
if (signingKey != null && signingKeyId != null && signingPassword != null) {
243+
signAllPublications()
244+
}
245+
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
246+
247+
coordinates(group.toString(), 'braintrust-sdk-java', version.toString())
248+
configure(
249+
new JavaLibrary(
250+
new JavadocJar.Javadoc(),
251+
true
252+
)
253+
)
254+
255+
pom {
256+
name = 'Braintrust Java SDK'
257+
description = 'Braintrust SDK for logs and evals in Java'
258+
url = 'https://github.com/braintrustdata/braintrust-sdk-java'
259+
260+
licenses {
261+
license {
262+
name = 'MIT License'
263+
url = 'https://opensource.org/licenses/MIT'
251264
}
252265
}
266+
267+
developers {
268+
developer {
269+
id = 'braintrust'
270+
name = 'Braintrust Team'
271+
email = 'info@braintrust.dev'
272+
}
273+
}
274+
275+
scm {
276+
connection = 'scm:git:git://github.com/braintrustdata/braintrust-sdk-java.git'
277+
developerConnection = 'scm:git:git://github.com/braintrustdata/braintrust-sdk-java.git'
278+
url = 'https://github.com/braintrustdata/braintrust-sdk-java'
279+
}
253280
}
254281
}
255282

0 commit comments

Comments
 (0)