Skip to content

Create Release

Create Release #2

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:
description: 'Is this a pre-release?'
required: true
default: false
# updateWorkflow:
# description: 'Update workflow default versions? NOTE: A personal access token must be available as secret WORKFLOW_TOKEN for this to work!'
# required: false
# default: false
permissions:
contents: write
actions: write
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Validate versions
run: |
VERSION_REGEX="^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\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
run: |
CHANGELOG=$(git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:"- %s")
echo "::set-output name=changelog::$CHANGELOG"
- 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
# - name: Update workflow
# run: |
#
# if [[ ${{ github.event.inputs.updateWorkflow }} == "false" ]]; then
# echo "Skipping workflow update."
# exit 0
# fi
#
# IFS='.' read -ra NEXT_VERSION_ARR <<< "${{ env.NEXT_VERSION }}"
# NEXT_VERSION_MINOR=$((NEXT_VERSION_ARR[1] + 1))
# NEW_NEXT_VERSION="${NEXT_VERSION_ARR[0]}.${NEXT_VERSION_MINOR}.0"
#
# echo $NEW_NEXT_VERSION
#
# set -x
# VERSION=${{ env.NEXT_VERSION }} yq eval '.on.workflow_dispatch.inputs.version.default = env(VERSION)' -i .github/workflows/gradle-release.yml
# NEXT_VERSION=$NEW_NEXT_VERSION yq eval '.on.workflow_dispatch.inputs.nextVersion.default = env(NEXT_VERSION)' -i .github/workflows/gradle-release.yml
# set +x
#
# cat .github/workflows/gradle-release.yml
#
# git config --global user.name "GitHub Action"
# git config --global user.email "<>"
# git add .github/workflows/gradle-release.yml
# git commit -m "Update workflow default versions"
# git push