name: Rust

on:
  # Trigger the workflow on push or pull request,
  # but only for the master branch
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
  release:
    types:
      - created

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        version:
          - 1.46.0
          - stable
          - beta
          - nightly
    steps:
      - uses: actions/checkout@v1
      - name: Install toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ matrix.version }}
          default: true
          profile: minimal
      - name: Build
        run: cargo build --verbose
      - name: Run tests
        run: cargo test --verbose
      - name: Build --all-features
        run: cargo build --verbose --all-features
      - name: Run tests --all-features
        run: cargo test --verbose --all-features

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

  clippy:
    name: cargo clippy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          components: clippy
          toolchain: stable
          profile: minimal
          override: true
      - uses: actions-rs/cargo@v1
        with:
          command: clippy
          args: -- -D warnings

  readme:
    name: cargo readme
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          profile: minimal
          override: true
      - run: cargo install cargo-readme
      - run: cargo readme > README.md && git diff --exit-code