name: CI
on:
  pull_request:
    paths:
    - '**'
    - '!/*.md'
    - '!/docs/**'
    - "!/LICENSE-*"
  push:
    branches:
    - master
    paths:
    - '**'
    - '!/*.md'
    - '!/docs/**'
    - "!/LICENSE-*"
jobs:
  ci:
    name: CI
    needs: [smoke, test, msrv, docs, rustfmt, clippy]
    runs-on: ubuntu-latest
    steps:
      - name: Done
        run: exit 0
  smoke:
    name: Quick Check
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v2
    - name: Install Rust
      uses: actions-rs/toolchain@v1
      with:
        toolchain: stable
        profile: minimal
        override: true
    - uses: Swatinem/rust-cache@v1
    - name: Default features
      run: cargo check --workspace --all-targets
    - name: All features
      run: cargo check --workspace --all-targets --all-features
    - name: No-default features
      run: cargo check --workspace --all-targets --no-default-features
  test:
    name: Test
    needs: smoke
    strategy:
      fail-fast: false
      matrix:
        os: ["ubuntu-latest", "windows-latest", "macos-latest"]
        rust: ["stable"]
    continue-on-error: ${{ matrix.rust != 'stable' }}
    runs-on: ${{ matrix.os }}
    steps:
    - name: Checkout repository
      uses: actions/checkout@v2
    - name: Install Rust
      uses: actions-rs/toolchain@v1
      with:
        toolchain: ${{ matrix.rust }}
        profile: minimal
        override: true
    - uses: Swatinem/rust-cache@v1
    - name: Build
      run: cargo test --no-run --workspace --all-features
    - name: Default features
      run: cargo test --workspace
    - name: No-default features
      run: cargo test --workspace --no-default-features
  msrv:
    name: "Check MSRV: 1.59.0"
    needs: smoke
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v2
    - name: Install Rust
      uses: actions-rs/toolchain@v1
      with:
        toolchain: 1.59.0  # MSRV
        profile: minimal
        override: true
    - uses: Swatinem/rust-cache@v1
    - name: Default features
      run: cargo check --workspace --all-targets
    - name: All features
      run: cargo check --workspace --all-targets --all-features
    - name: No-default features
      run: cargo check --workspace --all-targets --no-default-features
  docs:
    name: Docs
    needs: smoke
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v2
    - name: Install Rust
      uses: actions-rs/toolchain@v1
      with:
        toolchain: stable
        profile: minimal
        override: true
    - uses: Swatinem/rust-cache@v1
    - name: Check documentation
      env:
        RUSTDOCFLAGS: -D warnings
      run: cargo doc --workspace --all-features --no-deps --document-private-items
  rustfmt:
    name: rustfmt
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v2
    - name: Install Rust
      uses: actions-rs/toolchain@v1
      with:
        # Not MSRV because its harder to jump between versions and people are
        # more likely to have stable
        toolchain: stable
        profile: minimal
        override: true
        components: rustfmt
    - uses: Swatinem/rust-cache@v1
    - name: Check formatting
      run: cargo fmt --all -- --check
  clippy:
    name: clippy
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v2
    - name: Install Rust
      uses: actions-rs/toolchain@v1
      with:
        toolchain: 1.59.0  # MSRV
        profile: minimal
        override: true
        components: clippy
    - uses: Swatinem/rust-cache@v1
    - uses: actions-rs/clippy-check@v1
      with:
        token: ${{ secrets.GITHUB_TOKEN }}
        args: --workspace --all-features --all-targets -- -D warnings --allow deprecated
