How to Use GoReleaser to Automate Go Releases

Automate Go binary builds and GitHub releases by adding a goreleaser.yml workflow that triggers on version tags.

Create a .github/workflows/goreleaser.yml file in your repository root to trigger builds on tags and publish releases.

name: Goreleaser

on:
  push:
    tags:
      - "*"

permissions:
  contents: write

jobs:
  goreleaser:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v6
        with:
          fetch-depth: 0
      - name: Set up Go
        uses: actions/setup-go@v6
        with:
          go-version: "^1"
      - name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v7
        with:
          distribution: goreleaser
          version: latest
          args: release --clean
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - name: Trigger Go module reindex (pkg.go.dev)
        run: |
          curl -sSf "https://proxy.golang.org/github.com/${GITHUB_REPOSITORY,,}/@v/${GITHUB_REF_NAME}.info"

Push a new tag (e.g., git tag v1.0.0 && git push origin v1.0.0) to start the release process.