name: Release

on:
  push:
    tags:
      - "*.*.*"

permissions:
  contents: write

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@stable

      - run: cargo test --verbose

      - run: cargo build --release --verbose

      - run: |
          mv target/release/sortsort \
          sortsort-${{ github.ref_name }}-x86_64-unknown-linux-gnu

      - uses: actions/upload-artifact@v4
        with:
          name: binary
          path: sortsort-${{ github.ref_name }}-x86_64-unknown-linux-gnu

  release:
    name: Release
    needs: [build]
    runs-on: ubuntu-latest

    steps:
      - uses: actions/download-artifact@v4
        with:
          name: binary
          path: dist

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