Skip to content

Commit 9a15fe7

Browse files
committed
Update mvn publish workflow
1 parent 39efb24 commit 9a15fe7

2 files changed

Lines changed: 33 additions & 10 deletions

File tree

.github/workflows/maven-publish.yml

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
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
1+
# Publishes to Maven Central (Sonatype) when you push a tag v* (e.g. v0.6.17).
2+
# Trigger: push tag v* OR run manually via Actions tab ("Run workflow").
3+
# For a production release: set pom <version> to a release (e.g. 0.6.17, no -SNAPSHOT), commit, then tag and push: git tag v0.6.17 && git push origin v0.6.17
34

45
name: Maven Package
56

67
on:
78
push:
89
tags:
9-
- 'v*' # Push events to matching v*
10+
- 'v*'
1011
workflow_dispatch: {}
1112

1213
jobs:
@@ -19,19 +20,30 @@ jobs:
1920

2021
steps:
2122
- uses: actions/checkout@v2
23+
24+
- name: Require release version when triggered by tag
25+
if: startsWith(github.ref, 'refs/tags/')
26+
run: |
27+
V=$(grep -oP '(?<=<version>)[^<]+' pom.xml | head -1)
28+
if [[ "$V" == *-SNAPSHOT ]]; then
29+
echo "::error::Publishing from a tag requires a release version in pom.xml (no -SNAPSHOT). Current: $V"
30+
exit 1
31+
fi
32+
2233
- name: Set up Apache Maven Central
2334
uses: actions/setup-java@v2
2435
with: # running setup-java again overwrites the settings.xml
2536
distribution: 'zulu'
2637
java-version: '11'
27-
server-username: MAVEN_USERNAME # env variable for username in deploy
28-
server-password: MAVEN_CENTRAL_TOKEN # env variable for token in deploy
29-
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
30-
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
38+
server-id: sonatype-nexus-staging
39+
server-username: MAVEN_USERNAME
40+
server-password: MAVEN_CENTRAL_TOKEN
41+
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
42+
gpg-passphrase: MAVEN_GPG_PASSPHRASE
3143
settings-path: ${{ github.workspace }}/generated-settings
3244

3345
- name: Release to Apache Maven Central
34-
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml
46+
run: mvn deploy -s $GITHUB_WORKSPACE/generated-settings/settings.xml
3547
env:
3648
SONATYPE_USERNAME: ${{ secrets.MAVEN_CENTRAL_USER }}
3749
SONATYPE_PASSWORD: ${{ secrets.MAVEN_CENTRAL_TOKEN }}

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,19 @@ objectName="mirus:type=connector-task-metrics,connector=*" attribute="task-faile
255255
256256
## Developer Info
257257
258-
To preform a release: `mvn release:prepare release:perform`
259-
GPG Keys may need to be passed to maven with `-Darguments='-Dgpg.passphrase= -Dgpg.keyname=55Z32RD1'`
258+
### Releasing to Maven Central (GitHub Actions)
259+
260+
1. In `pom.xml`, set `<version>` to a **release** value (e.g. `0.6.17`) — **no** `-SNAPSHOT`.
261+
2. Commit and push to `master`.
262+
3. Tag that commit and push the tag:
263+
`git tag v0.6.17 && git push origin v0.6.17`
264+
4. The **Maven Package** workflow runs on tag push and deploys to Maven Central. Ensure repo secrets are set: `MAVEN_CENTRAL_USER`, `MAVEN_CENTRAL_TOKEN`, `MAVEN_GPG_PRIVATE_KEY`, `MAVEN_GPG_PASSPHRASE`.
265+
5. After the release, bump the version back to the next SNAPSHOT (e.g. `0.6.18-SNAPSHOT`) on `master`.
266+
267+
### Releasing locally
268+
269+
To perform a release locally: `mvn release:prepare release:perform`
270+
GPG keys may need to be passed to Maven with `-Darguments='-Dgpg.passphrase= -Dgpg.keyname=55Z32RD1'`
260271
261272
# Discussion
262273

0 commit comments

Comments
 (0)