Subversion Repositories ESP8266_P1_Meter

Rev

Blame | Last modification | View Log | RSS feed

# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json

name: (ESP8266) Build with Arduino CLI

on:
  workflow_dispatch:
  push:
    branches:
      - dev
  pull_request:

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

jobs:
  arduino-esp8266:
    name: ESP8266 (arduino-cli) (shard=${{ matrix.shard }})
    if: github.event_name == 'workflow_dispatch' || vars.ENABLE_BUILDS == 'true'
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        shard: [1, 2, 3, 4]
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install arduino-cli
        run: curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/usr/local/bin sh

      - name: Cache Arduino CLI data
        uses: actions/cache@v4
        with:
          key: ${{ runner.os }}-arduino-esp8266-${{ hashFiles('.github/workflows/cli-build-esp8266.yml') }}-${{ github.run_id }}-${{ matrix.shard }}
          restore-keys: |
            ${{ runner.os }}-arduino-esp8266-${{ hashFiles('.github/workflows/cli-build-esp8266.yml') }}-
            ${{ runner.os }}-arduino-esp8266-
          path: |
            ~/.arduino15
            ~/Arduino
            ~/.cache/arduino-cli

      - name: Update core index
        run: arduino-cli core update-index --additional-urls https://arduino.esp8266.com/stable/package_esp8266com_index.json

      - name: Install core
        run: arduino-cli core install --additional-urls https://arduino.esp8266.com/stable/package_esp8266com_index.json esp8266:esp8266

      - name: Install ESPAsyncTCP (ESP8266)
        run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/ESP32Async/ESPAsyncTCP#v2.0.0

      - name: Install ESPAsyncWebServer
        run: ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://github.com/ESP32Async/ESPAsyncWebServer#v3.7.3

      - name: Install ArduinoJson
        run: arduino-cli lib install ArduinoJson

      - name: Build Examples
        run: |
          set -uo pipefail

          total_shards=4
          shard="${{ matrix.shard }}"

          # Examples not intended for ESP8266 / this job
          EXCLUDE_EXAMPLES=(
            esp32-cam
            binaryWebSocket
            csvLoggerSD
            localRFID
            mysqlRFID
            mqtt_webserver
          )

          report_file="build-report-esp8266-arduino-cli-shard${{ matrix.shard }}.txt"
          : > "$report_file"

          failures=0
          total=0
          index=0

          for dir in examples/*; do
            if [[ ! -d "$dir" ]]; then
              continue
            fi

            example="$(basename "$dir")"

            if [[ " ${EXCLUDE_EXAMPLES[*]} " == *" ${example} "* ]]; then
              echo "Skipping: ${example}"
              printf '%-25s : SKIP\n' "${example}" >> "$report_file"
              continue
            fi

            # Split examples across shards for faster CI.
            index=$((index + 1))
            example_shard=$(( (index - 1) % total_shards + 1 ))
            if [[ "$example_shard" != "$shard" ]]; then
              continue
            fi

            sketch="examples/${example}/${example}.ino"
            total=$((total + 1))

            echo "============================================================="
            echo "Building ${sketch}..."
            echo "============================================================="

            if [[ ! -f "$sketch" ]]; then
              failures=$((failures + 1))
              printf '%-25s : FAIL (missing %s)\n' "${example}" "${sketch}" >> "$report_file"
              continue
            fi

            echo "::group::arduino-cli compile - ${example}"
            set +e
            arduino-cli compile \
              --library . \
              --warnings none \
              --build-cache-path "$HOME/.cache/arduino-cli" \
              -b esp8266:esp8266:huzzah \
              "$sketch"
            rc=$?
            set -e
            echo "::endgroup::"

            if [[ $rc -eq 0 ]]; then
              printf '%-25s : OK\n' "${example}" >> "$report_file"
            else
              failures=$((failures + 1))
              printf '%-25s : FAIL (exit=%s)\n' "${example}" "$rc" >> "$report_file"
            fi
          done

          echo ""
          echo "==================== Build report (esp8266/arduino-cli) ===================="
          cat "$report_file"
          echo "============================================================================="
          echo "Total attempted: ${total} | Failures: ${failures}"

          # Do not fail the job here: the final report job will decide.

      - name: Upload build report
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: arduino-cli-esp8266-report-shard${{ matrix.shard }}
          path: build-report-esp8266-arduino-cli-shard${{ matrix.shard }}.txt

  report:
    name: ESP8266 (arduino-cli) - Final report
    runs-on: ubuntu-latest
    needs: arduino-esp8266
    if: always() && needs.arduino-esp8266.result != 'skipped'
    steps:
      - name: Download all reports
        uses: actions/download-artifact@v4
        with:
          pattern: arduino-cli-esp8266-report-*
          merge-multiple: true
          path: reports

      - name: Print final report and set status
        run: |
          set -uo pipefail
          echo "==================== Final build report (ESP8266/arduino-cli) ===================="
          failures=0
          files=0
          shopt -s nullglob
          for f in reports/*.txt; do
            files=$((files + 1))
            echo "--- ${f} ---"
            cat "$f"
            if grep -q " : FAIL" "$f"; then
              failures=$((failures + 1))
            fi
          done
          if [[ $files -eq 0 ]]; then
            echo "No report files found (artifact download failed?)"
            exit 1
          fi
          echo "==========================================================================="
          if [[ $failures -gt 0 ]]; then
            echo "One or more shards reported FAIL."
            exit 1
          fi