Skip to content

Release Workflow

Release Workflow #3

Workflow file for this run

name: Release Workflow
on:
workflow_dispatch:
inputs:
tag:
description: 'Tag for the release (format: v{x}.{y}.{z})'
required: true
default: ''
release_name:
description: 'Release name/title'
required: true
default: ''
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
# Checkout repository
- name: Checkout repository
uses: actions/checkout@v3
# Set up Java environment
- name: Set up Java 21
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '21'
# Extract version from the provided tag
- name: Extract version from input tag
id: extract_version
run: |
TAG="${{ github.event.inputs.tag }}"
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Tag format must be v{x}.{y}.{z}"
exit 1
fi
VERSION="${TAG#v}"
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
echo "RELEASE_VERSION=${MAJOR}.${MINOR}.${PATCH}-1.21.3" >> $GITHUB_ENV
echo "NEXT_SNAPSHOT_VERSION=${MAJOR}.${MINOR}.$((PATCH + 1))-1.21.3-SNAPSHOT" >> $GITHUB_ENV
# Update pom.xml to release version
- name: Update version in pom.xml for release
run: |
mvn versions:set -DnewVersion="${{ env.RELEASE_VERSION }}"
mvn versions:commit
# Commit the updated pom.xml for release version
- name: Commit updated pom.xml
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git commit -am "Set version to ${{ env.RELEASE_VERSION }}"
# Build the project
- name: Build with Maven
run: |
mvn install
mvn package
# Upload JAR files to GitHub Release
- name: Upload JAR files to GitHub Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: "${{ github.workspace }}/target/*.jar"
# Create a new tag for the release version
- name: Create tag for release
run: |
git tag "v${{ env.RELEASE_VERSION }}"
# Update pom.xml to next SNAPSHOT version
- name: Update version in pom.xml to next SNAPSHOT
run: |
mvn versions:set -DnewVersion="${{ env.NEXT_SNAPSHOT_VERSION }}"
mvn versions:commit
# Commit updated pom.xml for next SNAPSHOT version
- name: Commit next SNAPSHOT version
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git commit -am "Set version to ${{ env.NEXT_SNAPSHOT_VERSION }}"
# Push changes back to the repository
- name: Push changes
uses: ad-m/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# Create and publish the release
- name: Create and publish release
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const tagName = context.payload.inputs.tag;
const releaseName = context.payload.inputs.release_name;
await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tagName,
name: releaseName,
draft: false
});