Skip to content

Release

Release #170

Workflow file for this run

name: Release
on:
release:
types:
- published
workflow_dispatch:
inputs:
tag_name:
description: 'Release tag to publish (e.g. v0.18.3)'
required: true
permissions:
contents: write
pull-requests: write
jobs:
sonar:
if: github.event_name == 'workflow_dispatch' || !contains(github.event.head_commit.message, '[version bump]')
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@v6
with:
ref: ${{ github.event.release.tag_name || github.event.inputs.tag_name || github.ref }}
- name: Setup Java
uses: actions/setup-java@v5
with:
distribution: 'microsoft'
java-version: '21'
cache: 'maven'
- name: Build and Analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify sonar:sonar -Dgpg.skip
publish:
if: github.event_name == 'workflow_dispatch' || !contains(github.event.head_commit.message, '[version bump]')
runs-on: ubuntu-latest
needs: [ sonar ]
steps:
- name: Checkout project
uses: actions/checkout@v6
with:
ref: ${{ github.event.release.tag_name || github.event.inputs.tag_name || github.ref }}
- name: Setup Java
uses: actions/setup-java@v5
with:
distribution: 'microsoft'
java-version: '21'
cache: 'maven'
server-id: 'central'
server-username: SONATYPE_USERNAME
server-password: SONATYPE_PASSWORD
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg-passphrase: GPG_PASSPHRASE
- name: Configure Git user
run: |
git config user.email "actions@github.com"
git config user.name "GitHub Actions"
- name: Setup release version from tag
env:
RELEASE_TAG: ${{ github.event.release.tag_name || github.event.inputs.tag_name }}
run: |
NEW_VERSION="${RELEASE_TAG#v}"
echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV
- name: Validate POM version matches release tag
run: |
POM_BASE_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | cut -d- -f1)
if [ "${POM_BASE_VERSION}" != "${NEW_VERSION}" ]; then
echo "::error::GitHub release tag v${NEW_VERSION} does not match POM version ${POM_BASE_VERSION}-SNAPSHOT. Bump the POM before publishing."
exit 1
fi
- name: Update POM Version
run: |
echo "New version is: $NEW_VERSION"
mvn versions:set -DnewVersion=${NEW_VERSION} -DgenerateBackupPoms=false -B
- name: Build and Publish
run: |
mvn \
--no-transfer-progress \
--batch-mode \
-DskipTests=true \
-Psonatype-deploy \
deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
- name: Commit files
run: |
git commit -m "[version bump]" -a
git tag -a release-$NEW_VERSION -m "[version bump]"
git push origin release-$NEW_VERSION
bump:
if: github.event_name == 'workflow_dispatch' || !contains(github.event.head_commit.message, '[version bump]')
runs-on: ubuntu-latest
needs: [ publish ]
steps:
- name: Resolve base branch
id: base
run: |
REF="${{ github.event.release.target_commitish || 'main' }}"
REF="${REF#refs/heads/}"
echo "branch=${REF}" >> $GITHUB_OUTPUT
- name: Checkout Branch
uses: actions/checkout@v6
with:
ref: ${{ steps.base.outputs.branch }}
- name: Setup Java
uses: actions/setup-java@v5
with:
distribution: 'microsoft'
java-version: '21'
cache: 'maven'
- name: Configure Git user
run: |
git config user.email "actions@github.com"
git config user.name "GitHub Actions"
- name: Bump And Update POM Version to new Development version
id: bump_version
run: |
RELEASE_VERSION="${{ github.event.release.tag_name || github.event.inputs.tag_name }}"
RELEASE_VERSION="${RELEASE_VERSION#v}"
VERSION_PARTS=($(echo "$RELEASE_VERSION" | tr "." "\n"))
NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.$((VERSION_PARTS[2]+1))-SNAPSHOT"
echo "New development version is: $NEW_VERSION"
mvn versions:set -DnewVersion=${NEW_VERSION} -DgenerateBackupPoms=false
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
commit-message: "chore: bump version to ${{ steps.bump_version.outputs.new_version }}"
title: "chore: bump version to ${{ steps.bump_version.outputs.new_version }}"
body: "Bumps the version to the next development version."
branch: "chore/bump-version-${{ steps.bump_version.outputs.new_version }}"
base: ${{ steps.base.outputs.branch }}
labels: automerge