80 lines
2.2 KiB
YAML
80 lines
2.2 KiB
YAML
name: Release Version
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
version:
|
|
description: 'New version (e.g., 1.0.1) or bump type (major, minor, patch)'
|
|
required: true
|
|
default: 'patch'
|
|
|
|
jobs:
|
|
bump-version:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
token: ${{ secrets.PAT_TOKEN }}
|
|
fetch-depth: 0
|
|
|
|
- name: Configure Git
|
|
run: |
|
|
git config --global user.name 'github-actions[bot]'
|
|
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
|
|
|
|
- name: Bump Version
|
|
id: bump
|
|
run: |
|
|
INPUT_VERSION="${{ inputs.version }}"
|
|
|
|
# Get the latest tag
|
|
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
|
|
echo "Latest tag: $LATEST_TAG"
|
|
|
|
# Remove 'v' prefix if present
|
|
LATEST_VERSION=${LATEST_TAG#v}
|
|
|
|
# Helper function to bump version
|
|
bump_version() {
|
|
local version=$1
|
|
local type=$2
|
|
|
|
# Split version into parts
|
|
IFS='.' read -r major minor patch <<< "$version"
|
|
|
|
case $type in
|
|
major)
|
|
major=$((major + 1))
|
|
minor=0
|
|
patch=0
|
|
;;
|
|
minor)
|
|
minor=$((minor + 1))
|
|
patch=0
|
|
;;
|
|
patch)
|
|
patch=$((patch + 1))
|
|
;;
|
|
esac
|
|
|
|
echo "${major}.${minor}.${patch}"
|
|
}
|
|
|
|
# Check if input is a valid bump type
|
|
if [[ "$INPUT_VERSION" =~ ^(major|minor|patch)$ ]]; then
|
|
NEW_VERSION=$(bump_version "$LATEST_VERSION" "$INPUT_VERSION")
|
|
else
|
|
# Set specific version
|
|
NEW_VERSION="$INPUT_VERSION"
|
|
fi
|
|
|
|
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
|
|
echo "New version: $NEW_VERSION"
|
|
|
|
- name: Create Tag and Push
|
|
run: |
|
|
git tag v${{ env.NEW_VERSION }}
|
|
git push origin v${{ env.NEW_VERSION }}
|