Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# DEPRECATED: This workflow is kept for backward compatibility only
#
# Please use the automated release process instead:
# 1. Create a new release in GitHub UI with tag format vX.Y.Z
# 2. The "Automated Release" workflow will handle the rest
#
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

name: Maven Release
name: Maven Release (Manual - Deprecated)

on: workflow_dispatch
jobs:
Expand Down
164 changes: 164 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# This workflow automates the release process when a release is created on GitHub
# It uses Maven release plugin to manage versions and deploys to Maven Central
#
# Usage:
# 1. Create a new release in GitHub UI with tag format: vX.Y.Z (e.g., v1.2.0)
# - Select the target branch (typically main)
# 2. This workflow will automatically:
# - Use Maven release:prepare to update versions and create release commits
# - Use Maven release:perform to build and deploy artifacts to Maven Central
# - Move the tag to point to the actual release commit
# - Push commits back to the originating branch

name: Automated Release

on:
release:
types: [created] # Trigger when release is created

permissions:
contents: write # Required to push commits and update tags

jobs:
release:
runs-on: ubuntu-latest

steps:
- name: Validate release tag format
id: validate_tag
run: |
TAG_NAME="${{ github.event.release.tag_name }}"
echo "Release tag: $TAG_NAME"

# Validate tag format (should be vX.Y.Z)
if [[ ! "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Invalid tag format. Expected format: vX.Y.Z (e.g., v1.2.0)"
exit 1
fi

# Remove 'v' prefix to get the version number
VERSION="${TAG_NAME#v}"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"

# Calculate next development version (increment patch version)
IFS='.' read -ra VERSION_PARTS <<< "$VERSION"
MAJOR="${VERSION_PARTS[0]}"
MINOR="${VERSION_PARTS[1]}"
PATCH="${VERSION_PARTS[2]}"
NEXT_PATCH=$((PATCH + 1))
NEXT_VERSION="${MAJOR}.${MINOR}.${NEXT_PATCH}-SNAPSHOT"
echo "next_version=${NEXT_VERSION}" >> $GITHUB_OUTPUT
echo "Next development version: $NEXT_VERSION"

- name: Determine target branch
id: target_branch
run: |
# Use target_commitish to determine the originating branch
TARGET="${{ github.event.release.target_commitish }}"

# If target_commitish is empty or a SHA, default to main
if [[ -z "$TARGET" ]] || [[ "$TARGET" =~ ^[0-9a-f]{40}$ ]]; then
TARGET="main"
fi

echo "target_branch=${TARGET}" >> $GITHUB_OUTPUT
echo "Target branch: $TARGET"

- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ steps.target_branch.outputs.target_branch }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
Comment thread
thomasturrell marked this conversation as resolved.

- name: Delete user-created tag
run: |
TAG_NAME="${{ github.event.release.tag_name }}"

# Delete the tag created by the user (will be recreated by release:prepare)
git tag -d "$TAG_NAME" || true
git push origin ":refs/tags/$TAG_NAME" || true

echo "Deleted user-created tag $TAG_NAME"

- name: Set up JDK 17
uses: actions/setup-java@v5
with:
java-version: "17"
distribution: "temurin"
cache: maven
server-id: central
Comment thread
thomasturrell marked this conversation as resolved.
Outdated
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_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: Run Maven release:prepare
run: |
VERSION="${{ steps.validate_tag.outputs.version }}"
NEXT_VERSION="${{ steps.validate_tag.outputs.next_version }}"
TAG_NAME="${{ github.event.release.tag_name }}"

echo "Preparing release version: $VERSION"
echo "Next development version: $NEXT_VERSION"
echo "Tag name: $TAG_NAME"

# Run release:prepare with explicit versions
./mvnw -B release:prepare \
-DreleaseVersion="${VERSION}" \
-DdevelopmentVersion="${NEXT_VERSION}" \
Comment thread
thomasturrell marked this conversation as resolved.
Outdated
-Dtag="${TAG_NAME}" \
-DpushChanges=false \
-DremoteTagging=false
Comment thread
thomasturrell marked this conversation as resolved.
Outdated
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}

- name: Run Maven release:perform
run: |
echo "Performing release and deploying to Maven Central"

# Run release:perform to build and deploy
./mvnw -B release:perform \
-DlocalCheckout=true \
-DeployAtEnd=true
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}

- name: Push changes to originating branch
run: |
TARGET_BRANCH="${{ steps.target_branch.outputs.target_branch }}"
TAG_NAME="${{ github.event.release.tag_name }}"

echo "Pushing changes to branch: $TARGET_BRANCH"

# Push the commits created by release:prepare
if ! git push --force-with-lease origin "HEAD:${TARGET_BRANCH}"; then
echo "::error::Failed to push release commits to ${TARGET_BRANCH} due to branch divergence."
echo "The remote branch may have new commits. Please resolve the conflict manually:"
echo " 1. Fetch the latest changes: git fetch origin"
echo " 2. Rebase or merge as needed, then push again with --force-with-lease."
exit 1
fi

# Push the tag created by release:prepare
git push origin "$TAG_NAME"

echo "Pushed release commits and tag to $TARGET_BRANCH"

- name: Clean up
Comment thread
thomasturrell marked this conversation as resolved.
Outdated
if: always()
run: |
# Clean up Maven release artifacts
rm -f release.properties pom.xml.releaseBackup
find . -name "pom.xml.releaseBackup" -delete || true
find . -name "pom.xml.tag" -delete || true
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,7 @@ public ResponseEntity<Collection<UUID>> postStatements(
}

```

## Contributing

For information about creating releases, see [RELEASING.md](RELEASING.md).
Loading