Skip to content

goreleaser

goreleaser #3

name: goreleaser
on:
push:
tags:
- 'v*'
paths:
- .github/workflows/goreleaser.yml
- .goreleaser.yaml
workflow_dispatch:
inputs:
tag:
description: 'Tag to release (e.g., v1.0.0)'
required: true
type: string
permissions:
contents: write
packages: write
id-token: write # for keyless signing with cosign
env:
REGISTRY: ghcr.io
ARCHS: linux/amd64,linux/arm64
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: v1.23
- name: Install cosign
uses: sigstore/cosign-installer@v3.5.0
- name: Install syft
uses: anchore/sbom-action/download-syft@v0.15.10
- name: Set env
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
if ! grep -E '^v[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*(-[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*)?$' <<<"${INPUT_TAG}"; then
echo 'Invalid tag format. Must be semver, e.g. v1.2.3 or v2.0.0-alpha.1'
exit 1
fi
echo "RELEASE_VERSION=${INPUT_TAG}" >> $GITHUB_ENV
else
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
fi
env:
INPUT_TAG: ${{ github.event.inputs.tag }}
- name: Create tag for manual dispatch
if: github.event_name == 'workflow_dispatch'
run: |
git tag "${INPUT_TAG}"
env:
INPUT_TAG: ${{ github.event.inputs.tag }}
- name: Delete non-semver tags
run: 'git tag -d $(git tag -l | grep -v "^v") || true'
- name: Run GoReleaser on tag
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
args: release --timeout 60m
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run GoReleaser on push without tag
if: github.event_name == 'push' && !contains(github.ref, 'refs/tags/')
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
args: release --timeout 60m --snapshot --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}