You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/workflows/maven-publish.yml
+20-8Lines changed: 20 additions & 8 deletions
Original file line number
Diff line number
Diff 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
3
4
4
5
name: Maven Package
5
6
6
7
on:
7
8
push:
8
9
tags:
9
-
- 'v*'# Push events to matching v*
10
+
- 'v*'
10
11
workflow_dispatch: {}
11
12
12
13
jobs:
@@ -19,19 +20,30 @@ jobs:
19
20
20
21
steps:
21
22
- 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
+
22
33
- name: Set up Apache Maven Central
23
34
uses: actions/setup-java@v2
24
35
with: # running setup-java again overwrites the settings.xml
25
36
distribution: 'zulu'
26
37
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
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'`
0 commit comments