name: Rust

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

env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4
    - uses: Swatinem/rust-cache@v2
    - name: Install FUSE dependencies
      run: |
        sudo apt-get update
        sudo apt-get install -y libfuse3-dev
    - name: Format
      run: cargo fmt --check --all
    - name: Clippy
      run: cargo clippy --all-targets -- -D warnings

  coverage:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: Swatinem/rust-cache@v2
    - name: Install FUSE dependencies
      run: |
        sudo apt-get update
        sudo apt-get install -y libfuse3-dev
    - name: Install cargo-llvm-cov
      uses: taiki-e/install-action@cargo-llvm-cov
    - name: Generate coverage
      run: cargo llvm-cov --workspace --lib --test repository_test --lcov --output-path lcov.info
    - name: Upload to Codecov
      uses: codecov/codecov-action@v5
      with:
        files: lcov.info
        fail_ci_if_error: true
      env:
        CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
