name: Release Binaries

on:
  push:
    tags:
      - "v[0-9]*"

jobs:
  release:
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: sh
    steps:
      - name: Install build tools
        run: apk add --no-cache git

      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - uses: actions/setup-go@v5
        with:
          go-version: "1.26"

      - uses: actions/cache@v4
        with:
          path: |
            ~/go/pkg/mod
            ~/.cache/go-build
          key: release-go-${{ hashFiles('go.sum') }}
          restore-keys: release-go-

      - name: Install git-cliff
        run: |
          apk add --no-cache curl
          VERSION=2.13.1
          curl -sSL "https://github.com/orhun/git-cliff/releases/download/v${VERSION}/git-cliff-${VERSION}-x86_64-unknown-linux-musl.tar.gz" | tar xz -C /tmp
          mv /tmp/git-cliff-*/git-cliff /usr/local/bin/
          git-cliff --version

      - name: Generate release notes
        run: git-cliff --current --strip header -o /tmp/release-notes.md

      - name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v7
        with:
          distribution: goreleaser
          version: "~> v2"
          args: release --clean --release-notes=/tmp/release-notes.md
        env:
          GORELEASER_CURRENT_TAG: ${{ github.ref_name }}
          GORELEASER_FORCE_TOKEN: gitea
          GITEA_TOKEN: ${{ secrets.RELEASE_TOKEN }}
          GITEA_API_URL: http://gitea:3000/api/v1
          HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}

      # GitHub release relaying is handled by .github/workflows/mirror-release.yml,
      # which runs on GitHub Actions when the push mirror delivers the tag and
      # copies this run's Gitea release assets — no PAT needed on this side.
