Skip to content

Release

Release #31

Workflow file for this run

name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
bump:
description: 'Version bump type'
required: false
default: 'none'
type: choice
options:
- none
- patch
- minor
- major
dry_run:
description: 'Dry run (build only, no release)'
required: false
default: true
type: boolean
permissions:
contents: write
jobs:
# ============================================================
# Version Bump: Create tag based on bump type (manual trigger)
# ============================================================
bump-version:
if: github.event_name == 'workflow_dispatch' && inputs.bump != 'none'
runs-on: ubuntu-latest
outputs:
new_tag: ${{ steps.bump.outputs.new_tag }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch all tags
run: git fetch --tags --force
- name: Get latest tag and bump version
id: bump
env:
BUMP_TYPE: ${{ inputs.bump }}
run: |
LATEST=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "Latest tag: $LATEST"
VERSION="${LATEST#v}"
MAJOR="${VERSION%%.*}"
REST="${VERSION#*.}"
MINOR="${REST%%.*}"
PATCH="${REST#*.}"
if [ "$PATCH" = "$REST" ]; then
PATCH="0"
fi
case "$BUMP_TYPE" in
major) NEW_TAG="v$((MAJOR + 1)).0.0" ;;
minor) NEW_TAG="v${MAJOR}.$((MINOR + 1)).0" ;;
patch) NEW_TAG="v${MAJOR}.${MINOR}.$((PATCH + 1))" ;;
esac
echo "Bumping $LATEST -> $NEW_TAG ($BUMP_TYPE)"
echo "new_tag=$NEW_TAG" >> "$GITHUB_OUTPUT"
- name: Create and push tag
env:
NEW_TAG: ${{ steps.bump.outputs.new_tag }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "$NEW_TAG"
git push origin "$NEW_TAG"
echo "Created and pushed $NEW_TAG"
# ============================================================
# Release: Build and publish with GoReleaser
# ============================================================
goreleaser:
needs: [bump-version]
if: always() && !cancelled()
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ needs.bump-version.outputs.new_tag || github.ref }}
- uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
args: release ${{ (github.event_name == 'workflow_dispatch' && inputs.dry_run) && '--snapshot --clean' || '--clean' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_TAP_TOKEN: ${{ secrets.SCOOP_TOKEN }}
SCOOP_TOKEN: ${{ secrets.SCOOP_TOKEN }}