dirscan 1.1.0

A high performance tool for summarizing large directories or drives
on: [push]

name: CI

jobs:
  build_and_test:
    name: Rust project
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        include:
          - os: ubuntu-latest
            bin: dirscan
            name: dirscan-Linux-x86_64.tar.gz
          - os: macOS-latest
            bin: dirscan
            name: dirscan-Darwin-x86_64.tar.gz
          - os: windows-latest
            bin: dirscan.exe
            name: dirscan-Windows-x86_64.zip
    steps:
      - uses: actions/checkout@master
      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true

      # Caching setup
      - name: Cache cargo registry
        uses: actions/cache@v1
        with:
          path: ~/.cargo/registry
          key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
      - name: Cache cargo index
        uses: actions/cache@v1
        with:
          path: ~/.cargo/git
          key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
      - name: Cache cargo build
        uses: actions/cache@v1
        with:
          path: target
          key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

      - name: Build
        uses: actions-rs/cargo@v1
        with:
          command: build

      - name: Simple Test
        run: |
          cargo run -- scan $(pwd) --format=json -o output.json
          cargo run -- stream $(pwd) > out
          cargo run -- parse output.json --depth=1

      - name: Build release
        if: startsWith(github.ref, 'refs/tags/')
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --release
      - name: Package
        if: startsWith(github.ref, 'refs/tags/')
        shell: bash
        run: |
          strip target/release/${{ matrix.bin }}
          cd target/release
          if [[ "${{ matrix.os }}" == "windows-latest" ]]
          then
          7z a ../../${{ matrix.name }} ${{ matrix.bin }}
          else
          tar czvf ../../${{ matrix.name }} ${{ matrix.bin }}
          fi
          cd -
      - name: Publish
        uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          draft: false
          files: 'dirscan*'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  check:
    name: Check
    runs-on: ubuntu-latest
    steps:
      - name: Checkout sources
        uses: actions/checkout@v1

      - name: Install stable toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true

      - name: Run cargo check
        uses: actions-rs/cargo@v1
        with:
          command: check

  clippy:
    name: Clippy
    runs-on: ubuntu-latest
    steps:
      - name: Checkout sources
        uses: actions/checkout@v1

      - name: Install stable toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
          components: clippy

      - uses: actions-rs/clippy-check@v1
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          args: --all-features

  fmt:
    name: Rustfmt
    runs-on: ubuntu-latest
    steps:
      - name: Checkout sources
        uses: actions/checkout@v1

      - name: Install stable toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
          components: rustfmt

      - name: Run cargo fmt
        uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: --all -- --check