name: Integreation Tests

on:
  push:
    branches:
      - '*'
      - '!master'
  pull_request:
    branches:
      - master

jobs:
  build:
    name: Compile Firmware
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Set up Python
        uses: actions/setup-python@v2
      - name: Install PlatformIO
        run: python -m pip install --upgrade pip platformio
      - name: Run PlatformIO CI
        run: platformio run
      - name: Upload artifacts
        uses: actions/upload-artifact@v2
        with:
          name: firmware
          path: .pio/build/*/firmware.bin

  formatting-check:
    name: Formatting Check
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Run clang-format style check for C/C++ programs.
        uses: jidicula/clang-format-action@v4.6.2
        with:
          clang-format-version: '11'
          check-path: src

  cppcheck:
    name: Run cppcheck
    runs-on: ubuntu-latest
    env:
      CPPCHECK_ARGS: --enable=all --std=c++14 --inline-suppr src
    steps:
      - name: checkout code
        uses: actions/checkout@v2
      - run: docker pull facthunder/cppcheck:latest
      - name: Run cppcheck and print result
        run: docker run --rm -v ${PWD}:/src facthunder/cppcheck:latest /bin/bash -c "cppcheck $CPPCHECK_ARGS"
      - name: Run cppcheck and create html
        run: docker run --rm -v ${PWD}:/src facthunder/cppcheck:latest /bin/bash -c "cppcheck --xml $CPPCHECK_ARGS 2> report.xml && cppcheck-htmlreport --file=report.xml --report-dir=output"
      - name: Upload report
        uses: actions/upload-artifact@v1
        with:
          name: Cppcheck Report
          path: output
