Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1919efd
use manual GPG configuration
agrgr Oct 22, 2025
cf951ee
use gpg.passphrase parameter in the simplified version of the workflow
agrgr Oct 22, 2025
b56c790
add GPG plugin configuration
agrgr Oct 22, 2025
a30312f
update Maven GPG plugin configuration
agrgr Oct 22, 2025
44a7461
update Maven GPG plugin version and configuration
agrgr Oct 22, 2025
8b61838
add GPG agent configuration to the workflow
agrgr Oct 22, 2025
f7a2092
add gpg passphrase parameter to the maven gpg plugin
agrgr Oct 22, 2025
2b0d9c8
remove gpg passphrase parameter
agrgr Oct 22, 2025
6822e5b
pre-cache the passphrase in the GPG agent before Maven runs
agrgr Oct 22, 2025
106a17e
add debug output
agrgr Oct 22, 2025
57425ee
pipe the passphrase via stdin
agrgr Oct 22, 2025
4a0388d
check passphrase for emptyness, add debug output
agrgr Oct 22, 2025
c009920
check passphrase for emptyness, add debug output
agrgr Oct 22, 2025
c4ee353
check that passprase is cached
agrgr Oct 22, 2025
2f19912
remove debug output
agrgr Oct 22, 2025
1be1b48
use cached passphrase
agrgr Oct 22, 2025
700f1fd
update maven gpg plugin configuration
agrgr Oct 22, 2025
d0eabad
transfer passphrase to Maven as system property
agrgr Oct 22, 2025
7826445
create settings-security.xml
agrgr Oct 22, 2025
fbb25c8
use setup-gpg shared workflow
agrgr Oct 23, 2025
65be4c7
use ghaction-import-gpg
agrgr Oct 23, 2025
777e99f
verify Maven settings on CI/CD
agrgr Oct 23, 2025
cfd1060
set env variables on the job level
agrgr Oct 23, 2025
b628cea
test Nexus credentials
agrgr Oct 23, 2025
2cbe27f
create settings.xml and test
agrgr Oct 23, 2025
92dc885
cleanup
agrgr Oct 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 40 additions & 16 deletions .github/workflows/maven-release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Maven Deploy

on:
workflow_dispatch: # Manual trigger without inputs
workflow_dispatch: # Manual trigger without inputs

jobs:
deploy:
Expand All @@ -16,26 +16,50 @@ jobs:
maven-version: 3.9.6

- name: Set up JDK
# Handles importing GPG private key to the local keyring and configures Maven to use GPG passphrase
# if pom.xml has the Maven GPG plugin configured
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '17'
server-id: ossrh # Must match server ID in settings.xml/pom.xml
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
# The private key is not required as a standard environment variable
gpg-private-key: ${{ secrets.GPG_SECRET_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE
# Parameters for handling GPG in headless CI/CD
gpg-passphrase-args: --pinentry-mode=loopback --no-tty --batch
cache: maven

- name: Deploy to Maven Central
- name: Import GPG key
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this action is not needed updated setup-java action can do this for you

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v5
    - name: Set up JDK 11
      uses: actions/setup-java@v5
      with:
        distribution: '<distribution>'
        java-version: '11'

    - name: Build with Maven
      run: mvn -B package --file pom.xml

    - name: Publish to GitHub Packages Apache Maven
      run: mvn deploy
      env:
        GITHUB_TOKEN: ${{ github.token }} # GITHUB_TOKEN is the default env for the password

    - name: Set up Apache Maven Central
      uses: actions/setup-java@v5
      with: # running setup-java again overwrites the settings.xml
        distribution: 'temurin'
        java-version: '11'
        server-id: maven # Value of the distributionManagement/repository/id field of the pom.xml
        server-username: MAVEN_USERNAME # env variable for username in deploy
        server-password: MAVEN_CENTRAL_TOKEN # env variable for token in deploy
        gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
        gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase

    - name: Publish to Apache Maven Central
      run: mvn deploy
      env:
        MAVEN_USERNAME: maven_username123
        MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
        MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}

uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_SECRET_KEY }}
passphrase: ${{ secrets.GPG_PASS }}

- name: Configure Maven settings
env:
MAVEN_USERNAME: ${{ secrets.AEROSPIKE_SA_CICD_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.AEROSPIKE_SA_CICD_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASS }}
GPG_TTY: "" # Tell GPG not to use terminal
# Use batch mode: no interactive prompts, cleaner logs
run: mvn --batch-mode clean deploy
run: |
mkdir -p ~/.m2
cat > ~/.m2/settings.xml <<EOF
<settings>
<servers>
<server>
<id>ossrh</id>
<username>${MAVEN_USERNAME}</username>
<password>${MAVEN_PASSWORD}</password>
</server>
</servers>
</settings>
EOF

- name: Test credentials
env:
MAVEN_USERNAME: ${{ secrets.AEROSPIKE_SA_CICD_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.AEROSPIKE_SA_CICD_PASSWORD }}
run: |
echo "Testing Sonatype authentication..."
STATUS=$(curl -s -o /dev/null -w "%{http_code}" -u "${MAVEN_USERNAME}:${MAVEN_PASSWORD}" https://oss.sonatype.org/service/local/status)

if [ "$STATUS" = "200" ]; then
echo "Credentials are valid"
else
echo "Authentication failed (HTTP $STATUS)"
exit 1
fi

- name: Deploy to Maven Central
run: mvn --batch-mode deploy
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
<nexus-staging-maven-plugin.version>1.7.0</nexus-staging-maven-plugin.version>
<maven-javadoc-plugin.version>3.5.0</maven-javadoc-plugin.version>
<maven-source-plugin.version>3.3.1</maven-source-plugin.version>
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>

<maven-gpg-plugin.version>3.1.0</maven-gpg-plugin.version>
<aerospike-client-jdk8.version>9.2.0</aerospike-client-jdk8.version>
<antlr.version>4.13.2</antlr.version>
<lombok.version>1.18.42</lombok.version>
Expand Down Expand Up @@ -211,6 +210,13 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${maven-gpg-plugin.version}</version>
<configuration>
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
<arg>--no-tty</arg>
</gpgArguments>
</configuration>
<executions>
<execution>
<id>sign-artifacts</id>
Expand Down
Loading