Publish To Maven Central #2
This file contains hidden or 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: Publish To Maven Central | |
| on: | |
| release: | |
| types: | |
| - published | |
| workflow_dispatch: | |
| inputs: | |
| release_version: | |
| description: Release version to publish, for example 1.0.0 | |
| required: false | |
| type: string | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: publish-maven-central-${{ github.event.release.tag_name || github.ref_name || github.run_id }} | |
| cancel-in-progress: false | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| env: | |
| CENTRAL_TOKEN_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }} | |
| CENTRAL_TOKEN_PASSWORD: ${{ secrets.CENTRAL_TOKEN_PASSWORD }} | |
| steps: | |
| - name: Checkout Source | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Validate Publish Secrets | |
| shell: bash | |
| run: | | |
| missing=0 | |
| for secret_name in CENTRAL_TOKEN_USERNAME CENTRAL_TOKEN_PASSWORD; do | |
| if [[ -z "${!secret_name}" ]]; then | |
| echo "::error::Missing required secret: ${secret_name}" | |
| missing=1 | |
| fi | |
| done | |
| if [[ -z "${{ secrets.GPG_PRIVATE_KEY }}" ]]; then | |
| echo "::error::Missing required secret: GPG_PRIVATE_KEY" | |
| missing=1 | |
| fi | |
| if [[ "${missing}" -ne 0 ]]; then | |
| exit 1 | |
| fi | |
| - name: Set Up JDK 25 | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: temurin | |
| java-version: '25' | |
| cache: maven | |
| server-id: central | |
| server-username: CENTRAL_TOKEN_USERNAME | |
| server-password: CENTRAL_TOKEN_PASSWORD | |
| gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} | |
| - name: Resolve Release Version | |
| id: release_version | |
| shell: bash | |
| run: | | |
| version="" | |
| if [[ "${{ github.event_name }}" == "release" ]]; then | |
| version="${{ github.event.release.tag_name }}" | |
| elif [[ -n "${{ inputs.release_version }}" ]]; then | |
| version="${{ inputs.release_version }}" | |
| fi | |
| version="${version#v}" | |
| echo "value=${version}" >> "$GITHUB_OUTPUT" | |
| - name: Apply Release Version | |
| if: ${{ steps.release_version.outputs.value != '' }} | |
| run: mvn -B -ntp versions:set -DnewVersion=${{ steps.release_version.outputs.value }} -DgenerateBackupPoms=false | |
| - name: Verify Build | |
| run: mvn -B -ntp test | |
| - name: Publish Package | |
| run: mvn -B -ntp -Prelease clean deploy |