name: goreleaser

on:
  push:
    branches:
      - main
    tags:
      - '*'
  pull_request:
    types: [opened, reopened, synchronize]

permissions:
  contents: write

jobs:
  goreleaser:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up Go
        uses: actions/setup-go@v4
        with:
          go-version: 1.21

      - name: Run GoReleaser release (SKIP publish)
        uses: goreleaser/goreleaser-action@v5
        if: startsWith(github.ref, 'refs/tags/') != true
        with:
          distribution: goreleaser
          version: latest
          args: release --clean --skip=publish --snapshot
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Run GoReleaser release
        uses: goreleaser/goreleaser-action@v5
        if: startsWith(github.ref, 'refs/tags/')
        with:
          distribution: goreleaser
          version: latest
          args: release --clean
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
