name: Build

inputs:
  board_id:
    description: The sdkconfig file to build
    required: true
  arch:
    description: The ESP32 SOC variant
    required: true

runs:
  using: "composite"
  steps:
    - uses: actions/checkout@v6
      with:
        submodules: recursive
    - name: 'Board select'
      shell: bash
      run: python device.py ${{ inputs.board_id }}
    - name: 'Build'
      uses: espressif/esp-idf-ci-action@v1
      with:
        # NOTE: Update with ESP-IDF!
        esp_idf_version: v5.5.2
        target: ${{ inputs.arch }}
        path: './'
    - name: 'Release'
      shell: bash
      env:
        # NOTE: Update with ESP-IDF!
        ESP_IDF_VERSION: '5.5.2'
      run: python Buildscripts/release-sdk.py release/TactilitySDK
    - name: 'Test Integration Prep'
      shell: bash
      # The manifest.properties of our integration test uses version 0.0.0 to indicate that it is not using a normal SDK
      # This way, it only works with our custom build. That means we have to create a copy of the SDK with the correct folder structure:
      run: |
        TACTILITY_SDK_NAME="0.0.0-${{ inputs.arch }}"
        mkdir -p test_sdk/$TACTILITY_SDK_NAME
        cp -r release/TactilitySDK test_sdk/$TACTILITY_SDK_NAME
    - name: 'Test Integration'
      uses: espressif/esp-idf-ci-action@v1
      with:
        esp_idf_version: v5.5.2
        target: ${{ inputs.arch }}
        command: export TACTILITY_SDK_PATH=../../test_sdk && cd Tests/SdkIntegration && python tactility.py build ${{ inputs.arch }} --local-sdk
    - name: 'Upload Artifact'
      uses: actions/upload-artifact@v4
      with:
        name: TactilitySDK-${{ inputs.arch }}
        path: release/TactilitySDK
        retention-days: 30
