Skip to content

fix: ci

fix: ci #3

Workflow file for this run

name: Test and Tag Release
on:
push:
branches: [ "main" ]
workflow_dispatch:
inputs:
version_bump:
description: 'Version bump type'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0 # Fetch all history for tags
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.23.x
- name: Install Task
run: curl -sL https://taskfile.dev/install.sh | sh
- name: Run Tests
run: ./bin/task test
tag-release:
needs: test
runs-on: ubuntu-latest
if: success()
permissions:
contents: write
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0 # Fetch all history for tags
token: ${{ secrets.GH_PAT }}
- name: Get latest tag
id: get_latest_tag
run: |
# Get the latest tag, default to v0.0.0 if no tags exist
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "Latest tag: $LATEST_TAG"
echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
- name: Determine version bump type
id: determine_bump
run: |
# Default to patch
BUMP_TYPE="patch"
# If workflow was manually triggered, use the input
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
BUMP_TYPE="${{ github.event.inputs.version_bump }}"
else
# Check commit messages for conventional commits
# Get commits since last tag
LATEST_TAG="${{ steps.get_latest_tag.outputs.latest_tag }}"
# Get commit messages since last tag
COMMITS=$(git log ${LATEST_TAG}..HEAD --pretty=format:"%s" 2>/dev/null || git log --pretty=format:"%s")
# Check for breaking changes (major version)
if echo "$COMMITS" | grep -qE "^(feat|fix|chore|docs|style|refactor|perf|test)(\(.+\))?!:|BREAKING CHANGE:"; then
BUMP_TYPE="major"
# Check for new features (minor version)
elif echo "$COMMITS" | grep -qE "^feat(\(.+\))?:"; then
BUMP_TYPE="minor"
# Everything else is patch
else
BUMP_TYPE="patch"
fi
fi
echo "Version bump type: $BUMP_TYPE"
echo "bump_type=$BUMP_TYPE" >> $GITHUB_OUTPUT
- name: Calculate new version
id: calculate_version
run: |
LATEST_TAG="${{ steps.get_latest_tag.outputs.latest_tag }}"
BUMP_TYPE="${{ steps.determine_bump.outputs.bump_type }}"
# Remove 'v' prefix and split into components
VERSION=${LATEST_TAG#v}
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
# Calculate new version based on bump type
case $BUMP_TYPE in
major)
NEW_VERSION="v$((MAJOR + 1)).0.0"
;;
minor)
NEW_VERSION="v${MAJOR}.$((MINOR + 1)).0"
;;
patch)
NEW_VERSION="v${MAJOR}.${MINOR}.$((PATCH + 1))"
;;
esac
echo "New version: $NEW_VERSION (bump type: $BUMP_TYPE)"
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Create and push tag
run: |
NEW_VERSION="${{ steps.calculate_version.outputs.new_version }}"
# Configure git
git config user.name "GitHub Actions"
git config user.email "[email protected]"
# Create annotated tag
git tag -a "$NEW_VERSION" -m "Release $NEW_VERSION - Automated ${{ steps.determine_bump.outputs.bump_type }} version bump"
# Push the tag
git push origin "$NEW_VERSION"