name: ci

on:
  push:
    branches:
    - master
    - release/*
  pull_request:
    branches:
    - master
    - release/*

jobs:
  cargo-test:
    name: cargo test (${{ matrix.os }} / ${{ matrix.rust-version }} / ${{ matrix.runtime }})
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macOS-latest]
        rust-version: [1.52.0, beta, nightly]
        runtime: [runtime-tokio, runtime-agnostic]
        include:
        - rust-version: nightly
          continue-on-error: true
    steps:
    - uses: actions/checkout@v2
    - name: Install Rust toolchain
      uses: actions-rs/toolchain@v1
      with:
        profile: minimal
        toolchain: ${{ matrix.rust-version }}
    - name: Run cargo test
      continue-on-error: ${{ matrix.continue-on-error || false }}
      uses: actions-rs/cargo@v1
      with:
        command: test
        args: --workspace --no-default-features --features ${{ matrix.runtime }}

  cargo-audit:
    name: cargo audit
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - uses: actions-rs/audit-check@v1
      with:
        token: ${{ secrets.GITHUB_TOKEN }}

  cargo-clippy:
    name: cargo clippy
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Install Rust toolchain
      uses: actions-rs/toolchain@v1
      with:
        profile: minimal
        toolchain: stable
        components: clippy
    - name: Run cargo clippy
      uses: actions-rs/clippy-check@v1
      with:
        token: ${{ secrets.GITHUB_TOKEN }}
        args: --all-targets -- -D warnings

  cargo-fmt:
    name: cargo fmt
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Install Rust toolchain
      uses: actions-rs/toolchain@v1
      with:
        profile: minimal
        toolchain: stable
        components: rustfmt
    - name: Run cargo fmt
      uses: actions-rs/cargo@v1
      with:
        command: fmt
        args: --all -- --check
