name: Integreation Tests

on: [push, pull_request]

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/lora_board/firmware.bin

  formatting-check:
    name: Formatting Check
    runs-on: ubuntu-latest
    strategy:
      matrix:
        path:
          - 'src'
          - 'lib/BoardFinder'
          - 'lib/ConfigurationManagement'
          #- 'lib/Display'
          #- 'lib/LoRa'
          - 'lib/LoRa_APRS'
          #- 'lib/NTPClient'
          - 'lib/PowerManagement'
          - 'lib/System'
          #- 'lib/TimeLib'
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Run clang-format style check for C/C++ programs.
        uses: jidicula/clang-format-action@v3.2.0
        with:
          clang-format-version: '11'
          check-path: ${{ matrix.path }}

  cppcheck:
    name: Run cppcheck
    runs-on: ubuntu-latest
    env:
      CPPCHECK_ARGS: --enable=all --std=c++14 --inline-suppr -I lib/BoardFinder -I lib/ConfigurationManagement -I lib/Display -I lib/LoRa -I lib/LoRa_APRS -I lib/NTPClient -I lib/PowerManagement -I lib/System -I lib/TimeLib -i lib/Display -i lib/LoRa -i lib/NTPClient -i lib/TimeLib src lib
    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
