name: esp32 port

on:
  push:
  pull_request:
    paths:
      - '.github/workflows/*.yml'
      - 'tools/**'
      - 'py/**'
      - 'extmod/**'
      - 'shared/**'
      - 'lib/**'
      - 'drivers/**'
      - 'ports/esp32/**'

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

env:
   # Oldest and newest supported ESP-IDF versions, should match ports/esp32/README.md
   IDF_OLDEST_VER: &oldest "v5.3"
   IDF_NEWEST_VER: &newest "v5.5.1"

jobs:
  build_idf:
    strategy:
      fail-fast: false
      matrix:
        idf_ver:
          - *oldest
          - *newest
        ci_func:  # names are functions in ci.sh
          - esp32_build_cmod_spiram_s2
          - esp32_build_s3_c3
          - esp32_build_c2_c5_c6
          - esp32_build_p4
        exclude:
          # Exclude some jobs on the oldest IDF version, to save resources
          - idf_ver: *oldest
            ci_func: esp32_build_c2_c5_c6
          - idf_ver: *oldest
            ci_func: esp32_build_p4
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v6

    # Only the newest IDF version will build the ESP-IDF lockfiles correctly,
    # so we need to disable MICROPY_MAINTAINER_BUILD on older versions.
    - name: Disable extra checks for older ESP-IDF
      id: check_newest_ver
      if: ${{ matrix.idf_ver != env.IDF_NEWEST_VER }}
      run: echo "MICROPY_MAINTAINER_BUILD=0" >> ${GITHUB_ENV}

    - name: Setup ESP-IDF
      uses: ./.github/actions/setup_esp32
      with:
        idf_ver: ${{ matrix.idf_ver }}
        ccache_key: ${{ matrix.ci_func }}


    - name: Build ci_${{matrix.ci_func }} on ESP-IDF ${{ matrix.idf_ver }}
      run: tools/ci.sh ${{ matrix.ci_func }}
