name: ci-test-build

on:
  workflow_dispatch:
  push:
    branches: [ main ]
    paths:
      - "**/*.rs"
      - "Cargo.lock"
      - "Cargo.toml"
      - ".github/workflows/ci-test-build.yml"
  pull_request:
    branches: [ main ]
    paths:
      - "**/*.rs"
      - "Cargo.lock"
      - "Cargo.toml"
      - ".github/workflows/ci-test-build.yml"

env:
  CARGO_TERM_COLOR: always

jobs:
  lints:
    name: Lints
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
          components: rustfmt, clippy
      - uses: Swatinem/rust-cache@v1
      - name: Fmt Check
        run: cargo fmt --check -v
      - name: Clippy
        run: cargo clippy -- -D warnings
      - name: Setup cargo-hack
        run: cargo install cargo-hack
      - name: Check all features
        run: cargo hack check --feature-powerset --no-dev-deps
        
  test:
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
    runs-on: ${{ matrix.os }}
            
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
      - uses: Swatinem/rust-cache@v1
      - name: Run tests
        if: matrix.os != 'windows-latest'
        run: cargo test --verbose
      - name: Run build
        run: cargo build --verbose
