name: Release

permissions:
  contents: write
  actions: write

env:
  CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
  CARGO_TERM_COLOR: always

  RUST_BACKTRACE: full

on:
  push:
    tags:
      - "v[0-9]+.[0-9]+.[0-9]+"

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
  release:
    name: Release
    runs-on: ubuntu-latest
    steps:
      - name: Publish
        uses: ncipollo/release-action@v1.20.0
        with:
          discussionCategoryName: Announcements
          generateReleaseNotes: true

  publish-on-crates-io:
    name: Publish on crates.io
    runs-on: ubuntu-latest
    steps:
      - name: Fetch latest code
        uses: actions/checkout@v6

      - name: Login
        run: cargo login ${{ secrets.CARGO_REGISTRY_TOKEN }}

      - name: Publish
        run: cargo publish --locked
