Files
shared-actions/.github/workflows/go-release.yaml
T

155 lines
4.7 KiB
YAML

name: Go Release
on:
workflow_call:
inputs:
go-version:
description: "Go version to use"
required: false
type: string
default: ">=1.21"
semver-config:
description: "Path to semver config file"
required: false
type: string
default: "semver.yaml"
docker-enabled:
description: "Enable Docker builds (requires QEMU, Buildx, GHCR login)"
required: false
type: boolean
default: false
docker-registry:
description: "Docker registry to push to"
required: false
type: string
default: "ghcr.io"
rolling-release-tag:
description: "Create a rolling release tag (e.g., 'v1') that always points to latest"
required: false
type: string
default: ""
# Permissions are inherited from the caller workflow via secrets: inherit
# Caller must declare: contents: write (required), packages: write (if docker-enabled)
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}
- name: Run tests
run: go test -race -v ./...
version:
name: Calculate Version
needs: test
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version_formatted.outputs.version }}
version_tag: ${{ steps.version_formatted.outputs.version_tag }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Calculate version
id: semver
uses: lukaszraczylo/semver-generator@v1
with:
config_file: ${{ inputs.semver-config }}
repository_local: true
- name: Format version
id: version_formatted
run: |
VERSION="${{ steps.semver.outputs.semantic_version }}"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "version_tag=v${VERSION}" >> $GITHUB_OUTPUT
- name: Print version
run: |
echo "Version: ${{ steps.version_formatted.outputs.version }}"
echo "Version tag: ${{ steps.version_formatted.outputs.version_tag }}"
release:
name: Release
needs: version
if: needs.version.outputs.version_tag != ''
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}
# Docker setup (optional)
- name: Set up QEMU
if: inputs.docker-enabled
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
if: inputs.docker-enabled
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
if: inputs.docker-enabled
uses: docker/login-action@v3
with:
registry: ${{ inputs.docker-registry }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- 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 ${{ needs.version.outputs.version_tag }} -m "Release ${{ needs.version.outputs.version_tag }}" || true
git push origin ${{ needs.version.outputs.version_tag }} || true
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: "~> v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
# Rolling release (optional, e.g., v1 for GitHub Actions)
- name: Delete existing rolling release
if: inputs.rolling-release-tag != ''
run: |
gh release delete ${{ inputs.rolling-release-tag }} --cleanup-tag -y || true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create rolling release
if: inputs.rolling-release-tag != ''
uses: ncipollo/release-action@v1
with:
name: ${{ inputs.rolling-release-tag }} - ${{ needs.version.outputs.version_tag }}
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ inputs.rolling-release-tag }}
prerelease: false
allowUpdates: true
makeLatest: false
body: |
Rolling release pointing to version ${{ needs.version.outputs.version_tag }}.
Use `@${{ inputs.rolling-release-tag }}` in your GitHub Actions workflows for automatic updates.