name: Release

on:
  push:
    tags:
      - "v*"

permissions:
  contents: write
  id-token: write

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install Rust
        run: |
          rustup toolchain install stable --profile minimal
          rustup default stable
      - name: Check formatting
        run: cargo fmt --check
      - name: Test
        run: cargo test --locked
      - name: Verify package
        run: cargo publish --dry-run --locked
      - name: Authenticate to crates.io
        id: auth
        uses: rust-lang/crates-io-auth-action@v1
      - name: Publish to crates.io
        run: cargo publish --locked
        env:
          CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
      - name: Create GitHub Release
        env:
          GH_TOKEN: ${{ github.token }}
        run: gh release create "${GITHUB_REF_NAME}" --title "muga ${GITHUB_REF_NAME}" --generate-notes --verify-tag
