@@ -9,23 +9,71 @@ This repository uses a GitHub Actions workflow to build and deploy releases to S
99
1010Add these secrets in ** Settings → Secrets and variables → Actions** :
1111
12- - ` CENTRAL_TOKEN_USERNAME `
13- - ` CENTRAL_TOKEN_PASSWORD `
14- - ` MAVEN_GPG_PRIVATE_KEY ` (ASCII-armored private key content)
15- - ` MAVEN_GPG_PASSPHRASE `
12+ | Secret | Description |
13+ | --- | --- |
14+ | ` CENTRAL_TOKEN_USERNAME ` | Sonatype Central user token name (from ` central.sonatype.com ` → Account → Generate User Token). |
15+ | ` CENTRAL_TOKEN_PASSWORD ` | Sonatype Central user token password. |
16+ | ` MAVEN_GPG_PRIVATE_KEY_BASE64 ` | Your ASCII-armored GPG private key, ** base64-encoded as a single line** (see below). |
17+ | ` MAVEN_GPG_PASSPHRASE ` | Passphrase for the GPG private key. |
1618
1719The workflow configures Maven ` serverId=central ` and signs artifacts with GPG.
1820
21+ ### Why base64 for the GPG key?
22+
23+ GitHub Secrets does ** not** reliably preserve the newlines in a multi-line
24+ ASCII-armored PGP key. When pasted directly, the line breaks get collapsed and
25+ ` gpg --import ` fails with ` no valid OpenPGP data found ` (exit code 2). Encoding
26+ the key as a single base64 line avoids this entirely; the workflow strips any
27+ whitespace and decodes it back to the original key before importing.
28+
29+ ### Generating ` MAVEN_GPG_PRIVATE_KEY_BASE64 `
30+
31+ First find your signing key ID:
32+
33+ ``` bash
34+ gpg --list-secret-keys --keyid-format=long
35+ # e.g. sec rsa4096/0E23305B9C989C9A ... -> key id is 0E23305B9C989C9A
36+ ```
37+
38+ Then export it and base64-encode it as a single line.
39+
40+ ** Linux / macOS:**
41+
42+ ``` bash
43+ gpg --armor --export-secret-keys 0E23305B9C989C9A | base64 -w0 > gpg_key_b64.txt
44+ ```
45+
46+ ** Windows (PowerShell):**
47+
48+ ``` powershell
49+ $key = gpg --armor --export-secret-keys 0E23305B9C989C9A
50+ $bytes = [Text.Encoding]::ASCII.GetBytes(($key -join "`n") + "`n")
51+ [Convert]::ToBase64String($bytes) | Set-Content -NoNewline gpg_key_b64.txt
52+ ```
53+
54+ Paste the contents of ` gpg_key_b64.txt ` into the ` MAVEN_GPG_PRIVATE_KEY_BASE64 `
55+ secret, then ** delete the file** (it contains your private key).
56+
57+ You can sanity-check the value decodes back to a valid key:
58+
59+ ``` bash
60+ base64 -d gpg_key_b64.txt | gpg --show-keys
61+ ```
62+
1963## How to publish a release
2064
21651 . Update the project version in ` pom.xml ` (for example ` 1.2.3 ` ).
22662 . Edit ` release/deploy.txt ` :
2367 - ` enabled=true `
2468 - ` version=<same version as pom.xml> `
25- 3 . Commit and push to ` main ` or ` master ` .
26- 4 . The workflow will run and execute:
27- - version validation (` deploy.txt ` vs ` pom.xml ` )
28- - ` mvn clean deploy -DskipITs=true `
69+ 3 . Commit and push to ` master ` .
70+ 4 . The workflow will run two jobs:
71+ - ** prepare** – parses ` release/deploy.txt ` ; only proceeds if ` enabled=true ` .
72+ - ** deploy** – sets up JDK 21 + Maven, imports the GPG key, validates the
73+ version (` deploy.txt ` vs ` pom.xml ` ), then runs
74+ ` mvn -B -ntp clean deploy -DskipITs=true ` .
75+ 5 . Maven signs the artifacts and the ` central-publishing-maven-plugin ` uploads
76+ and auto-publishes the bundle to Sonatype Central.
2977
3078## Trigger file format
3179
@@ -42,12 +90,32 @@ If `enabled` is not `true`, deployment is skipped.
4290
4391You can also run the workflow manually via ** Actions → Release Deploy → Run workflow** .
4492It still reads ` release/deploy.txt ` , so keep ` enabled=true ` there for deployment.
93+ Note: the ` deploy ` job only runs on ` master ` , so a manual run from any other
94+ branch will not publish anything.
4595
4696## After a successful release
4797
4898Set ` enabled=false ` in ` release/deploy.txt ` and commit it, to avoid accidental re-deploy on future edits.
4999
100+ ## Troubleshooting
101+
102+ ** ` gpg: no valid OpenPGP data found ` / ` gpg failed with exit code 2 ` **
103+ The ` MAVEN_GPG_PRIVATE_KEY_BASE64 ` secret is missing, truncated, or wasn't
104+ base64-encoded as described above. Regenerate it with ` base64 -w0 ` (single line,
105+ no wrapping) and re-paste. Do ** not** paste the raw ASCII-armored key — its
106+ newlines get lost in GitHub Secrets.
107+
108+ ** ` Version mismatch ` **
109+ ` version= ` in ` release/deploy.txt ` must exactly match ` <version> ` in ` pom.xml ` .
110+
111+ ** Deployment doesn't start**
112+ The workflow only triggers on pushes that change ` release/deploy.txt ` on
113+ ` master ` . Make sure that file is part of your commit. Releases can ** only** be
114+ published from ` master ` — a manual ** Run workflow** from any other branch will
115+ run ` prepare ` but skip the ` deploy ` job by design.
116+
50117## Notes
51118
52119- ` mvnrepository.com ` may lag behind Sonatype Central indexing.
53- - The release workflow is intentionally independent from the regular CI build workflow.
120+ - The release workflow is intentionally independent from the regular CI build
121+ workflow (` build.yml ` ignores changes to ` release/deploy.txt ` ).
0 commit comments