name: ESP32 Build & Release on: push: branches: - main jobs: build: runs-on: ubuntu-latest steps: # ------------------------------------------------------------ # Checkout # ------------------------------------------------------------ - name: Checkout uses: actions/checkout@v4 # ------------------------------------------------------------ # System dependencies # ------------------------------------------------------------ - name: Install system dependencies shell: bash run: | sudo apt-get update sudo apt-get install -y \ git \ wget \ flex \ bison \ gperf \ python3 \ python3-pip \ python3-venv \ cmake \ ninja-build \ ccache \ libffi-dev \ libssl-dev \ dfu-util # ------------------------------------------------------------ # Cache ESP-IDF and Espressif tools # ------------------------------------------------------------ - name: Cache ESP-IDF uses: actions/cache@v4 with: path: | ~/esp/esp-idf ~/.espressif key: esp-idf-5.5-esp32-${{ runner.os }} restore-keys: | esp-idf-5.5-esp32- # ------------------------------------------------------------ # Install ESP-IDF 5.5 # ------------------------------------------------------------ - name: Install ESP-IDF 5.5 shell: bash run: | mkdir -p "$HOME/esp" if [ ! -f "$HOME/esp/esp-idf/export.sh" ]; then echo "ESP-IDF not found in cache." echo "Cloning ESP-IDF 5.5..." git clone --recursive \ --branch v5.5 \ https://github.com/espressif/esp-idf.git \ "$HOME/esp/esp-idf" cd "$HOME/esp/esp-idf" ./install.sh esp32 else echo "Using cached ESP-IDF." fi # ------------------------------------------------------------ # Verify ESP-IDF # ------------------------------------------------------------ - name: Verify ESP-IDF shell: bash run: | source "$HOME/esp/esp-idf/export.sh" echo "ESP-IDF:" idf.py --version # ------------------------------------------------------------ # Build firmware # ------------------------------------------------------------ - name: Build firmware shell: bash run: | source "$HOME/esp/esp-idf/export.sh" idf.py set-target esp32 idf.py build # ------------------------------------------------------------ # Create merged firmware image # ------------------------------------------------------------ - name: Create merged firmware shell: bash run: | source "$HOME/esp/esp-idf/export.sh" idf.py merge-bin # ------------------------------------------------------------ # Prepare release artifacts # ------------------------------------------------------------ - name: Prepare release shell: bash run: | mkdir -p release echo "Build artifacts:" find build -maxdepth 2 -type f \ \( -name "*.bin" -o -name "*.elf" -o -name "flasher_args.json" \) \ -print # Find merged binary MERGED_BIN=$(find build -maxdepth 1 -type f -name "*.bin" | head -n 1) if [ -z "$MERGED_BIN" ]; then echo "ERROR: No merged .bin found" exit 1 fi echo "Using merged binary: $MERGED_BIN" cp "$MERGED_BIN" release/firmware.bin # ELF for debugging find build -maxdepth 1 -type f -name "*.elf" \ -exec cp {} release/ \; # Flash configuration if [ -f build/flasher_args.json ]; then cp build/flasher_args.json release/ fi echo "" echo "Release contents:" ls -lh release/ # ------------------------------------------------------------ # Delete existing "latest" release # ------------------------------------------------------------ - name: Delete existing latest release shell: bash env: GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | API="${{ github.server_url }}/api/v1" echo "Removing existing latest release..." curl -fsSL \ -X DELETE \ -H "Authorization: token ${GITEA_TOKEN}" \ "${API}/repos/${{ github.repository }}/releases/tags/latest" \ || true # Delete the tag as well curl -fsSL \ -X DELETE \ -H "Authorization: token ${GITEA_TOKEN}" \ "${API}/repos/${{ github.repository }}/tags/latest" \ || true # ------------------------------------------------------------ # Create latest release # ------------------------------------------------------------ - name: Create latest release uses: akkuman/gitea-release-action@v1 with: server_url: ${{ github.server_url }} repository: ${{ github.repository }} token: ${{ secrets.GITHUB_TOKEN }} tag_name: latest name: "Latest ESP32 Firmware" body: | Automatically built from the `main` branch. Commit: ${{ github.sha }} ESP-IDF: 5.5 Target: ESP32 This release is automatically replaced on every push to `main`. files: | release/*