Files
lm-lib/.github/workflows/maven-publish.yml
extio-de d64a7d0ad5 fix: pin Maven 3.9.16 via Maven Wrapper for release workflow
setup-java@v4 has no maven-version input, so the previous pin was
silently ignored and the runner kept using Maven 3.10, whose stray
staging files still got bundled and rejected by Central. Add the
Maven Wrapper pinned to 3.9.16 and switch the workflow to ./mvnw.
2026-10-17 21:41:44 +02:00

111 lines
3.7 KiB
YAML

# This workflow creates a release from a manually supplied version,
# commits the release-version files first, tags that exact commit, and deploys to Maven Central.
name: Release To Maven Central
on:
workflow_dispatch:
inputs:
version:
description: Release version, for example 2.6.0 or v2.6.0
required: true
type: string
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.repository.default_branch }}
- name: Set up JDK 25
uses: actions/setup-java@v4
with:
java-version: '25'
distribution: 'temurin'
# Maven itself is pinned via the Maven Wrapper (.mvn/wrapper), because
# Maven 3.10 leaves _remote.repositories / maven-metadata files in the
# staging dir and central-publishing-maven-plugin bundles them, so
# Central rejects the deployment. Keep pinned until upstream is fixed.
server-id: central
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.GPG_SIGNING_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Read release version input
id: version
shell: bash
run: |
set -euo pipefail
requested_version="${{ inputs.version }}"
release_tag="$requested_version"
release_version="${requested_version#v}"
if [[ ! "$release_version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
echo "Unsupported release version format: $requested_version" >&2
exit 1
fi
if git ls-remote --exit-code --tags origin "refs/tags/$release_tag" >/dev/null 2>&1; then
echo "Tag already exists on origin: $release_tag" >&2
exit 1
fi
echo "release_version=$release_version" >> "$GITHUB_OUTPUT"
echo "release_tag=$release_tag" >> "$GITHUB_OUTPUT"
- name: Update release files
env:
RELEASE_VERSION: ${{ steps.version.outputs.release_version }}
run: |
set -euo pipefail
./mvnw -B versions:set -DnewVersion="$RELEASE_VERSION" -DgenerateBackupPoms=false
perl -0pi -e 's{<version>\d+\.\d+\.\d+</version>}{<version>'"$RELEASE_VERSION"'</version>}g' README.md
- name: Commit release version
env:
RELEASE_VERSION: ${{ steps.version.outputs.release_version }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
set -euo pipefail
git add pom.xml README.md
if git diff --cached --quiet; then
echo "Repository version already matches $RELEASE_VERSION"
else
git commit -m "chore: release $RELEASE_VERSION"
git push origin HEAD:"$DEFAULT_BRANCH"
fi
- name: Create and push release tag
env:
RELEASE_TAG: ${{ steps.version.outputs.release_tag }}
run: |
set -euo pipefail
git tag "$RELEASE_TAG"
git push origin "$RELEASE_TAG"
- name: Publish package
run: ./mvnw -B -P release deploy -DskipTests
env:
MAVEN_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.CENTRAL_TOKEN_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_SIGNING_KEY_PASSWORD }}
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ steps.version.outputs.release_tag }}
run: |
set -euo pipefail
gh release create "$RELEASE_TAG" \
--title "$RELEASE_TAG" \
--generate-notes