flash-watcher 0.1.2

A blazingly fast file watcher that executes commands when files change
Documentation
name: CI

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

env:
  CARGO_TERM_COLOR: always

jobs:
  test:
    name: Test
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        rust: [stable, beta]
        exclude:
          - os: windows-latest
            rust: beta
          - os: macos-latest
            rust: beta

    steps:
    - uses: actions/checkout@v4

    - name: Install Rust
      uses: dtolnay/rust-toolchain@master
      with:
        toolchain: ${{ matrix.rust }}
        components: rustfmt, clippy

    - name: Cache cargo registry
      uses: actions/cache@v3
      with:
        path: ~/.cargo/registry
        key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

    - name: Cache cargo index
      uses: actions/cache@v3
      with:
        path: ~/.cargo/git
        key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}

    - name: Cache cargo build
      uses: actions/cache@v3
      with:
        path: target
        key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

    - name: Check formatting
      run: cargo fmt --all -- --check
      if: matrix.rust == 'stable'

    - name: Run clippy
      run: cargo clippy --all-targets --all-features -- -D warnings
      if: matrix.rust == 'stable'

    - name: Build
      run: cargo build --verbose

    - name: Run tests
      run: cargo test --verbose

    # Benchmarks are excluded from regular CI to save workflow minutes
    # They can be run manually or in dedicated benchmark workflows

  security:
    name: Security audit
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: rustsec/audit-check@v1.4.1
      with:
        token: ${{ secrets.GITHUB_TOKEN }}

  coverage:
    name: Code coverage
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/main'
    steps:
    - uses: actions/checkout@v4

    - name: Install Rust
      uses: dtolnay/rust-toolchain@stable
      with:
        components: llvm-tools-preview

    - name: Install cargo-llvm-cov
      uses: taiki-e/install-action@cargo-llvm-cov

    - name: Generate code coverage
      run: |
        # Temporarily disable benchmarks in Cargo.toml to avoid long-running benchmark execution
        sed -i 's/^\[\[bench\]\]/# [[bench]]/' Cargo.toml
        sed -i 's/^name = "file_watcher"/# name = "file_watcher"/' Cargo.toml
        sed -i 's/^harness = false/# harness = false/' Cargo.toml
        sed -i 's/^required-features = \["benchmarks"\]/# required-features = ["benchmarks"]/' Cargo.toml

        # Generate coverage reports
        cargo llvm-cov --all-features --workspace --tests --lcov --output-path lcov.info
        cargo llvm-cov --all-features --workspace --tests --html --output-dir coverage-html
        cargo llvm-cov --all-features --workspace --tests --summary-only

        # Restore benchmarks in Cargo.toml
        sed -i 's/^# \[\[bench\]\]/[[bench]]/' Cargo.toml
        sed -i 's/^# name = "file_watcher"/name = "file_watcher"/' Cargo.toml
        sed -i 's/^# harness = false/harness = false/' Cargo.toml
        sed -i 's/^# required-features = \["benchmarks"\]/required-features = ["benchmarks"]/' Cargo.toml

    - name: Upload coverage reports as artifacts
      uses: actions/upload-artifact@v4
      with:
        name: coverage-reports
        path: |
          lcov.info
          coverage-html/
        retention-days: 30