Release & Publish to Maven Central #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release & Publish to Maven Central | |
on: | |
workflow_dispatch: | |
inputs: | |
branch: | |
description: "Branch to release from" | |
required: false | |
default: "master" | |
confirm: | |
description: "NOTE: You are publishing an immortal artifact on Maven Central that can never be removed! (type 'yes' to continue)" | |
required: true | |
default: "no" | |
jobs: | |
confirm-job: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Confirm input | |
if: ${{ inputs.confirm != 'yes' }} | |
run: | | |
echo "Confirmation not given. Exiting." | |
exit 1 | |
- name: Proceed with the workflow | |
run: echo "Proceeding with workflow as confirmation was given." | |
publish: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.inputs.branch || 'master' }} | |
- name: Set up JDK 11 for deploy to Sonatype | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: 11 | |
server-id: central | |
server-username: MAVEN_USERNAME | |
server-password: MAVEN_CENTRAL_TOKEN | |
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} | |
gpg-passphrase: MAVEN_GPG_PASSPHRASE | |
- name: Set up Git user | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Remove snapshot from maven version | |
run: | | |
mvn -B versions:set -DremoveSnapshot -DgenerateBackupPoms=false | |
MAVEN_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) | |
echo "Committing and tagging version $MAVEN_VERSION" | |
git commit -m "Setting release version to $MAVEN_VERSION" pom.xml | |
git tag -a "v$MAVEN_VERSION" -m "Release version $MAVEN_VERSION" | |
git push origin | |
git push origin "v$MAVEN_VERSION" | |
- name: Publish to Apache Maven Central | |
run: mvn deploy -PsonatypeDeploy | |
env: | |
MAVEN_USERNAME: ${{ secrets.NEXUS_USERNAME }} | |
MAVEN_CENTRAL_TOKEN: ${{ secrets.NEXUS_PASSWORD }} | |
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} | |
- name: Set next snapshot version | |
run: | | |
mvn -B versions:set -DnextSnapshot -DgenerateBackupPoms=false | |
MAVEN_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) | |
git commit -m "Setting next snapshot version to $MAVEN_VERSION" pom.xml | |
git push origin | |