name: CI

on:
  push:
    branches:
    - master
  pull_request:
    branches:
    - master

defaults:
  run:
    shell: bash

jobs:
  test:
    strategy:
      matrix:
        os:
        - ubuntu-latest
        - macos-latest
        - windows-latest

    runs-on: ${{matrix.os}}

    env:
      RUSTFLAGS: --deny warnings

    steps:
    - uses: actions/checkout@v2

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

    - uses: Swatinem/rust-cache@v1

    - run: |
        cargo test --all
        cargo test --all --features axum
        cargo test --all --features reload

    - run: |
        rustup target add thumbv6m-none-eabi
        cargo build --target thumbv6m-none-eabi --package boilerplate
        cargo build --target thumbv6m-none-eabi --package boilerplate-tests

  lint:
    runs-on: ubuntu-latest

    env:
      RUSTFLAGS: --deny warnings

    steps:
    - uses: actions/checkout@v2

    - uses: actions-rs/toolchain@v1
      with:
        components: clippy, rustfmt
        toolchain: stable

    - uses: Swatinem/rust-cache@v1

    - run: cargo update --locked --package boilerplate

    - run: cargo clippy --all

    - run: cargo fmt --all -- --check

    - run: |
        sudo apt-get update
        sudo apt-get install ripgrep
        ./bin/forbid
