name: CI

on:
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]
  release:
    types: [published]

env:
  CARGO_TERM_COLOR: always

jobs:
  build_and_test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Use Rust stable
        run: rustup update stable && rustup default stable
      - name: Build project
        run: cargo build --verbose
      - name: Run tests
        run: cargo test --verbose
      - name: Publish (on tag)
        if: github.ref_type == 'tag'
        run: cargo publish --verbose
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}