Skip to content

Commit 743afe8

Browse files
committed
Refactor GitHub Actions workflow for Maven publishing by improving GPG key import process and updating settings.xml creation. This enhances security and ensures proper configurations for deployment, including the use of GPG key name in the Maven command.
1 parent 5a9b28b commit 743afe8

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

.github/workflows/maven-publish.yml

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,34 @@ jobs:
2121
server-id: central
2222
server-username: ${{ secrets.MAVEN_USERNAME }}
2323
server-password: ${{ secrets.MAVEN_PASSWORD }}
24-
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
25-
gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }}
2624

27-
- name: Configure GPG Key
25+
- name: Import GPG Key
2826
run: |
2927
# Setup GPG directory permissions
3028
mkdir -p ~/.gnupg/
3129
chmod 700 ~/.gnupg/
30+
31+
# Configure GPG for non-interactive use
3232
echo "allow-loopback-pinentry" > ~/.gnupg/gpg-agent.conf
3333
echo "pinentry-mode loopback" > ~/.gnupg/gpg.conf
3434
35+
# Save and import the GPG key
36+
echo "${{ secrets.GPG_PRIVATE_KEY }}" | gpg --batch --import
37+
38+
# List imported keys for debugging
39+
gpg --list-secret-keys --keyid-format LONG
40+
3541
- name: Build and Publish package
3642
env:
3743
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
3844
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
3945
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
4046
GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }}
4147
run: |
42-
# Create settings-security.xml
48+
# Create Maven settings
4349
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-
50+
51+
# Ensure settings.xml has proper configurations
5752
cat > ~/.m2/settings.xml << EOF
5853
<settings>
5954
<servers>
@@ -73,7 +68,6 @@ jobs:
7368
<properties>
7469
<gpg.executable>gpg</gpg.executable>
7570
<gpg.passphrase>${GPG_PASSPHRASE}</gpg.passphrase>
76-
<gpg.keyname>${GPG_KEY_NAME}</gpg.keyname>
7771
</properties>
7872
</profile>
7973
</profiles>
@@ -87,4 +81,4 @@ jobs:
8781
echo "Maven settings created. Deploying with Maven..."
8882
8983
# Build and deploy
90-
mvn -B clean deploy -Dgpg.passphrase=${GPG_PASSPHRASE}
84+
mvn -B clean deploy -Dgpg.passphrase="${GPG_PASSPHRASE}" -Dgpg.keyname="${GPG_KEY_NAME}"

0 commit comments

Comments
 (0)