name: Rust

on: [push, pull_request]

jobs:
  check:
    name: Check
    runs-on: ubuntu-latest
    strategy:
      matrix:
        mcu: [
          # atsam4e
          atsam4e8c, atsam4e8e, atsam4e16c, atsam4e16e,
          # atsam4n
          atsam4n8a, atsam4n8b, atsam4n8c,
          atsam4n16b, atsam4n16c,
          # atsam4s
          atsam4s2a, atsam4s2b, atsam4s2c,
          atsam4s4a, atsam4s4b, atsam4s4c,
          atsam4s8b, atsam4s8c,
          atsam4sa16b, atsam4sa16c,
          atsam4sd16b, atsam4sd16c,
          atsam4sd32b, atsam4sd32c,
        ]

    steps:
      - uses: actions/checkout@v1
        # atsam4e toolchain
      - uses: actions-rs/toolchain@v1
        if: ${{ contains(matrix.mcu, 'atsam4e') }}
        with:
          target: thumbv7em-none-eabihf
          toolchain: stable
          override: true
      - uses: actions-rs/toolchain@v1
        if: ${{ contains(matrix.mcu, 'atsam4s') || contains(matrix.mcu, 'atsam4n') }}
        with:
          target: thumbv7em-none-eabi
          toolchain: stable
          override: true
      - uses: actions-rs/cargo@v1
        if: ${{ contains(matrix.mcu, 'atsam4e') }}
        with:
          command: check
          args: --target thumbv7em-none-eabihf --no-default-features --features ${{ matrix.mcu }}
      - uses: actions-rs/cargo@v1
        if: ${{ contains(matrix.mcu, 'atsam4s') }}
        with:
          command: check
          args: --target thumbv7em-none-eabi --no-default-features --features ${{ matrix.mcu }}

  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
      - uses: actions-rs/cargo@v1
        with:
          command: build
          args: --target x86_64-unknown-linux-gnu

  fmt:
    name: Rustfmt
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
      - run: rustup component add rustfmt
      - uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: -- --check

  clippy:
    name: Clippy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
      - run: rustup component add clippy
      - uses: actions-rs/cargo@v1
        with:
          command: clippy
          args: --target x86_64-unknown-linux-gnu -- -D warnings

  doc:
    name: Doc Check
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
      - uses: actions-rs/cargo@v1
        with:
          command: doc
          args: --target x86_64-unknown-linux-gnu
