Skip to content

Release

Release #12

Workflow file for this run

name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Version override (e.g. v1.2.3). Leave empty to auto-detect via git-cliff.'
required: false
default: ''
permissions:
contents: write
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
- run: go test ./...
release:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
fetch-tags: true
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Ensure tags are available
run: git fetch --force --tags
- name: Determine version via git-cliff
id: cliff
uses: orhun/git-cliff-action@v4
with:
config: cliff.toml
args: --bumped-version
- name: Resolve release version
id: version
run: |
DETECTED_VERSION="$(echo "${{ steps.cliff.outputs.content }}" | tr -d '[:space:]')"
if [ -z "$DETECTED_VERSION" ]; then
LAST_TAG="$(git tag --list 'v*' --sort=-version:refname | head -n1)"
if [[ -z "$LAST_TAG" ]]; then
DETECTED_VERSION="v0.1.0"
echo "git-cliff returned empty; no prior tags found. Falling back to $DETECTED_VERSION"
elif [[ "$LAST_TAG" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
PATCH="${BASH_REMATCH[3]}"
DETECTED_VERSION="v${MAJOR}.${MINOR}.$((PATCH + 1))"
echo "git-cliff returned empty; falling back to patch bump from $LAST_TAG -> $DETECTED_VERSION"
else
echo "Error: latest tag '$LAST_TAG' is not semver (vX.Y.Z). Set workflow input 'version'." >&2
exit 1
fi
fi
VERSION="${{ inputs.version }}"
if [ -z "$VERSION" ]; then
VERSION="$DETECTED_VERSION"
fi
if [ -z "$VERSION" ]; then
echo "Error: could not determine version. git-cliff returned nothing (no prior tags?). Use the version override input." >&2
exit 1
fi
if git rev-parse -q --verify "refs/tags/$VERSION" >/dev/null; then
echo "Error: tag '$VERSION' already exists. Set workflow input 'version' to a new value." >&2
exit 1
fi
echo "Releasing $VERSION"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Generate changelog
uses: orhun/git-cliff-action@v4
with:
config: cliff.toml
args: --tag ${{ steps.version.outputs.version }} -o CHANGELOG.md
- name: Commit changelog and create tag
run: |
VERSION="${{ steps.version.outputs.version }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add CHANGELOG.md
git commit -m "chore: release $VERSION" || echo "No changelog changes to commit"
git tag -a "$VERSION" -m "$VERSION"
git push origin HEAD:main --follow-tags
- name: Ensure clean git state for goreleaser
run: |
git clean -ffdx
if [ -n "$(git status --porcelain)" ]; then
echo "Error: working tree is dirty before goreleaser." >&2
git status --porcelain
exit 1
fi
- uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}