Skip to content

Commit b11517e

Browse files
committed
GH-331 - Set up automatic release to Maven Central.
Added a new workflow reacting to commits to the release/release branch. It consumes the release key secret for GPG signing and issues the release deployment. Polish general build to rather use environment variables for secrets rather than command line arguments.
1 parent b43da53 commit b11517e

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ jobs:
2424
cache: 'maven'
2525

2626
- name: Build and deploy snapshot
27-
run: ./mvnw -B deploy --file pom.xml -s settings.xml -DcentralOssrhUsername=${{ secrets.CENTRAL_OSSRH_USERNAME }} -DcentralOssrhPassword=${{ secrets.CENTRAL_OSSRH_PASSWORD }}
27+
env:
28+
CENTRAL_USER: ${{ secrets.CENTRAL_OSSRH_USERNAME }}
29+
CENTAL_PASSWORD: ${{ secrets.CENTRAL_OSSRH_PASSWORD }}
30+
run: ./mvnw -B deploy -s settings.xml

.github/workflows/release.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Release to Maven Central
2+
3+
on:
4+
push:
5+
branches: [ release/release ]
6+
7+
jobs:
8+
build:
9+
name: Release project
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
14+
- name: Check out sources
15+
uses: actions/checkout@v4
16+
17+
- name: Set up JDK 17
18+
uses: actions/setup-java@v3
19+
with:
20+
distribution: 'temurin'
21+
java-version: 17
22+
cache: 'maven'
23+
24+
- name: Install GPG key
25+
run: |
26+
echo "${{ secrets.GPG_PRIVATE_KEY }}" > gpg.asc
27+
echo "${{ secrets.GPG_PASSPHRASE }}" | gpg --batch --yes --passphrase-fd 0 --import gpg.asc
28+
29+
- name: Release to Maven Central OSSRH
30+
env:
31+
CENTRAL_OSSRH_USERNAME: ${{ secrets.CENTRAL_OSSRH_USERNAME }}
32+
CENTRAL_OSSRH_PASSWORD: ${{ secrets.CENTRAL_OSSRH_PASSWORD }}
33+
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
34+
run: |
35+
./mvnw -B clean deploy -Psonatype -s settings.xml

settings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<servers>
55
<server>
66
<id>central-ossrh</id>
7-
<username>${centralOssrhUsername}</username>
8-
<password>${centralOssrhPassword}</password>
7+
<username>${env.CENTRAL_OSSRH_USERNAME}</username>
8+
<password>${env.CENTRAL_OSSRH_PASSWORD}</password>
99
</server>
1010
</servers>
1111
</settings>

0 commit comments

Comments
 (0)