name: CI

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

env:
  CARGO_TERM_COLOR: always
  RUSTFLAGS: "-D warnings"

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

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy

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

      - name: rustfmt
        run: cargo fmt --all -- --check

      - name: clippy
        run: cargo clippy --all-targets -- -D warnings

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

  integration-tmux:
    name: tmux integration (feature = tmux-it)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5

      - name: Install tmux
        run: sudo apt-get update && sudo apt-get install -y tmux

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

      - name: Cache cargo
        uses: actions/cache@v5
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
            target
          key: ubuntu-latest-cargo-tmux-it-${{ hashFiles('**/Cargo.lock') }}

      - name: test with tmux-it
        run: cargo test --features tmux-it --all-targets
