name: Firmware build check

# Fires on every push touching firmware source, unlike
# firmware-release-build.yml (which only builds+publishes when
# firmware/version.txt itself is bumped -- the "cut a release" signal).
# This just verifies both board variants still compile; nothing else in
# CI catches a firmware/** push that breaks the build until someone
# happens to bump the version next.
on:
  push:
    branches: [main]
    paths:
      - "firmware/**"
      - ".gitea/workflows/firmware-build-check.yml"

jobs:
  build-check:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      # Same docker create/cp/start pattern as firmware-release-build.yml
      # (see that file's own comment for why -- the runner's job
      # workspace lives in a named Docker volume, not a real host path,
      # so a nested `docker run -v "$PWD:..."` bind-mounts nothing
      # useful). No release/artifact step here -- this only needs to
      # prove `idf.py build` still succeeds for each board.
      - name: Build (devkit -- ESP32-C6-DevKitC-1)
        run: |
          cid=$(docker create -w /workspace/firmware espressif/idf:release-v6.0 bash -c '
            git config --global --add safe.directory /workspace &&
            . "$IDF_PATH/export.sh" &&
            ./build_for_board.sh devkit set-target esp32c6 &&
            ./build_for_board.sh devkit build
          ')
          docker cp "$PWD/." "$cid:/workspace"
          docker start -a "$cid"
          docker rm "$cid"

      - name: Build (xiao -- Seeed XIAO ESP32-C6)
        run: |
          cid=$(docker create -w /workspace/firmware espressif/idf:release-v6.0 bash -c '
            git config --global --add safe.directory /workspace &&
            . "$IDF_PATH/export.sh" &&
            ./build_for_board.sh xiao set-target esp32c6 &&
            ./build_for_board.sh xiao build
          ')
          docker cp "$PWD/." "$cid:/workspace"
          docker start -a "$cid"
          docker rm "$cid"
