Skip to content

Release patch

Release patch #14

Workflow file for this run

name: Release
run-name: "Release ${{ inputs.bump }}${{ inputs.prerelease && ' (RC)' || '' }}"
on:
workflow_dispatch:
inputs:
bump:
description: 'Version bump type'
required: true
type: choice
options:
- patch
- minor
- major
prerelease:
description: 'Pre-release (will append -rc.N)'
required: false
type: boolean
default: false
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine release version
id: version
run: |
# Get latest stable tag (exclude RCs)
LATEST_STABLE=$(git tag -l 'v*' | grep -v '\-rc\.' | sort -V | tail -n1)
if [[ -z "$LATEST_STABLE" ]]; then
# No stable tags exist, start from v0.0.0
LATEST_STABLE="v0.0.0"
fi
echo "Latest stable: $LATEST_STABLE"
# Parse version components
VERSION_NUM=${LATEST_STABLE#v}
MAJOR=$(echo "$VERSION_NUM" | cut -d. -f1)
MINOR=$(echo "$VERSION_NUM" | cut -d. -f2)
PATCH=$(echo "$VERSION_NUM" | cut -d. -f3)
# Calculate next version based on bump type
case "${{ inputs.bump }}" in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
esac
NEXT_VERSION="v${MAJOR}.${MINOR}.${PATCH}"
echo "Next version: $NEXT_VERSION"
if [[ "${{ inputs.prerelease }}" == "true" ]]; then
# Pre-release: find existing RCs and create next one
EXISTING_RCS=$(git tag -l "${NEXT_VERSION}-rc.*" | sort -V)
if [[ -z "$EXISTING_RCS" ]]; then
RELEASE_VERSION="${NEXT_VERSION}-rc.0"
else
LAST_RC=$(echo "$EXISTING_RCS" | tail -n1)
LAST_RC_NUM=$(echo "$LAST_RC" | sed "s/${NEXT_VERSION}-rc\.//")
NEXT_RC_NUM=$((LAST_RC_NUM + 1))
RELEASE_VERSION="${NEXT_VERSION}-rc.${NEXT_RC_NUM}"
fi
echo "Creating pre-release: $RELEASE_VERSION"
echo "is_prerelease=true" >> $GITHUB_OUTPUT
else
# Stable release
EXISTING_RCS=$(git tag -l "${NEXT_VERSION}-rc.*" | sort -V)
if [[ -n "$EXISTING_RCS" ]]; then
echo "Promoting from RC to stable: $NEXT_VERSION"
else
echo "Creating fresh release: $NEXT_VERSION"
fi
RELEASE_VERSION="$NEXT_VERSION"
echo "is_prerelease=false" >> $GITHUB_OUTPUT
fi
echo "version=$RELEASE_VERSION" >> $GITHUB_OUTPUT
echo "base_version=$NEXT_VERSION" >> $GITHUB_OUTPUT
- name: Check if tag already exists
run: |
if git rev-parse "${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
echo "::error::Tag ${{ steps.version.outputs.version }} already exists!"
exit 1
fi
- name: Create and push tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "${{ steps.version.outputs.version }}" -m "Release ${{ steps.version.outputs.version }}"
git push origin "${{ steps.version.outputs.version }}"
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.24"
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
- name: Summary
run: |
echo "## 馃崊 Release Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| | |" >> $GITHUB_STEP_SUMMARY
echo "|---|---|" >> $GITHUB_STEP_SUMMARY
echo "| **Version** | \`${{ steps.version.outputs.version }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| **Bump Type** | \`${{ inputs.bump }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| **Type** | ${{ steps.version.outputs.is_prerelease == 'true' && '馃И Pre-release (RC)' || '馃殌 Stable Release' }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Commit** | \`${{ github.sha }}\` |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 馃摝 Assets" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Platform | Architecture |" >> $GITHUB_STEP_SUMMARY
echo "|----------|--------------|" >> $GITHUB_STEP_SUMMARY
echo "| Linux | amd64, arm64 |" >> $GITHUB_STEP_SUMMARY
echo "| macOS | amd64, arm64 |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 馃敆 Links" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- [Release Page](https://github.com/tomatool/tomato/releases/tag/${{ steps.version.outputs.version }})" >> $GITHUB_STEP_SUMMARY
update-action-tag:
needs: release
runs-on: ubuntu-latest
if: ${{ inputs.prerelease == false }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Update major version tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Get the version we just released
LATEST_TAG=$(git tag -l 'v*' | grep -v '\-rc\.' | sort -V | tail -n1)
MAJOR_VERSION=$(echo "$LATEST_TAG" | cut -d. -f1)
echo "Updating $MAJOR_VERSION tag to point to $LATEST_TAG"
# Update major version tag (e.g., v2 -> v2.1.0)
git tag -fa "$MAJOR_VERSION" -m "Update $MAJOR_VERSION tag to $LATEST_TAG"
git push origin "$MAJOR_VERSION" --force
update-docs:
needs: release
runs-on: ubuntu-latest
if: ${{ inputs.prerelease == false }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.24"
- name: Build tomato
run: go build -o tomato .
- name: Generate documentation
run: ./tomato docs
- name: Commit and push docs
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Get the version we just released
LATEST_TAG=$(git tag -l 'v*' | grep -v '\-rc\.' | sort -V | tail -n1)
git add docs/
git diff --staged --quiet || git commit -m "docs: update documentation for $LATEST_TAG"
git push origin HEAD:main