language: c
addons:
  apt:
    packages:
    - jq
    - doxygen
    - graphviz
    - python3
    - python3-pip
    - pylint3
    - python3-setuptools
env:
  - PLATFORMIO_BUILD_CACHE_DIR="../../.pio/buildcache"
    IRRECVDUMP_RE=".*IRrecvDumpV.*"
    IRMQTTSERVER_RE=".*IRMQTTServer.*"
    MAKEFLAGS="-j 2"
cache:
  directories:
    - "~/.platformio"
before_install:
  - wget https://raw.githubusercontent.com/google/styleguide/gh-pages/cpplint/cpplint.py
  - python --version && pip --version
  - python3 --version && pip3 --version
  - sudo pip3 install -U platformio
  - pio update
script: echo Running checks
notifications:
  email:
    on_success: change
    on_failure: change
jobs:
  include:
    - name: "Compile the trivial examples"
      script:
      # Check that everything compiles but some heavy tasks e.g. IRMQTTServer & IRrecvDumpV2+
      # i.e. We are splitting the work load in to parallel tasks.
      - find . -regextype egrep -name platformio.ini -type f \! -regex "${IRRECVDUMP_RE}|${IRMQTTSERVER_RE}" | sed 's,/platformio.ini$,,' | xargs --verbose -n 1 pio run --jobs 2 --project-dir
    - name: "Compile the IRrecvDumpV2+ examples"
      script:
      # Check that IRrecvDumpV2+ compiles.
      # i.e. We are splitting the work load in to parallel tasks.
      - find . -regextype egrep -name platformio.ini -type f -regex "${IRRECVDUMP_RE}" | sed 's,/platformio.ini$,,' | xargs --verbose -n 1 pio run  --jobs 2 --project-dir
    - name: "Unit tests, Linter, Doc checks, & Compile IRMQTTServer"
      script:
      # Run all the Tests & check the code linters have no issues, and that
      # IRMQTTServer compiles.
      # i.e. We are splitting the work load in to parallel tasks.
      # Check the version numbers match.
      - LIB_VERSION=$(egrep "^#define\s+_IRREMOTEESP8266_VERSION_\s+" src/IRremoteESP8266.h  | cut -d\" -f2)
      - test ${LIB_VERSION} == "$(jq -r .version library.json)"
      - grep -q "^version=${LIB_VERSION}$" library.properties
      # Check the tools programs compile.
      - (cd tools; make all)
      # Check for lint issues.
      - shopt -s nullglob
      - python cpplint.py --extensions=c,cc,cpp,ino --headers=h,hpp {src,src/locale,test,tools}/*.{h,c,cc,cpp,hpp,ino} examples/*/*.{h,c,cc,cpp,hpp,ino}
      - pylint3 -d F0001 {src,test,tools}/*.py
      - shopt -u nullglob
      # Build and run the unit tests.
      - (cd test; make run)
      - (cd tools; make run_tests)
      # Check that every example directory has a platformio.ini file.
      - (status=0; for dir in examples/*; do if [[ ! -f "${dir}/platformio.ini" ]]; then echo "${dir} has no 'platform.ini' file!"; status=1; fi; done; exit ${status})
      # Check that doxygen completes without errors or warnings.
      - (DOXYGEN_OUTPUT=$(doxygen 2>&1); if [[ $? -ne 0 || -n "${DOXYGEN_OUTPUT}" ]]; then echo "${DOXYGEN_OUTPUT}"; exit 1; fi)
      # Check that all files has supported sections.
      - (SUPPORTED_OUTPUT=$(python3 tools/scrape_supported_devices.py --noout --alert 2>&1); if [[ $? -ne 0 || -n "${SUPPORTED_OUTPUT}" ]]; then echo "${SUPPORTED_OUTPUT}"; exit 1; fi)
      # Check that IRMQTTServer compiles.
      - find . -regextype egrep -name platformio.ini -type f -regex "${IRMQTTSERVER_RE}" | sed 's,/platformio.ini$,,' | xargs --verbose -n 1 pio run  --jobs 2 --project-dir
