Skip to content

Release

Release #5

Workflow file for this run

name: Release
on:
workflow_dispatch:
inputs:
release-version:
description: 'Release version (e.g. 1.0.0) — leave blank to use current POM version without -SNAPSHOT'
required: false
next-version:
description: 'Next development version (e.g. 1.0.1-SNAPSHOT) — leave blank to use incremented patch version with -SNAPSHOT'
required: false
permissions:
contents: write
pull-requests: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: '25'
distribution: 'zulu'
cache: 'maven'
server-id: central
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE
- name: Get cache week
id: date
run: echo "week=$(date +%Y-%W)" >> $GITHUB_OUTPUT
- name: Cache Docker images
id: cache-docker
uses: actions/cache@v4
with:
path: /tmp/docker-images
key: docker-images-${{ runner.os }}-${{ steps.date.outputs.week }}
restore-keys: |
docker-images-${{ runner.os }}-
- name: Load cached Docker images
if: steps.cache-docker.outputs.cache-hit == 'true'
run: docker load -i /tmp/docker-images/images.tar
- name: Pull and save Docker images
if: steps.cache-docker.outputs.cache-hit != 'true'
run: |
docker pull alpine:latest
docker pull nginx:latest
docker pull rabbitmq:latest
mkdir -p /tmp/docker-images
docker save alpine:latest nginx:latest rabbitmq:latest -o /tmp/docker-images/images.tar
- name: Determine Versions
id: versions
run: |
CURRENT_VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout)
RELEASE_VERSION="${{ inputs.release-version }}"
if [ -z "$RELEASE_VERSION" ]; then
RELEASE_VERSION="${CURRENT_VERSION/-SNAPSHOT/}"
fi
NEXT_VERSION="${{ inputs.next-version }}"
if [ -z "$NEXT_VERSION" ]; then
PATCH=$(echo "$RELEASE_VERSION" | cut -d. -f3)
NEXT_PATCH=$((PATCH + 1))
NEXT_VERSION=$(echo "$RELEASE_VERSION" | sed "s/\.[0-9]*$/.${NEXT_PATCH}-SNAPSHOT/")
fi
echo "release-version=$RELEASE_VERSION" >> $GITHUB_OUTPUT
echo "next-version=$NEXT_VERSION" >> $GITHUB_OUTPUT
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Create Release Branch
run: git checkout -b release-${{ steps.versions.outputs.release-version }}
- name: Set Release Version
run: |
./mvnw versions:set-property \
-Dproperty=revision \
-DnewVersion=${{ steps.versions.outputs.release-version }} \
-DgenerateBackupPoms=false
- name: Build and Deploy Release
run: ./mvnw clean deploy
env:
MAVEN_PUBLISH: "true"
MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
- name: Commit and Tag Release
run: |
git add pom.xml
git commit -m "Release ${{ steps.versions.outputs.release-version }}"
git tag -a v${{ steps.versions.outputs.release-version }} -m "Release ${{ steps.versions.outputs.release-version }}"
- name: Set Next Development Version
run: |
./mvnw versions:set-property \
-Dproperty=revision \
-DnewVersion=${{ steps.versions.outputs.next-version }} \
-DgenerateBackupPoms=false
- name: Commit Next Development Version
run: |
git add pom.xml
git commit -m "Prepare for next development iteration ${{ steps.versions.outputs.next-version }}"
- name: Push Release Branch and Tag
run: git push --follow-tags origin release-${{ steps.versions.outputs.release-version }}
- name: Open and Merge PR to main
env:
GH_TOKEN: ${{ secrets.RELEASE_TOKEN }}
run: |
PR_URL=$(gh pr create \
--base main \
--head release-${{ steps.versions.outputs.release-version }} \
--title "Prepare for development of ${{ steps.versions.outputs.next-version }}" \
--body "Prepares next development iteration **${{ steps.versions.outputs.next-version }}**.")
gh pr merge "$PR_URL" --squash