# This is the name of the workflow, visible on GitHub UI.
name: Compile All Inverters

# Here we tell GitHub when to run the workflow.
on: [push, pull_request]

# This is the list of jobs that will be run concurrently.
# Since we use a build matrix, the actual number of jobs
# started depends on how many configurations the matrix
# will produce.
jobs:
  # This is the name of the job.
  build-inverters:

    # Here we tell GitHub that the jobs must be determined
    # dynamically depending on a matrix configuration.
    strategy:
      # The matrix will produce one job for each combination of parameters.
      matrix:
        # This is the development board hardware for which the code will be compiled.
        # FBQN stands for "fully qualified board name", and is used by Arduino to define the hardware to compile for.
        fqbn:
          - esp32:esp32:esp32
          # further ESP32 chips
          #- esp32:esp32:esp32c3
          #- esp32:esp32:esp32c2
          #- esp32:esp32:esp32c6
          #- esp32:esp32:esp32h2
          #- esp32:esp32:esp32s3
        # These are the batteries for which the code will be compiled.
        battery:
#         - BMW_I3_BATTERY
#         - CHADEMO_BATTERY
#         - IMIEV_CZERO_ION_BATTERY
#         - KIA_HYUNDAI_64_BATTERY
          - NISSAN_LEAF_BATTERY
#         - RENAULT_ZOE_BATTERY
#         - TESLA_MODEL_3_BATTERY
        # These are the emulated inverter communication protocols for which the code will be compiled.
        inverter:
          - BYD_CAN
          - BYD_MODBUS
          - LUNA2000_MODBUS
          - PYLON_CAN
          - SMA_CAN
          - SOFAR_CAN
          - SOLAX_CAN

    # This is the platform GitHub will use to run our workflow.
    runs-on: ubuntu-latest

    # This is the list of steps this job will run.
    steps:
      # First we clone the repo using the `checkout` action.
      - name: Checkout
        uses: actions/checkout@v4

      # We use the `arduino/setup-arduino-cli` action to install and
      # configure the Arduino CLI on the system.
      - name: Setup Arduino CLI
        uses: arduino/setup-arduino-cli@v1

      # We then install the platform.
      - name: Install platform
        run: |
          arduino-cli core update-index
          arduino-cli core install esp32:esp32

      # Finally, we compile the sketch, using the FQBN that was set
      # in the build matrix, and using build flags to define the
      # battery and inverter set in the build matrix.
      - name: Compile Sketch
        run: arduino-cli compile --fqbn ${{ matrix.fqbn }} --build-property "build.extra_flags=-DESP32 -D${{ matrix.battery}} -D${{ matrix.inverter}}" ./Software
