Skip to content

Maven Release

Maven Release #6

Workflow file for this run

name: Maven Release
on:
workflow_dispatch:
inputs:
dry_run:
description: 'Perform a dry run of the Maven release'
required: true
default: false
type: boolean
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
# Export the gpg private key using the following command and add the contents of that file to the GitHub secret
# gpg --armor --export-secret-keys <key_id> > gpg_key.asc
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE
- name: Set up git
run: |
git config --global user.email "[email protected]"
git config --global user.name "Steve Springett"
git config --global credential.helper 'store --file ~/.git-credentials'
echo "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com" > ~/.git-credentials
- name: Set Maven options
id: maven_options
run: |
# Set the Maven options based on the 'dry_run' input
if ${{ github.event.inputs.dry_run }}; then
echo "options=release:prepare -DdryRun=true -Prelease" >> $GITHUB_ENV
else
echo "options=release:clean release:prepare release:perform -Prelease" >> $GITHUB_ENV
fi
- name: Run Maven command and capture exit code
id: run_maven
run: |
mvn -B ${{ env.options }} || echo "Maven failed" > /tmp/maven_failed
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Rollback if release fails
if: ${{ steps.run_maven.outcome == 'failure' && github.event.inputs.dry_run == false }}
run: |
echo "Release failed. Rolling back..."
mvn -B release:rollback -Prelease
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}