name: release

on:
  push:
    tags:
      - "v*"

permissions:
  contents: write
  id-token: write
  packages: write

jobs:
  trigger-generate:
    runs-on: ubuntu-latest
    needs: goreleaser
    steps:
      - uses: benc-uk/workflow-dispatch@v1.2.4
        with:
          ref: main
          token: ${{ secrets.GH_PAT }}
          workflow: generate.yml
  goreleaser:
    runs-on: ubuntu-latest
    env:
      DOCKER_CLI_EXPERIMENTAL: "enabled"
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: actions/setup-go@v5
        with:
          go-version: stable
      - uses: arduino/setup-task@v2
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
      - uses: sigstore/cosign-installer@v3.8.1
      - uses: anchore/sbom-action/download-syft@v0.18.0
      - uses: docker/setup-qemu-action@v3
      - uses: docker/setup-buildx-action@v3
      - uses: cachix/install-nix-action@v31
        with:
          github_access_token: ${{ secrets.GITHUB_TOKEN }}
      - run: task setup
      - run: task build
      - uses: docker/login-action@v3
        if: startsWith(github.ref, 'refs/tags/v')
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
      - uses: docker/login-action@v3
        if: startsWith(github.ref, 'refs/tags/v')
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - uses: goreleaser/goreleaser-action@v6
        if: success()
        with:
          version: latest
          args: release --clean
          distribution: goreleaser-pro
        env:
          GITHUB_TOKEN: ${{ secrets.GH_PAT }}
          GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
          TWITTER_CONSUMER_KEY: ${{ secrets.TWITTER_CONSUMER_KEY }}
          TWITTER_CONSUMER_SECRET: ${{ secrets.TWITTER_CONSUMER_SECRET }}
          TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }}
          TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}
          DISCORD_WEBHOOK_ID: ${{ secrets.DISCORD_WEBHOOK_ID }}
          DISCORD_WEBHOOK_TOKEN: ${{ secrets.DISCORD_WEBHOOK_TOKEN }}
          FURY_TOKEN: ${{ secrets.FURY_TOKEN }}
          AUR_KEY: ${{ secrets.AUR_KEY }}
