feat: update release workflow to allow manual version input and improve version handling

This commit is contained in:
extio-de
2026-05-08 19:33:00 +02:00
parent 6235c49358
commit 0651a66374

View File

@@ -1,16 +1,18 @@
# This workflow derives the next release version from the repository, tags it, # This workflow creates a release from a manually supplied version,
# updates the published release, and deploys the artifact to Maven Central. # commits the release-version files first, tags that exact commit, and deploys to Maven Central.
name: Release To Maven Central name: Release To Maven Central
on: on:
release: workflow_dispatch:
types: [published] inputs:
version:
description: Release version, for example 2.6.0 or v2.6.0
required: true
type: string
jobs: jobs:
publish: publish:
if: ${{ !github.event.release.prerelease }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
contents: write contents: write
@@ -34,27 +36,28 @@ jobs:
run: | run: |
git config user.name "github-actions[bot]" git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Calculate release version - name: Read release version input
id: version id: version
shell: bash shell: bash
run: | run: |
set -euo pipefail set -euo pipefail
current_version="$(mvn -q -DforceStdout help:evaluate -Dexpression=project.version | tail -n 1 | tr -d '\r')" requested_version="${{ inputs.version }}"
base_version="${current_version%-SNAPSHOT}" release_tag="$requested_version"
release_version="${requested_version#v}"
if [[ ! "$base_version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then if [[ ! "$release_version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
echo "Unsupported project version format: $current_version" >&2 echo "Unsupported release version format: $requested_version" >&2
exit 1 exit 1
fi fi
major="${BASH_REMATCH[1]}" if git ls-remote --exit-code --tags origin "refs/tags/$release_tag" >/dev/null 2>&1; then
minor="${BASH_REMATCH[2]}" echo "Tag already exists on origin: $release_tag" >&2
release_version="${major}.$((minor + 1)).0" exit 1
fi
echo "current_version=$current_version" >> "$GITHUB_OUTPUT"
echo "release_version=$release_version" >> "$GITHUB_OUTPUT" echo "release_version=$release_version" >> "$GITHUB_OUTPUT"
echo "release_tag=$release_version" >> "$GITHUB_OUTPUT" echo "release_tag=$release_tag" >> "$GITHUB_OUTPUT"
- name: Update release files - name: Update release files
env: env:
RELEASE_VERSION: ${{ steps.version.outputs.release_version }} RELEASE_VERSION: ${{ steps.version.outputs.release_version }}
@@ -66,13 +69,18 @@ jobs:
- name: Commit release version - name: Commit release version
env: env:
RELEASE_VERSION: ${{ steps.version.outputs.release_version }} RELEASE_VERSION: ${{ steps.version.outputs.release_version }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: | run: |
set -euo pipefail set -euo pipefail
git add pom.xml README.md git add pom.xml README.md
git commit -m "chore: release $RELEASE_VERSION" if git diff --cached --quiet; then
git push origin HEAD:${{ github.event.repository.default_branch }} echo "Repository version already matches $RELEASE_VERSION"
- name: Create release tag else
git commit -m "chore: release $RELEASE_VERSION"
git push origin HEAD:"$DEFAULT_BRANCH"
fi
- name: Create and push release tag
env: env:
RELEASE_TAG: ${{ steps.version.outputs.release_tag }} RELEASE_TAG: ${{ steps.version.outputs.release_tag }}
run: | run: |
@@ -80,22 +88,19 @@ jobs:
git tag "$RELEASE_TAG" git tag "$RELEASE_TAG"
git push origin "$RELEASE_TAG" git push origin "$RELEASE_TAG"
- name: Retarget GitHub release
env:
GH_TOKEN: ${{ github.token }}
RELEASE_ID: ${{ github.event.release.id }}
RELEASE_TAG: ${{ steps.version.outputs.release_tag }}
run: |
set -euo pipefail
gh api "repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}" \
--method PATCH \
-f tag_name="$RELEASE_TAG" \
-f target_commitish="${{ github.event.repository.default_branch }}" \
-f name="$RELEASE_TAG"
- name: Publish package - name: Publish package
run: mvn -B -P release deploy -DskipTests run: mvn -B -P release deploy -DskipTests
env: env:
MAVEN_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }} MAVEN_USERNAME: ${{ secrets.CENTRAL_TOKEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.CENTRAL_TOKEN_PASSWORD }} MAVEN_PASSWORD: ${{ secrets.CENTRAL_TOKEN_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_SIGNING_KEY_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