Skip to content

Create Release

Create Release #6

Workflow file for this run

name: Create Release
on:
workflow_dispatch:
branches:
- main
- feature/**
inputs:
version:
description: 'Version to release (e.g. 0.0.0)'
required: true
default: '4.28.0'
nextVersion:
description: 'Next version for development (e.g. 0.0.0; do not include -SNAPSHOT)'
required: true
default: '4.29.0'
preRelease:
type: boolean
description: 'Is this a pre-release?'
required: true
default: false
permissions:
contents: write
actions: write
pull-requests: read
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Validate versions
run: |
VERSION_REGEX="^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$"
echo "Checking if version and nextVersion comply with semantic versioning..."
if [[ ! "${{ github.event.inputs.version }}" =~ $VERSION_REGEX ]] || [[ ! "${{ github.event.inputs.nextVersion }}" =~ $VERSION_REGEX ]]; then
echo "Error: version does not comply with semantic versioning! Use MAJOR.MINOR.PATCH pattern."
exit 1
fi
echo "Checking if version and nextVersion are identical..."
if [[ ( "${{ github.event.inputs.version }}" == "${{ github.event.inputs.nextVersion }}" ) ]]; then
echo "Error: version and nextVersion may not be identical."
exit 1
fi
echo "Checking if nextVersion is higher than version..."
IFS='.' read -ra VERSION_ARR <<< "${{ github.event.inputs.version }}"
IFS='.' read -ra NEXT_VERSION_ARR <<< "${{ github.event.inputs.nextVersion }}"
for i in "${!VERSION_ARR[@]}"; do
if (( NEXT_VERSION_ARR[i] < VERSION_ARR[i] )); then
echo "Error: next version needs to be higher than release version"
exit 1
elif (( NEXT_VERSION_ARR[i] > VERSION_ARR[i] )); then
break
fi
done
echo "Checking if tag v${{ github.event.inputs.version }} already exists..."
if git rev-parse "v${{ github.event.inputs.version }}" >/dev/null 2>&1; then
echo "Tag v${{ github.event.inputs.version }} already exists!"
exit 1
fi
echo "Creating release with version v${{ github.event.inputs.version }}."
echo "Next version will be v${{ github.event.inputs.nextVersion }}-SNAPSHOT."
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
echo "NEXT_VERSION=${{ github.event.inputs.nextVersion }}" >> $GITHUB_ENV
echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
- name: Check pre-release
run: |
echo "Creating pre-release: ${{ github.event.inputs.preRelease }}"
if [[ ${{ github.event.inputs.preRelease }} == "true" ]]; then
echo "PRE_RELEASE=true" >> $GITHUB_ENV
else
echo "Creating final release from ${{ env.BRANCH_NAME }}."
if [[ "${{ env.BRANCH_NAME }}" != "main" ]]; then
echo "Error: final releases can only be created from main branch."
exit 1
fi
echo "PRE_RELEASE=false" >> $GITHUB_ENV
fi
- name: Set up JDK 11
uses: actions/setup-java@v4.0.0
with:
java-version: '11'
distribution: 'temurin'
check-latest: true
cache: gradle
- name: Setup Gradle
uses: gradle/gradle-build-action@v3.0.0
- name: Setup git config
run: |
git config --global user.name "GitHub Action"
git config --global user.email "<>"
- name: Release with Gradle
run: ./gradlew release -Prelease.useAutomaticVersion=true -Prelease.releaseVersion=${{ env.VERSION }} -Prelease.newVersion=${{ env.NEXT_VERSION }}-SNAPSHOT
- name: Generate changelog
id: changelog
uses: mikepenz/release-changelog-builder-action@v4
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
name: Release v${{ env.VERSION }}
tag_name: ${{ env.VERSION }}
prerelease: ${{ env.PRE_RELEASE }}
body: ${{ steps.changelog.outputs.changelog }}
files: |
./build/hivemq-extension/hivemq-sparkplug-aware-extension-*.zip
./build/hivemq-extension/hivemq-sparkplug-aware-extension-*.zip.sha256