name: Release

on:
  push:
    tags:
      - 'v*'

permissions:
  contents: write

jobs:
  build:
    name: Build (${{ matrix.target }})
    runs-on: ${{ matrix.runner }}
    strategy:
      matrix:
        include:
          - target: aarch64-apple-darwin
            runner: macos-latest
          - target: x86_64-apple-darwin
            runner: macos-13

    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      - name: Build
        run: cargo build --release --target ${{ matrix.target }}

      - name: Package
        run: |
          BIN="target/${{ matrix.target }}/release/pstramp"
          ARCHIVE="pstramp-${GITHUB_REF_NAME}-${{ matrix.target }}"
          cp "$BIN" "$ARCHIVE"
          shasum -a 256 "$ARCHIVE" > "$ARCHIVE.sha256"

      - uses: actions/upload-artifact@v4
        with:
          name: pstramp-${{ matrix.target }}
          path: |
            pstramp-*-${{ matrix.target }}
            pstramp-*-${{ matrix.target }}.sha256

  release:
    name: Create Release
    needs: build
    runs-on: ubuntu-latest

    steps:
      - uses: actions/download-artifact@v4
        with:
          path: artifacts/
          merge-multiple: true

      - name: List assets
        run: ls -lh artifacts/

      - uses: softprops/action-gh-release@v2
        with:
          generate_release_notes: true
          files: artifacts/*
