Skip to content

Create Release Tag

Create Release Tag #1

Workflow file for this run

name: Create Release Tag
on:
workflow_dispatch:
inputs:
version:
description: 'Version number (e.g., 1.2.3). Leave empty to auto-increment patch version.'
required: false
type: string
version_type:
description: 'Version increment type (only used when version is empty)'
required: false
type: choice
default: 'patch'
options:
- patch
- minor
- major
jobs:
create-tag:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get latest tag
id: get-latest
run: |
# Get the latest version tag
LATEST_TAG=$(git tag -l 'v*' --sort=-v:refname | head -n 1)
if [[ -z "$LATEST_TAG" ]]; then
LATEST_TAG="v0.0.0"
fi
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
echo "Latest tag: $LATEST_TAG"
- name: Calculate new version
id: new-version
run: |
INPUT_VERSION="${{ github.event.inputs.version }}"
VERSION_TYPE="${{ github.event.inputs.version_type }}"
LATEST_TAG="${{ steps.get-latest.outputs.latest_tag }}"
if [[ -n "$INPUT_VERSION" ]]; then
# Use provided version, strip 'v' prefix if present
NEW_VERSION="${INPUT_VERSION#v}"
else
# Parse current version
CURRENT="${LATEST_TAG#v}"
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
# Default to 0 if empty
MAJOR=${MAJOR:-0}
MINOR=${MINOR:-0}
PATCH=${PATCH:-0}
# Increment based on type
case "$VERSION_TYPE" in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch|*)
PATCH=$((PATCH + 1))
;;
esac
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
fi
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION"
- name: Validate version format
run: |
VERSION="${{ steps.new-version.outputs.new_version }}"
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Invalid version format '$VERSION'. Expected format: X.Y.Z"
exit 1
fi
- name: Check if tag exists
run: |
VERSION="${{ steps.new-version.outputs.new_version }}"
if git rev-parse "v$VERSION" >/dev/null 2>&1; then
echo "Error: Tag v$VERSION already exists!"
exit 1
fi
- name: Create and push tag
run: |
VERSION="${{ steps.new-version.outputs.new_version }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "v$VERSION" -m "Release v$VERSION"
git push origin "v$VERSION"
echo "✅ Created and pushed tag: v$VERSION"
- name: Summary
run: |
echo "## Release Tag Created" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Previous version:** ${{ steps.get-latest.outputs.latest_tag }}" >> $GITHUB_STEP_SUMMARY
echo "- **New version:** v${{ steps.new-version.outputs.new_version }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "The release workflow will now build and publish the installers." >> $GITHUB_STEP_SUMMARY