name: GoReleaser

on:
  push:
    tags:
      - 'v0*'
      - 'v1*'
    branches:
      - 'main'
  pull_request:
    branches:
      - 'main'

permissions:
  contents: write

env:
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  SNAPSHOT: ${{ !startsWith(github.ref, 'refs/tags/v') && '--snapshot' || '' }}

jobs:
  goreleaser:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 0
      - name: check disk usage
        run: df -h
      - name: cleanup disk
        run: |
            sudo rm -rf /usr/share/dotnet
            sudo rm -rf /opt/ghc
            sudo rm -rf /usr/local/share/boost
            sudo rm -fr /usr/local/lib/android
            sudo rm -fr /opt/hostedtoolcache/CodeQL
            sudo docker image prune --all --force
            sudo docker builder prune -a -f
      - uses: actions/setup-go@v6
        with:
          go-version-file: go.mod
      - name: check disk usage
        run: df -h
      - uses: goreleaser/goreleaser-action@v7
        with:
          version: latest
          args: release --clean ${{ env.SNAPSHOT }}
