Skip to content

Commit 3bc07bd

Browse files
authored
add github action for version releases to Sonatype (#996)
What changed? added a github action release.yaml on push-tag and manual triggers (For safety, currently it's only auto-push-to-staging-and-close mode and requires manual release on sonatype) added gralde nexus plugin bump version to 3.12.7-SNAPSHOT Plan: after it's tested against some version upgrade, we can switch mode to auto-release Why? Releasing requires PGP key access + sonatype access. These overheads slow down the release process How did you test it? Tested nexus plugin locally on staging repository Test with act locally act -j release --secret-file dummy ... [Release to Maven Central/release] ✅ Success - Main Publish to Sonatype OSSRH (Maven Central) [2m0.223553458s] [Release to Maven Central/release] ⭐ Run Complete job [Release to Maven Central/release] Cleaning up container for job release [Release to Maven Central/release] ✅ Success - Complete job [Release to Maven Central/release] 🏁 Job succeeded Screenshot 2025-05-01 at 3 12 35 PM
1 parent b62c91b commit 3bc07bd

File tree

3 files changed

+99
-9
lines changed

3 files changed

+99
-9
lines changed

.github/workflows/release.yml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Release to Maven Central
2+
3+
on:
4+
# Manual trigger
5+
workflow_dispatch:
6+
inputs:
7+
release_version:
8+
description: 'Version to release (if empty, derive from project version)'
9+
required: false
10+
# Automatic trigger on pushing a version tag (e.g., "v1.2.3")
11+
push:
12+
tags:
13+
- 'v*'
14+
15+
jobs:
16+
release:
17+
runs-on: ubuntu-latest
18+
container:
19+
image: adoptopenjdk/openjdk11:jdk-11.0.10_9
20+
steps:
21+
- name: Check out code
22+
uses: actions/checkout@v3
23+
24+
- name: Install necessary tooling
25+
env:
26+
APACHE_THRIFT_VERSION: 0.9.3
27+
run: |
28+
apt-get update &&apt-get install -y wget gcc make build-essential git
29+
30+
wget https://archive.apache.org/dist/thrift/${APACHE_THRIFT_VERSION}/thrift-${APACHE_THRIFT_VERSION}.tar.gz && \
31+
tar -xvf thrift-${APACHE_THRIFT_VERSION}.tar.gz && \
32+
rm thrift-${APACHE_THRIFT_VERSION}.tar.gz && \
33+
cd thrift-${APACHE_THRIFT_VERSION}/ && \
34+
./configure --enable-libs=no --enable-tests=no --enable-tutorial=no --with-cpp=no --with-c_glib=no --with-java=yes --with-ruby=no --with-erlang=no --with-go=no --with-nodejs=no --with-python=no && \
35+
make && \
36+
make install && \
37+
cd .. && \
38+
rm -rf thrift-${APACHE_THRIFT_VERSION}
39+
40+
- name: Determine release version
41+
id: vars
42+
run: |
43+
# Read version from build.gradle
44+
RELEASE_VERSION=$(grep -E 'version\s*=' build.gradle | sed "s/[[:space:]]*version[[:space:]]*=[[:space:]]*'\(.*\)'/\1/")
45+
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
46+
47+
- name: Publish to Sonatype OSSRH (Maven Central)
48+
env:
49+
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
50+
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
51+
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
52+
OSSATUBER_PASSWORD: ${{ secrets.OSSATUBER_PASSWORD }}
53+
OSSATUBER_USERNAME: ${{ secrets.OSSATUBER_USERNAME }}
54+
run: | # TODO old way of setting the properties from environment variables in gradle
55+
./gradlew publishToSonatype closeSonatypeStagingRepository --info \
56+
-Psigning.keyId="${SIGNING_KEY_ID}" \
57+
-Psigning.password="${SIGNING_PASSWORD}" \
58+
-Psigning.key="${SIGNING_KEY}" \
59+
-PossrhPassword="${OSSATUBER_PASSWORD}" \
60+
-PossrhUsername="${OSSATUBER_USERNAME}"

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ src/main/idls/*
1313
/bin
1414
.classpath
1515
.project
16-
.settings
16+
.settings
17+
.vscode

build.gradle

+37-8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ plugins {
1212
id 'java-library'
1313
id 'jacoco'
1414
id 'com.google.protobuf' version '0.8.11'
15+
id("io.github.gradle-nexus.publish-plugin") version "1.3.0" // Nexus publishing
16+
}
17+
18+
ext {
19+
ossrhUsername = findProperty('ossrhUsername')
20+
ossrhPassword = findProperty('ossrhPassword')
21+
signingKeyId = findProperty('signing.keyId')
22+
signingKey = findProperty('signing.key')
23+
signingPassword = findProperty('signing.password')
1524
}
1625

1726
repositories {
@@ -38,7 +47,7 @@ googleJavaFormat {
3847
tasks.googleJavaFormat.dependsOn 'license'
3948

4049
group = 'com.uber.cadence'
41-
version = '3.12.6'
50+
version = '3.12.7-SNAPSHOT'
4251

4352
description = '''Uber Cadence Java Client'''
4453

@@ -214,9 +223,6 @@ artifacts {
214223
archives javadocJar, sourcesJar
215224
}
216225

217-
def ossrhUsername = hasProperty('ossrhUsername') ? property('ossrhUsername') : ''
218-
def ossrhPassword = hasProperty('ossrhPassword') ? property('ossrhPassword') : ''
219-
220226
publishing {
221227
publications {
222228
mavenJava(MavenPublication) {
@@ -268,11 +274,34 @@ publishing {
268274
}
269275
}
270276

271-
if (hasProperty('signing.keyId')) {
277+
nexusPublishing {
278+
repositories {
279+
sonatype {
280+
username.set(ossrhUsername)
281+
password.set(ossrhPassword)
282+
nexusUrl.set(uri("https://oss.sonatype.org/service/local/"))
283+
snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots/"))
284+
}
285+
}
286+
}
287+
288+
if (signingKeyId) {
272289
apply plugin: 'signing'
273-
signing {
274-
sign configurations.archives
275-
sign publishing.publications.mavenJava
290+
if (signingKey) { // for CI
291+
signing {
292+
useInMemoryPgpKeys(
293+
signingKeyId,
294+
signingKey.replace('\\n','\n'),
295+
signingPassword
296+
)
297+
sign configurations.archives
298+
sign publishing.publications.mavenJava
299+
}
300+
} else {
301+
signing {
302+
sign configurations.archives
303+
sign publishing.publications.mavenJava
304+
}
276305
}
277306
}
278307

0 commit comments

Comments
 (0)