qbak 1.5.1

A single-command backup helper for Linux and POSIX systems
Documentation
name: CI

on:
  push:
    branches: [ "main", "dev", "feature/*" ]
  pull_request:
    branches: [ "main", "dev" ]

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: 1

jobs:
  # Check code formatting and linting
  check:
    name: Check
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

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

      - name: Cache dependencies
        uses: Swatinem/rust-cache@v2

      - name: Check formatting
        run: cargo fmt --all -- --check

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

      - name: Check documentation
        run: cargo doc --no-deps --document-private-items
        env:
          RUSTDOCFLAGS: -D warnings

  # Test on multiple platforms and Rust versions
  test:
    name: Test Suite
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        rust: [1.71.0, stable, beta]
        exclude:
          # Beta tests only on Linux to save CI time
          - os: windows-latest
            rust: beta
          - os: macos-latest
            rust: beta
    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4

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

      - name: Cache dependencies
        uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.os }}-${{ matrix.rust }}

      - name: Run tests
        run: cargo test --verbose -- --test-threads=1

      - name: Run tests with all features
        run: cargo test --verbose --all-features -- --test-threads=1

      - name: Test release build
        run: cargo test --verbose --release -- --test-threads=1

  # Build binaries for all platforms
  build:
    name: Build
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
          - target: x86_64-unknown-linux-musl
            os: ubuntu-latest
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
          - target: aarch64-unknown-linux-musl
            os: ubuntu-latest
          - target: armv7-unknown-linux-gnueabihf
            os: ubuntu-latest
          - target: x86_64-apple-darwin
            os: macos-latest
          - target: aarch64-apple-darwin
            os: macos-latest
          - target: x86_64-pc-windows-msvc
            os: windows-latest
    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      - name: Install musl tools (Linux musl only)
        if: matrix.target == 'x86_64-unknown-linux-musl'
        run: sudo apt-get install -y musl-tools

      - name: Install ARM64 musl tools (ARM64 musl only)
        if: matrix.target == 'aarch64-unknown-linux-musl'
        run: |
          sudo apt-get update
          sudo apt-get install -y musl-tools gcc-aarch64-linux-gnu

      - name: Install ARM64 cross-compilation tools
        if: matrix.target == 'aarch64-unknown-linux-gnu'
        run: |
          sudo apt-get update
          sudo apt-get install -y gcc-aarch64-linux-gnu

      - name: Install ARMv7 cross-compilation tools
        if: matrix.target == 'armv7-unknown-linux-gnueabihf'
        run: |
          sudo apt-get update
          sudo apt-get install -y gcc-arm-linux-gnueabihf

      - name: Configure cross-compilation (ARM64 Linux)
        if: contains(matrix.target, 'aarch64-unknown-linux')
        run: |
          echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
          echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV

      - name: Configure cross-compilation (ARMv7 Linux)
        if: matrix.target == 'armv7-unknown-linux-gnueabihf'
        run: |
          echo "CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc" >> $GITHUB_ENV

      - name: Cache dependencies
        uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.target }}

      - name: Build binary
        run: cargo build --release --target ${{ matrix.target }}

      - name: Upload binary (Unix)
        if: matrix.os != 'windows-latest'
        uses: actions/upload-artifact@v4
        with:
          name: qbak-${{ matrix.target }}
          path: target/${{ matrix.target }}/release/qbak
          retention-days: 7

      - name: Upload binary (Windows)
        if: matrix.os == 'windows-latest'
        uses: actions/upload-artifact@v4
        with:
          name: qbak-${{ matrix.target }}
          path: target/${{ matrix.target }}/release/qbak.exe
          retention-days: 7

  # Minimum Supported Rust Version check
  msrv:
    name: MSRV Check
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

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

      - name: Cache dependencies
        uses: Swatinem/rust-cache@v2
        with:
          key: msrv-1.71.0

      - name: Check MSRV compilation
        run: cargo check --all-targets

      - name: Test MSRV
        run: cargo test -- --test-threads=1

  # Integration tests with real file operations
  integration:
    name: Integration Tests
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

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

      - name: Cache dependencies
        uses: Swatinem/rust-cache@v2

      - name: Build release binary
        run: cargo build --release

      - name: Test CLI functionality
        run: |
          # Create test files
          echo "Test content" > test.txt
          mkdir test_dir
          echo "Nested file" > test_dir/nested.txt
          echo "Hidden file" > .hidden

          # Test basic backup
          ./target/release/qbak test.txt
          test -f test-*-qbak.txt

          # Test directory backup
          ./target/release/qbak test_dir
          test -d test_dir-*-qbak

          # Test dry run
          ./target/release/qbak --dry-run test.txt | grep "Would create backup"

          # Test verbose mode
          ./target/release/qbak --verbose test.txt | grep "Processed:"

          # Test quiet mode (should only show errors)
          ./target/release/qbak --quiet test.txt

          # Test help
          ./target/release/qbak --help | grep "qbak"

          # Test version
          ./target/release/qbak --version | grep "qbak 1.5.1"

          echo "✅ All integration tests passed!"

  # Check for unused dependencies
  unused-deps:
    name: Unused Dependencies
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

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

      - name: Install cargo-udeps
        run: cargo install cargo-udeps --locked

      - name: Cache dependencies
        uses: Swatinem/rust-cache@v2

      - name: Check for unused dependencies
        run: cargo +nightly udeps --all-targets