name: CI

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

env:
  CARGO_TERM_COLOR: always

jobs:
  test:
    name: test / ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest]
    steps:
      - uses: actions/checkout@v4

      - name: Install Rust stable
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable

      - name: Cargo cache
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
          restore-keys: |
            ${{ runner.os }}-cargo-

      - name: cargo build
        run: cargo build --all-targets --verbose

      - name: cargo test
        run: cargo test --all-targets --verbose

      - name: cargo doc
        run: cargo doc --no-deps
        env:
          RUSTDOCFLAGS: "-D warnings"

  examples:
    name: run examples
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@master
        with: { toolchain: stable }
      - name: cargo run --example hello
        run: cargo run --example hello
      - name: cargo run --example config
        run: cargo run --example config
      - name: cargo run --example literals
        run: cargo run --example literals
      - name: cargo run --example worker
        run: cargo run --example worker
      - name: cargo run --example pipeline
        run: cargo run --example pipeline
