Skip to content

Commit 733eac7

Browse files
authored
feat: Add Maven Central release workflow (#24)
* Add release workflow to publish to Maven Central Automates the release process: extracts version from build.gradle, builds and signs the artifact, publishes to Maven Central, and creates a GitHub release with the shadow jar. * Bump version to 0.3.0 * Update README with version 0.3.0 and JDK 17 requirement * Address PR review feedback on release workflow - Bump actions/cache from v3 to v4 (Node 16 deprecation) - Add concurrency group to prevent parallel release attempts - Document base64 encoding requirement for GPG_PRIVATE_KEY secret
1 parent 8bac4f3 commit 733eac7

3 files changed

Lines changed: 98 additions & 4 deletions

File tree

.github/workflows/release.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Publish Release to Maven Central
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'lib/build.gradle'
9+
10+
permissions:
11+
contents: write
12+
13+
concurrency:
14+
group: release
15+
cancel-in-progress: false
16+
17+
jobs:
18+
release:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
27+
- name: Extract version from build.gradle
28+
id: version
29+
run: |
30+
VERSION=$(grep "^version = " lib/build.gradle | sed "s/version = '\(.*\)'/\1/")
31+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
32+
echo "Detected version: $VERSION"
33+
34+
- name: Check if tag already exists
35+
id: tag_check
36+
run: |
37+
if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
38+
echo "Tag v${{ steps.version.outputs.version }} already exists, skipping release."
39+
echo "exists=true" >> "$GITHUB_OUTPUT"
40+
else
41+
echo "Tag v${{ steps.version.outputs.version }} does not exist, proceeding with release."
42+
echo "exists=false" >> "$GITHUB_OUTPUT"
43+
fi
44+
45+
- name: Set up JDK 17
46+
if: steps.tag_check.outputs.exists == 'false'
47+
uses: actions/setup-java@v4
48+
with:
49+
distribution: 'adopt'
50+
java-version: '17'
51+
52+
- name: Cache Gradle packages
53+
if: steps.tag_check.outputs.exists == 'false'
54+
uses: actions/cache@v4
55+
with:
56+
path: ~/.gradle/caches
57+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
58+
restore-keys: |
59+
${{ runner.os }}-gradle-
60+
61+
- name: Import GPG key
62+
if: steps.tag_check.outputs.exists == 'false'
63+
run: |
64+
# GPG_PRIVATE_KEY must be stored as base64-encoded:
65+
# gpg --export-secret-keys --armor <KEY_ID> | base64 | pbcopy
66+
echo "${{ secrets.GPG_PRIVATE_KEY }}" | base64 --decode | gpg --batch --import
67+
echo "allow-preset-passphrase" >> ~/.gnupg/gpg-agent.conf
68+
gpgconf --kill gpg-agent
69+
gpgconf --launch gpg-agent
70+
GPG_KEYGRIP=$(gpg --with-keygrip --list-secret-keys | grep -A1 '^\[S\]' | grep Keygrip | awk '{print $3}')
71+
if [ -z "$GPG_KEYGRIP" ]; then
72+
GPG_KEYGRIP=$(gpg --with-keygrip --list-secret-keys | grep Keygrip | head -1 | awk '{print $3}')
73+
fi
74+
/usr/lib/gnupg/gpg-preset-passphrase --preset "$GPG_KEYGRIP" <<< "${{ secrets.GPG_PASSPHRASE }}"
75+
76+
- name: Build and publish to Maven Central
77+
if: steps.tag_check.outputs.exists == 'false'
78+
run: chmod +x ./gradlew && ./gradlew clean build shadowJar publishToCentralPortal
79+
env:
80+
GRADLE_OPTS: -Dorg.gradle.daemon=false
81+
OSSRH_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
82+
OSSRH_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
83+
84+
- name: Create GitHub Release
85+
if: steps.tag_check.outputs.exists == 'false'
86+
env:
87+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
run: |
89+
VERSION="v${{ steps.version.outputs.version }}"
90+
gh release create "$VERSION" \
91+
--title "$VERSION" \
92+
--generate-notes \
93+
lib/build/libs/*-all.jar

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
A JDBC driver for [Wherobots Spatial SQL](https://www.wherobots.com), enabling
88
Java, Scala, and Kotlin applications to interact with WherobotsDB and leverage
9-
its powerful geospatial analytics capabilities.
9+
its powerful geospatial analytics capabilities. The driver is compiled against
10+
JDK 17 and requires Java 17 or later.
1011

1112
This driver is also compatible with database tools like [JetBrains
1213
DataGrip](https://www.jetbrains.com/datagrip/) and
@@ -18,7 +19,7 @@ DataGrip](https://www.jetbrains.com/datagrip/) and
1819

1920
```gradle
2021
dependencies {
21-
implementation 'com.wherobots.jdbc:wherobots-jdbc-driver:0.2.2'
22+
implementation 'com.wherobots.jdbc:wherobots-jdbc-driver:0.3.0'
2223
}
2324
```
2425

@@ -28,7 +29,7 @@ dependencies {
2829
<dependency>
2930
<groupId>com.wherobots.jdbc</groupId>
3031
<artifactId>wherobots-jdbc-driver</artifactId>
31-
<version>0.2.2</version>
32+
<version>0.3.0</version>
3233
</dependency>
3334
```
3435

lib/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ plugins {
1515

1616
description = 'JDBC driver for the Wherobots Cloud Spatial SQL API'
1717
group = 'com.wherobots.jdbc'
18-
version = '0.2.2'
18+
version = '0.3.0'
1919

2020
repositories {
2121
mavenCentral()

0 commit comments

Comments
 (0)