# Releases to Maven Central with maven-release-plugin, the same way as a local # `./mvnw release:prepare release:perform`: bumps the version, commits, tags, # pushes to master, then builds the tag and deploys it with # central-publishing-maven-plugin. # # Required secrets, on the "release" environment (restricted to master, with required reviewers): # CENTRAL_USERNAME / CENTRAL_PASSWORD: Central Portal user token (https://central.sonatype.com/account) # GPG_PRIVATE_KEY: ASCII-armored private key of a dedicated release signing key, not a personal key # GPG_PASSPHRASE: passphrase of that key (optional) name: release on: workflow_dispatch: inputs: releaseVersion: description: "Version to release, e.g. 4.10.1 (empty: current version without -SNAPSHOT)" required: false type: string developmentVersion: description: "Next development version, e.g. 4.11.0-SNAPSHOT (empty: next patch SNAPSHOT)" required: false type: string permissions: contents: read concurrency: group: release cancel-in-progress: false jobs: release: if: github.ref == 'refs/heads/master' runs-on: ubuntu-latest environment: release permissions: contents: write # push the release commits and tag steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 - uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0 with: distribution: "zulu" java-version: "24" cache: maven server-id: central # matches publishingServerId of central-publishing-maven-plugin server-username-env-var: CENTRAL_USERNAME server-password-env-var: CENTRAL_PASSWORD - name: Configure git env: GITHUB_TOKEN: ${{ github.token }} run: | git config --global user.name "${GITHUB_ACTOR}" git config --global user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com" # the pom's developerConnection is an SSH URL: let maven-release-plugin push and clone over HTTPS git config --global url."https://x-access-token:${GITHUB_TOKEN}@github.com/".insteadOf "git@github.com:" - name: Release env: RELEASE_VERSION: ${{ inputs.releaseVersion }} DEVELOPMENT_VERSION: ${{ inputs.developmentVersion }} CENTRAL_USERNAME: ${{ secrets.CENTRAL_USERNAME }} CENTRAL_PASSWORD: ${{ secrets.CENTRAL_PASSWORD }} # read by the BouncyCastle signer of maven-gpg-plugin (-Dgpg.signer=bc): no gpg binary nor keyring MAVEN_GPG_KEY: ${{ secrets.GPG_PRIVATE_KEY }} MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} run: | args=() if [ -n "${RELEASE_VERSION}" ]; then args+=("-DreleaseVersion=${RELEASE_VERSION}"); fi if [ -n "${DEVELOPMENT_VERSION}" ]; then args+=("-DdevelopmentVersion=${DEVELOPMENT_VERSION}"); fi # release:prepare's `clean verify` runs the tests and integration tests on the # release commit; release:perform rebuilds that same commit from the tag, so skip them there ./mvnw --batch-mode "${args[@]}" release:prepare -Darguments=-Dgpg.signer=bc ./mvnw --batch-mode release:perform "-Darguments=-Dgpg.signer=bc -Dmaven.test.skip=true"