---
name: CI Build

on:
  push:
    branches:
      - '**'
    paths-ignore:
      - '**/*.md'
      - 'LICENSE'
  pull_request:
    branches:
      - '**'
    paths-ignore:
      - '**/*.md'
      - 'LICENSE'
  workflow_dispatch:
  schedule:
    - cron: '0 0 * * 1'

env:
  RUSTFLAGS: '--deny warnings'

jobs:
  format:
    name: "Rust Format Check"
    runs-on: ubuntu-latest
    steps:
      - name: "Checkout"
        uses: actions/checkout@v2

      - name: "Rust Toolchain setup"
        uses: actions-rs/toolchain@v1
        with:
            toolchain: stable
            components: rustfmt
            override: true

      - name: "Format Check"
        uses: mbrobbel/rustfmt-check@master
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

  build-linux:
    name: "CI Build - Linux"
    runs-on: ubuntu-latest
    needs: format
    strategy:
      matrix:
        RUST: [stable]
        TARGET:
          - x86_64-unknown-linux-gnu
          - armv7-unknown-linux-gnueabihf
          - aarch64-unknown-linux-gnu

    steps:
      - name: "Checkout"
        uses: actions/checkout@v2
      
      - name: "Rust Toolchain setup"
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: ${{ matrix.RUST }}
          target: ${{ matrix.TARGET }}
          override: true

      - name: "Build"
        uses: actions-rs/cargo@v1
        with:
          use-cross: true
          command: build
          args: --target=${{ matrix.TARGET }}

      - name: "Test"
        uses: actions-rs/cargo@v1
        with:
          use-cross: true
          command: test
          args: --target=${{ matrix.TARGET }}

  build-macos:
    name: "CI Build - Macos"
    runs-on: macos-latest
    needs: format
    strategy:
      matrix:
        RUST: [stable]
        TARGET:
          - x86_64-apple-darwin
          - aarch64-apple-darwin
    steps:
      - name: "Checkout"
        uses: actions/checkout@v2
      
      - name: "Rust Toolchain setup"
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: ${{ matrix.RUST }}
          target: ${{ matrix.TARGET }}
          override: true

      - name: "Build"
        uses: actions-rs/cargo@v1
        with:
          use-cross: true
          command: build
          args: --target=${{ matrix.TARGET }}

      - name: "Test"
        uses: actions-rs/cargo@v1
        with:
          command: test
