name: CI

on:
  push:
    branches: [main, master]
  pull_request:

jobs:
  test:
    name: Test (Linux x86_64)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - uses: actions/setup-python@v5
        with:
          python-version: "3.13"
      - name: Create virtualenv + install
        run: |
          python -m venv .venv
          . .venv/bin/activate
          pip install maturin pytest
          maturin develop --release
      - name: Run 111 TOON spec fixtures
        run: |
          . .venv/bin/activate
          python -m pytest tests/test_spec_fixtures.py -q
      - name: Build CLI binary
        run: cargo build --release --bin etoon --no-default-features
      - name: Smoke-test CLI
        run: |
          echo '{"a":[1,2,3],"b":"hi"}' | ./target/release/etoon
          ./target/release/etoon --help

  rustfmt:
    name: rustfmt
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - run: cargo fmt --all -- --check

  clippy:
    name: clippy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
      - run: cargo clippy --no-default-features --all-targets -- -D warnings
