name: CI

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  rust:
    name: Lint and Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          components: clippy

      - uses: Swatinem/rust-cache@v1

      - run: cargo build --all-features

      - run: cargo test

      - run: cargo clippy -- -D warnings

  rustfmt:
    name: Rustfmt
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: nightly
          components: rustfmt

      - run: cargo +nightly fmt -- --check
