name: ESP-IDF Build

on:
  push:
    paths:
      - "firmware/**"
      - ".github/workflows/esp32_build.yml"
  pull_request:
  merge_group:
  workflow_dispatch:
  schedule:
    - cron: "0 5 * * 3"

permissions:
  contents: read
  pull-requests: write

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build:
    strategy:
      matrix:
        idf_ver: [release-v5.4, release-v5.5, latest]
        idf_target: [esp32c6, esp32s3]

    runs-on: ubuntu-latest
    timeout-minutes: 30

    steps:
      - name: Checkout repo
        uses: actions/checkout@v4
        with:
          submodules: "recursive"

      - name: Delete CMakeLists.txt in components (only used for simulator build)
        run: rm firmware/components/CMakeLists.txt

      - name: ESP-IDF build
        uses: espressif/esp-idf-ci-action@v1
        with:
          esp_idf_version: ${{ matrix.idf_ver }}
          target: ${{ matrix.idf_target }}
          path: firmware
          command: idf.py -DSDKCONFIG_DEFAULTS="sdkconfig.defaults;sdkconfig.release" build
