-
Notifications
You must be signed in to change notification settings - Fork 0
110 lines (100 loc) · 3.65 KB
/
maven-central.yml
File metadata and controls
110 lines (100 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: Publish to Maven Central
on:
push:
tags:
- 'v*'
branches:
- 'feature/release-*'
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
cache: maven
- name: Setup GPG
env:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
GPG_KEYNAME: ${{ secrets.GPG_KEYNAME }}
run: |
set -euo pipefail
echo "Setting up GPG..."
mkdir -p ~/.gnupg
chmod 700 ~/.gnupg
if [ -z "${GPG_KEYNAME:-}" ]; then
echo "::error::GPG_KEYNAME is empty — set it to the long key ID or fingerprint (no spaces) from gpg --list-secret-keys --keyid-format LONG"
exit 1
fi
if [ -z "${GPG_PRIVATE_KEY:-}" ]; then
echo "::error::GPG_PRIVATE_KEY is empty — paste the full armored block (BEGIN/END PGP PRIVATE KEY BLOCK)"
exit 1
fi
# Strip CR (Windows line endings break gpg --import)
printf '%s\n' "$GPG_PRIVATE_KEY" | tr -d '\r' > private.key
echo "Importing GPG key..."
gpg --batch --import private.key
rm -f private.key
echo "Configuring GPG..."
cat > ~/.gnupg/gpg.conf << EOF
default-key $GPG_KEYNAME
use-agent
pinentry-mode loopback
EOF
echo "=== GPG secret keys ==="
gpg --list-secret-keys --keyid-format LONG
if ! gpg --list-secret-keys --keyid-format LONG 2>/dev/null | grep -q '^sec'; then
echo "::error::No secret key after import. Use gpg --export-secret-keys (not --export), full private armored block, and matching GPG_KEYNAME."
exit 1
fi
echo "=== GPG public keys ==="
gpg --list-keys --keyid-format LONG
- name: Configure Maven
run: |
mkdir -p ~/.m2
cat > ~/.m2/settings.xml << EOF
<settings>
<servers>
<server>
<id>central</id>
<username>${{ secrets.OSSRH_USERNAME_TOKEN }}</username>
<password>${{ secrets.OSSRH_PASSWORD_TOKEN }}</password>
</server>
</servers>
<profiles>
<profile>
<id>central</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.executable>gpg</gpg.executable>
<gpg.passphrase>${{ secrets.GPG_PASSPHRASE }}</gpg.passphrase>
</properties>
</profile>
</profiles>
</settings>
EOF
- name: Build and Publish
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME_TOKEN }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD_TOKEN }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
run: |
echo "Starting Maven build and deploy..."
mvn clean deploy -P release \
-Dmaven.javadoc.skip=false \
-Dmaven.deploy.skip=false \
-Dgpg.keyname=${{ secrets.GPG_KEYNAME }} \
-Dgpg.useagent=true \
-Dmaven.test.failure.ignore=false \
-DaltDeploymentRepository=ossrh::default::https://central.sonatype.com/api/v1/publisher/upload \
-DrepositoryId=ossrh \
-Dusername=${{ secrets.OSSRH_USERNAME_TOKEN }} \
-Dpassword=${{ secrets.OSSRH_PASSWORD_TOKEN }}