name: goreleaser

on:
  push:
    # run only against tags
    tags:
      - '*'

permissions:
  contents: write
  # packages: write
  issues: write

jobs:
  build:
    # runs-on: ubuntu-latest
    name: ${{ matrix.job.os }} (${{ matrix.job.target }})
    runs-on: ${{ matrix.job.os }}
    strategy:
      fail-fast: false
      matrix:
        job:
          - {os: ubuntu-latest, target: x86_64-unknown-linux-gnu}
    steps:
      - name: Checkout
        uses: actions/checkout@v6
      - name: Fetch all tags
        run: git fetch --force --tags
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          target: ${{ matrix.job.target }}
      - uses: Swatinem/rust-cache@v2
      - name: Build on ${{ matrix.job.target }}
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --release --target=${{ matrix.job.target }}

      - uses: actions/upload-artifact@v6
        with:
          name: raffi-${{ matrix.job.target }}
          path: target/${{ matrix.job.target }}/release/raffi
  goreleaser:
    name: Goreleaser over Rust
    needs: build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v6
        with:
          fetch-depth: 0
      - uses: actions/download-artifact@v7
        with:
          name: raffi-x86_64-unknown-linux-gnu
          path: target/linux_amd64/raffi

      - name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v5
        with:
          distribution: goreleaser
          version: latest
          args: release --rm-dist
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          AUR_PRIVATE_KEY: ${{ secrets.AUR_PRIVATE_KEY }}
