Skip to content

Commit 5afb822

Browse files
committed
Add a manually triggered Maven deploy workflow
In order to test deployment, add a new workflow which can be triggered manually to release to Maven central. Simplify configuration to use a single server entry 'ossrh' instead of separate ones for snapshots vs. releases. Update to the latest nexus-staging-maven-plugin.
1 parent 3412985 commit 5afb822

File tree

4 files changed

+100
-13
lines changed

4 files changed

+100
-13
lines changed

.github/workflows/maven-deploy.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ jobs:
4343
echo $GPG_KEY | base64 --decode > signing-key
4444
gpg --passphrase $GPG_PASSPHRASE --batch --import signing-key
4545
shred signing-key
46-
46+
4747
- name: Configure GIT
4848
run: |
49-
git config --global user.email "[email protected]"
49+
git config --global user.email "[email protected]"
5050
git config --global user.name "envoy-bot"
5151
5252
- name: Set up JDK
@@ -55,7 +55,7 @@ jobs:
5555
distribution: 'temurin'
5656
java-version: '17'
5757
cache: 'maven'
58-
server-id: sonatype-nexus-snapshots
58+
server-id: ossrh
5959
server-username: ${ env.SONATYPE_USER }
6060
server-password: ${ env.SONATYPE_PASSWORD }
6161
gpg-private-key: ${{ secrets.GPG_SECRET_KEY }}
@@ -68,7 +68,7 @@ jobs:
6868
- name: Publish to Maven Packages Apache Maven
6969
working-directory: ${{ github.workspace }}/java
7070
run: |
71-
mvn -B -s settings.xml clean deploy \
71+
mvn -B -s settings.xml ${{ inputs.deployArgs }} clean deploy \
7272
-Darguments="-s settings.xml" \
7373
-DreleaseVersion=${{ env.VERSION }} \
7474
-DdevelopmentVersion=${{ env.VERSION }}-SNAPSHOT \

.github/workflows/maven-release.yaml

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
2+
## For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path
3+
4+
name: Maven Manual Deploy
5+
6+
on:
7+
workflow_dispatch:
8+
inputs:
9+
ref:
10+
description: "Git ref to release"
11+
required: true
12+
version:
13+
description: "Maven version to release (without 'v' prefix)"
14+
required: true
15+
deployArgs:
16+
description: "Additional Maven deploy arguments (e.g. '--debug -DautoReleaseAfterClose=false')"
17+
required: false
18+
19+
jobs:
20+
build:
21+
runs-on: ubuntu-latest
22+
env:
23+
SONATYPE_USER: ${{secrets.BUF_SONATYPE_USER}}
24+
SONATYPE_PASSWORD: ${{secrets.BUF_SONATYPE_PASSWORD}}
25+
GPG_KEY_NAME: ${{secrets.GPG_KEY_NAME}}
26+
GPG_PASSPHRASE: ${{secrets.GPG_PASSPHRASE}}
27+
MAVEN_OPTS: "--add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/java.awt.font=ALL-UNNAMED"
28+
REF_NAME: ${{ inputs.ref }}
29+
30+
steps:
31+
- uses: actions/checkout@v4
32+
with:
33+
ref: ${{ inputs.ref }}
34+
- uses: actions/setup-go@v5
35+
with:
36+
go-version: 'stable'
37+
- name: Set VERSION variable from tag
38+
run: |
39+
echo "VERSION=${{ inputs.VERSION }}" >> $GITHUB_ENV
40+
41+
- name: 'Configure GPG signing'
42+
env:
43+
GPG_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
44+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
45+
run: |
46+
# https://github.com/keybase/keybase-issues/issues/2798
47+
export GPG_TTY=$(tty)
48+
# Import gpg keys and warm the passphrase to avoid the gpg
49+
# passphrase prompt when initating a deploy
50+
# `--pinentry-mode=loopback` could be needed to ensure we
51+
# suppress the gpg prompt
52+
echo $GPG_KEY | base64 --decode > signing-key
53+
gpg --passphrase $GPG_PASSPHRASE --batch --import signing-key
54+
shred signing-key
55+
56+
- name: Configure GIT
57+
run: |
58+
git config --global user.email "[email protected]"
59+
git config --global user.name "envoy-bot"
60+
61+
- name: Set up JDK
62+
uses: actions/setup-java@v4
63+
with:
64+
distribution: 'temurin'
65+
java-version: '17'
66+
cache: 'maven'
67+
server-id: ossrh
68+
server-username: ${ env.SONATYPE_USER }
69+
server-password: ${ env.SONATYPE_PASSWORD }
70+
gpg-private-key: ${{ secrets.GPG_SECRET_KEY }}
71+
gpg-passphrase: ${ env.GPG_PASSPHRASE }
72+
73+
- name: Update version in pom
74+
working-directory: ${{ github.workspace }}/java
75+
run: mvn -B versions:set -DnewVersion=${{ env.VERSION }} -DgenerateBackupPoms=false
76+
77+
- name: Publish to Maven Packages Apache Maven
78+
working-directory: ${{ github.workspace }}/java
79+
run: |
80+
mvn -B -s settings.xml ${{ inputs.deployArgs }} clean deploy \
81+
-Darguments="-s settings.xml" \
82+
-DreleaseVersion=${{ env.VERSION }} \
83+
-DdevelopmentVersion=${{ env.VERSION }}-SNAPSHOT \
84+
-DscmCommentPrefix="java release: "
85+
env:
86+
MAVEN_USERNAME: ${{ env.SONATYPE_USER }}
87+
MAVEN_CENTRAL_TOKEN: ${{ env.SONATYPE_PASSWORD }}
88+
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}

java/pom.xml

+7-3
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@
157157
<plugin>
158158
<groupId>org.sonatype.plugins</groupId>
159159
<artifactId>nexus-staging-maven-plugin</artifactId>
160-
<version>1.6.13</version>
160+
<version>1.7.0</version>
161161
<extensions>true</extensions>
162162
<configuration>
163-
<serverId>sonatype-nexus-staging</serverId>
163+
<serverId>ossrh</serverId>
164164
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
165165
<autoReleaseAfterClose>true</autoReleaseAfterClose>
166166
</configuration>
@@ -206,8 +206,12 @@
206206
</scm>
207207

208208
<distributionManagement>
209+
<repository>
210+
<id>ossrh</id>
211+
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
212+
</repository>
209213
<snapshotRepository>
210-
<id>sonatype-nexus-snapshots</id>
214+
<id>ossrh</id>
211215
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
212216
</snapshotRepository>
213217
</distributionManagement>

java/settings.xml

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
33
<servers>
44
<server>
5-
<id>sonatype-nexus-snapshots</id>
6-
<username>${env.SONATYPE_USER}</username>
7-
<password>${env.SONATYPE_PASSWORD}</password>
8-
</server>
9-
<server>
10-
<id>sonatype-nexus-staging</id>
5+
<id>ossrh</id>
116
<username>${env.SONATYPE_USER}</username>
127
<password>${env.SONATYPE_PASSWORD}</password>
138
</server>

0 commit comments

Comments
 (0)