Skip to content

Commit d6d7df4

Browse files
committed
updating release
1 parent 782f619 commit d6d7df4

3 files changed

Lines changed: 81 additions & 28 deletions

File tree

.github/workflows/release-deploy.yml

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
push:
55
branches:
66
- master
7-
- main
87
paths:
98
- release/deploy.txt
109
workflow_dispatch:
@@ -51,7 +50,7 @@ jobs:
5150
5251
deploy:
5352
needs: prepare
54-
if: needs.prepare.outputs.run_release == 'true'
53+
if: needs.prepare.outputs.run_release == 'true' && github.ref == 'refs/heads/master'
5554
runs-on: ubuntu-latest
5655
env:
5756
CENTRAL_TOKEN_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }}
@@ -71,13 +70,12 @@ jobs:
7170
server-username: CENTRAL_TOKEN_USERNAME
7271
server-password: CENTRAL_TOKEN_PASSWORD
7372

74-
- name: Import GPG key manually
73+
- name: Import GPG key
7574
shell: bash
7675
env:
7776
GPG_PRIVATE_KEY_B64: ${{ secrets.MAVEN_GPG_PRIVATE_KEY_BASE64 }}
7877
run: |
7978
set -euo pipefail
80-
echo "Importing GPG key..."
8179
8280
KEYFILE=$(mktemp)
8381
trap "rm -f $KEYFILE" EXIT
@@ -87,20 +85,7 @@ jobs:
8785
# GitHub Secrets UI. Strip all whitespace, then decode to the real key.
8886
printf '%s' "$GPG_PRIVATE_KEY_B64" | tr -d '[:space:]' | base64 -d > "$KEYFILE"
8987
90-
echo "=== Diagnostics ==="
91-
echo "Key file size: $(wc -c < "$KEYFILE") bytes"
92-
echo "Line count: $(wc -l < "$KEYFILE")"
93-
echo "Has BEGIN marker: $(grep -c 'BEGIN PGP PRIVATE KEY' "$KEYFILE" || true)"
94-
echo "Has END marker: $(grep -c 'END PGP PRIVATE KEY' "$KEYFILE" || true)"
95-
96-
echo "=== Importing ==="
97-
gpg --batch \
98-
--import \
99-
--import-options import-show \
100-
"$KEYFILE" || { echo "Import failed"; exit 1; }
101-
102-
echo "✓ GPG key imported successfully"
103-
gpg --list-secret-keys --keyid-format=long
88+
gpg --batch --quiet --import "$KEYFILE"
10489
10590
- name: Validate version
10691
if: needs.prepare.outputs.requested_version != ''

release/README.md

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,71 @@ This repository uses a GitHub Actions workflow to build and deploy releases to S
99

1010
Add 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

1719
The 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

2165
1. Update the project version in `pom.xml` (for example `1.2.3`).
2266
2. 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

4391
You can also run the workflow manually via **Actions → Release Deploy → Run workflow**.
4492
It 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

4898
Set `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`).

release/deploy.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# 1) Set enabled=true
33
# 2) Set version to the pom.xml release version you want to publish
44
# 3) Commit and push this file to main/master
5-
enabled=true
5+
enabled=false
66
version=1.2.3

0 commit comments

Comments
 (0)