Skip to content

Release

Release #37

Workflow file for this run

name: Release
on:
workflow_dispatch:
inputs:
section:
type: choice
description: Create release tag by incrementing sem-ver section.
options:
- PATCH
- MINOR
- MAJOR
- RERUN
- MANUAL
required: true
default: PATCH
version:
type: string
description: |
Manually setup version (like: 1.2.3).
required: false
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.CI_TOKEN }}
- name: Get versions
id: versions
env:
MANUAL_VERSION: ${{ inputs.version }}
INCREMENT_SECTION: ${{ inputs.section }}
run: |
declare -r GIT_VERSION="$(git tag -l 'v[0-9]*.[0-9]*.[0-9]*' --sort=-v:refname | head -n 1 | cut -c2-)"
declare -r VERSION=${GIT_VERSION:-0.0.0}
declare -r MAJOR="$(echo "$VERSION" | cut -d. -f1)"
declare -r MINOR="$(echo "$VERSION" | cut -d. -f2)"
declare -r PATCH="$(echo "$VERSION" | cut -d. -f3)"
declare NEXT_VERSION=""
if [ "$INCREMENT_SECTION" == "MANUAL" ]; then
if [ "$MANUAL_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]; then
NEXT_VERSION="$MANUAL_VERSION"
else
echo "Invalid manual version: $MANUAL_VERSION" >&2
return 1
fi
elif [ "$INCREMENT_SECTION" == "PATCH" ]; then
NEXT_VERSION="$MAJOR.$MINOR.$(( PATCH + 1 ))"
elif [ "$INCREMENT_SECTION" == "MINOR" ]; then
NEXT_VERSION="$MAJOR.$(( MINOR + 1 )).0"
elif [ "$INCREMENT_SECTION" == "MAJOR" ]; then
NEXT_VERSION="$(( MAJOR + 1 )).0.0"
elif [ "$INCREMENT_SECTION" == "RERUN" ]; then
NEXT_VERSION="$VERSION"
git tag -d "v$NEXT_VERSION" || echo "Local tag does not exist: v$NEXT_VERSION"
git push --delete origin "v$NEXT_VERSION" || echo "Remote tag does not exist: v$NEXT_VERSION"
else
echo "Unrecognized option: $INCREMENT_SECTION" >&2
return 1
fi
echo "next_version=$NEXT_VERSION" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo -e "VERSION: $VERSION\nNEXT_VERSION: $NEXT_VERSION"
- name: Create Release Tag
env:
NEXT_VERSION: ${{ steps.versions.outputs.next_version }}
run: |
git tag "v$NEXT_VERSION"
git push origin "v$NEXT_VERSION"