# This is the name of the workflow, visible on GitHub UI.
name: Test Compile ESP Code
on:
  push: # see: https://help.github.com/en/actions/reference/events-that-trigger-workflows#pull-request-event-pull_request
    paths:
      - '**.ino'
      - '**.cpp'
      - '**.h'
      - '**test-compile.yml'
  pull_request:
   branches:
      - main

jobs:
  build:
    name: ${{ matrix.arduino-boards-fqbn }}

    runs-on: ubuntu-latest

    env:
      # Comma separated list without double quotes around the list.
      REQUIRED_LIBRARIES: WiFi@1.2.7,WebServer@3.2.1,ESP2SOTA@1.0.2
      ENV_CLI_VERSION: latest

    strategy:
      matrix:
        # The matrix will produce one job for each configuration parameter of type `arduino-boards-fqbn`
        # In the Arduino IDE, the fqbn is printed in the first line of the verbose output for compilation as parameter -fqbn=... for the "arduino-builder -dump-prefs" command
        #
        # Examples: arduino:avr:uno, arduino:avr:leonardo, arduino:avr:nano, arduino:avr:mega
        # arduino:sam:arduino_due_x, arduino:samd:arduino_zero_native"
        # ATTinyCore:avr:attinyx5:chip=85,clock=1internal, digistump:avr:digispark-tiny, digistump:avr:digispark-pro
        # STMicroelectronics:stm32:GenF1:pnum=BLUEPILL_F103C8
        # esp8266:esp8266:huzzah:eesz=4M3M,xtal=80, esp32:esp32:featheresp32:FlashFreq=80
        # You may add a suffix behind the fqbn with "|" to specify one board for e.g. different compile options like arduino:avr:uno|trace
        #############################################################################################################
        arduino-boards-fqbn:
          - esp32:esp32:ESP32_DEV

        # Specify parameters for each board.
        #############################################################################################################
        include:
          - arduino-boards-fqbn: esp32:esp32:doitESP32devkitV1
            platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

      # Do not cancel all jobs / architectures if one job fails
      fail-fast: false

    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Install dependencies
        run: |
          apt update -y && apt install python3-pip -y
          /usr/bin/python3 -m pip install --upgrade pip
          /usr/bin/python3 -m pip install pyserial
          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
      - name: Compile all examples using the arduino-test-compile action
        uses: https://github.com/ArminJo/arduino-test-compile@master
        with:
          arduino-board-fqbn: ${{ matrix.arduino-boards-fqbn }}
          arduino-platform: ${{ matrix.arduino-platform }}
          platform-url: ${{ matrix.platform-url }}
          required-libraries: ${{ env.REQUIRED_LIBRARIES }}
          sketches-exclude: ${{ matrix.sketches-exclude }}
          build-properties: ${{ toJson(matrix.build-properties) }}
          sketch-names:
            "FM-Transmitter.ino"
          sketch-names-find-start: FM-Transmitter
          debug-compile: false
          debug-install: false