Skip to content

publish

publish #5

Workflow file for this run

# Publish release artifacts to Maven Central when a GitHub Release is created,
# or when this workflow is run manually from the Actions tab.
# See DEPLOY.md for required release environment secrets and release process.
name: publish
on:
release:
types: [created]
workflow_dispatch:
inputs:
tag:
description: Release tag to publish (for example v1.2.0)
required: true
type: string
permissions:
contents: read
jobs:
publish:
runs-on: ubuntu-latest
environment: release
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1
with:
egress-policy: audit
- name: Checkout release tag
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.event.release.tag_name || github.event.inputs.tag }}
- name: Setup Java and Maven Central credentials
uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5.1.0
with:
distribution: temurin
java-version: "11"
cache: maven
server-id: central
server-username: MAVEN_USERNAME
server-password: MAVEN_CENTRAL_TOKEN
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE
- name: Set project version from release tag
run: |
VERSION="${TAG_NAME#v}"
if [ -z "$VERSION" ]; then
echo "Release tag must be vX.Y.Z (for example v1.2.0)" >&2
exit 1
fi
mvn -B org.codehaus.mojo:versions-maven-plugin:2.17.1:set \
-DnewVersion="$VERSION" \
-DgenerateBackupPoms=false
env:
TAG_NAME: ${{ github.event.release.tag_name || github.event.inputs.tag }}
- name: Verify formatting
run: mvn -B spotless:check
- name: Test
run: mvn -B test
- name: Publish to Maven Central
run: mvn -B clean deploy -Dgpg.keyname="${GPG_KEY_ID}"
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
GPG_KEY_ID: ${{ secrets.MAVEN_GPG_KEY_ID }}