name: Trigger Release
on:
workflow_dispatch:
inputs:
version_bump:
description: 'Version bump type (ignored if manual_tag is set)'
required: false
default: 'patch'
type: choice
options:
- 'patch'
- 'minor'
- 'major'
prerelease:
description: 'Create a prerelease version (ignored if manual_tag is set)'
required: false
default: 'none'
type: choice
options:
- 'none'
- 'beta'
- 'alpha'
manual_tag:
description: 'Manual tag to create (e.g., v1.2.3) - overrides version bump'
required: false
type: string
permissions:
contents: write
actions: write
jobs:
create-release-tag:
name: Create Release Tag
runs-on: ubuntu-latest
outputs:
new-version: ${{ steps.release.outputs.new-version }}
new-tag: ${{ steps.release.outputs.new-tag }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Create Release Tag and Trigger Workflow
id: release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Check if manual tag is provided
if [ -n "${{ github.event.inputs.manual_tag }}" ]; then
# Use manual tag
TAG="${{ github.event.inputs.manual_tag }}"
# Strip 'v' prefix if present to get version
if [[ "$TAG" == v* ]]; then
NEW_VERSION="${TAG:1}"
else
NEW_VERSION="$TAG"
TAG="v$TAG"
fi
echo "Using manual tag: $TAG"
echo "Version: $NEW_VERSION"
else
# Get current version from Cargo.toml
CURRENT_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
echo "Current version: $CURRENT_VERSION"
# Parse version components (handle prerelease versions)
BASE_VERSION=${CURRENT_VERSION%%-*}
IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE_VERSION"
# Calculate new version based on bump type
case "${{ github.event.inputs.version_bump }}" in
"major")
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
"minor")
MINOR=$((MINOR + 1))
PATCH=0
;;
"patch")
PATCH=$((PATCH + 1))
;;
esac
# Handle prerelease suffix if needed
PRERELEASE_SUFFIX=""
if [ "${{ github.event.inputs.prerelease }}" = "beta" ]; then
# Check if we're already in a beta
if [[ "$CURRENT_VERSION" == *"-beta."* ]]; then
# Increment beta number
BETA_NUM=$(echo "$CURRENT_VERSION" | grep -oP 'beta\.\K[0-9]+')
BETA_NUM=$((BETA_NUM + 1))
PRERELEASE_SUFFIX="-beta.${BETA_NUM}"
else
PRERELEASE_SUFFIX="-beta.0"
fi
elif [ "${{ github.event.inputs.prerelease }}" = "alpha" ]; then
# Check if we're already in an alpha
if [[ "$CURRENT_VERSION" == *"-alpha."* ]]; then
# Increment alpha number
ALPHA_NUM=$(echo "$CURRENT_VERSION" | grep -oP 'alpha\.\K[0-9]+')
ALPHA_NUM=$((ALPHA_NUM + 1))
PRERELEASE_SUFFIX="-alpha.${ALPHA_NUM}"
else
PRERELEASE_SUFFIX="-alpha.0"
fi
fi
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}${PRERELEASE_SUFFIX}"
TAG="v${NEW_VERSION}"
echo "New version: $NEW_VERSION"
fi
# Update Cargo.toml with new version
sed -i "s/^version = \".*\"/version = \"$NEW_VERSION\"/" Cargo.toml
# Update Cargo.lock
cargo update --workspace
# Commit version changes
git add Cargo.toml Cargo.lock
git commit -m "chore(release): ${NEW_VERSION}" || echo "No changes to commit"
# Push the commit to main
git push origin HEAD:${{ github.ref_name }}
echo "new-version=${NEW_VERSION}" >> $GITHUB_OUTPUT
echo "new-tag=$TAG" >> $GITHUB_OUTPUT
# Trigger the release workflow using workflow dispatch
echo "✅ Triggering release workflow for $TAG"
gh workflow run release.yml -f tag="$TAG"
echo "🚀 Release workflow triggered successfully!"
echo "Check the Actions tab for the release progress"
echo ""
echo "Note: Release notes will be generated automatically from commit history"