name: Main

on:
  push:
    branches:
      - main
    tags:
      - 'v[0-9]+.[0-9]+.[0-9]+'
  pull_request:
    branches:
      - main

jobs:
  test_publish:
    name: Test and publish
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - name: Checkout code
        uses: actions/checkout@v6
        with:
          fetch-depth: 0

      - name: Install dependencies
        run: make setup

      - name: Run tests
        run: make test

      - name: Publish (dry run)
        run: cargo publish --dry-run

      - name: Publish
        if: startsWith(github.ref, 'refs/tags/v') # Only release for tagged commits.
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: make publish
