name: Release

on:
  push:
    tags:
      - 'v*'
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always

jobs:
  publish-crate:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v6
    
    - name: Install Rust
      uses: dtolnay/rust-toolchain@stable
    
    - name: Cache Rust dependencies
      uses: Swatinem/rust-cache@v2

    - name: Run tests before publish
      run: cargo test --all-features

    - name: Install cargo-semver-checks
      uses: taiki-e/install-action@v2
      with:
        tool: cargo-semver-checks
    
    - name: Check semver compatibility
      run: cargo semver-checks check-release
    
    - name: Publish to crates.io
      run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
