Skip to content

Commit 5a9b28b

Browse files
committed
Enhance GitHub Actions workflow for Maven publishing by configuring GPG key permissions and updating settings.xml to include GPG passphrase and profile settings. This improves security and ensures proper deployment configuration.
1 parent 99e4f84 commit 5a9b28b

File tree

1 file changed

+47
-11
lines changed

1 file changed

+47
-11
lines changed

.github/workflows/maven-publish.yml

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,73 @@ jobs:
1818
with:
1919
java-version: '17'
2020
distribution: 'temurin'
21-
cache: maven
21+
server-id: central
22+
server-username: ${{ secrets.MAVEN_USERNAME }}
23+
server-password: ${{ secrets.MAVEN_PASSWORD }}
24+
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
25+
gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }}
2226

23-
- name: Import GPG key
27+
- name: Configure GPG Key
2428
run: |
25-
echo "${{ secrets.GPG_PRIVATE_KEY }}" > private.asc
26-
gpg --batch --import private.asc
27-
29+
# Setup GPG directory permissions
30+
mkdir -p ~/.gnupg/
31+
chmod 700 ~/.gnupg/
32+
echo "allow-loopback-pinentry" > ~/.gnupg/gpg-agent.conf
33+
echo "pinentry-mode loopback" > ~/.gnupg/gpg.conf
34+
2835
- name: Build and Publish package
2936
env:
3037
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
3138
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
3239
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
3340
GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }}
3441
run: |
35-
# Create settings.xml with proper server configurations
42+
# Create settings-security.xml
3643
mkdir -p ~/.m2
44+
45+
# Add the gpg.passphrase configuration to settings.xml
46+
cat > ~/.m2/settings-security.xml << EOF
47+
<settingsSecurity>
48+
<master>${GPG_PASSPHRASE}</master>
49+
</settingsSecurity>
50+
EOF
51+
52+
# Ensure settings.xml has proper GPG passphrase configuration
53+
if [ -f ~/.m2/settings.xml ]; then
54+
mv ~/.m2/settings.xml ~/.m2/settings.xml.bak
55+
fi
56+
3757
cat > ~/.m2/settings.xml << EOF
3858
<settings>
3959
<servers>
4060
<server>
4161
<id>central</id>
42-
<username>\${env.MAVEN_USERNAME}</username>
43-
<password>\${env.MAVEN_PASSWORD}</password>
62+
<username>${MAVEN_USERNAME}</username>
63+
<password>${MAVEN_PASSWORD}</password>
4464
</server>
4565
<server>
4666
<id>gpg.passphrase</id>
47-
<passphrase>\${env.GPG_PASSPHRASE}</passphrase>
67+
<passphrase>${GPG_PASSPHRASE}</passphrase>
4868
</server>
4969
</servers>
70+
<profiles>
71+
<profile>
72+
<id>gpg</id>
73+
<properties>
74+
<gpg.executable>gpg</gpg.executable>
75+
<gpg.passphrase>${GPG_PASSPHRASE}</gpg.passphrase>
76+
<gpg.keyname>${GPG_KEY_NAME}</gpg.keyname>
77+
</properties>
78+
</profile>
79+
</profiles>
80+
<activeProfiles>
81+
<activeProfile>gpg</activeProfile>
82+
</activeProfiles>
5083
</settings>
5184
EOF
52-
85+
86+
# Print debug info
87+
echo "Maven settings created. Deploying with Maven..."
88+
5389
# Build and deploy
54-
mvn -B clean deploy
90+
mvn -B clean deploy -Dgpg.passphrase=${GPG_PASSPHRASE}

0 commit comments

Comments
 (0)