name: Repo PlatformIO Build on: workflow_dispatch: inputs: owner: required: true type: string repo: required: true type: string ref: required: true type: string target_env: required: true type: string repo_build_id: required: true type: string build_key: required: true type: string resolved_source_sha: required: true type: string convex_url: required: true type: string platform_root: description: Monorepo subdirectory (git submodule path) containing the PlatformIO project; empty = zip at repo root required: false type: string default: "" jobs: build: runs-on: ubuntu-latest env: CONVEX_URL: ${{ inputs.convex_url }} REPO_BUILD_ID: ${{ inputs.repo_build_id }} CONVEX_BUILD_TOKEN: ${{ secrets.CONVEX_BUILD_TOKEN }} CI_PROGRESS_TOTAL: "10" PLATFORMIO_LIBDEPS_DIR: ${{ github.workspace }}/.pio-libdeps/${{ inputs.owner }}/${{ inputs.repo }}/${{ inputs.platform_root == '' && '__root__' || inputs.platform_root }}/${{ inputs.target_env }} steps: - uses: actions/checkout@v4 - name: Notify Convex — running shell: bash run: | curl -sSf -X POST "$CONVEX_URL/ingest-repo-build" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $CONVEX_BUILD_TOKEN" \ -d "{\"repo_build_id\":\"$REPO_BUILD_ID\",\"state\":\"running\",\"github_run_id\":${{ github.run_id }}}" - name: CI progress — build started shell: bash env: STEP_INDEX: 1 LABEL: Build started on Actions run: python3 "${{ github.workspace }}/scripts/ci/report-convex-ci-progress.py" - name: Set up Python uses: actions/setup-python@v5 with: python-version: "3.x" - name: Setup Bun uses: oven-sh/setup-bun@v1 with: bun-version: latest - name: CI progress — tooling ready shell: bash env: STEP_INDEX: 2 LABEL: Runner tooling ready run: python3 "${{ github.workspace }}/scripts/ci/report-convex-ci-progress.py" - name: Download source archive if: ${{ inputs.platform_root == '' }} shell: bash env: OWNER: ${{ inputs.owner }} REPO: ${{ inputs.repo }} REF: ${{ inputs.ref }} run: | STEP_INDEX=3 LABEL="Downloading source archive" python3 "${{ github.workspace }}/scripts/ci/report-convex-ci-progress.py" ENC_REF=$(python3 -c "import urllib.parse,os; print(urllib.parse.quote(os.environ['REF'], safe=''))") curl -fsSL -o /tmp/src.zip "https://codeload.github.com/${OWNER}/${REPO}/zip/${ENC_REF}" - name: Clone monorepo with submodules if: ${{ inputs.platform_root != '' }} shell: bash env: OWNER: ${{ inputs.owner }} REPO: ${{ inputs.repo }} REF: ${{ inputs.ref }} PLATFORM_ROOT: ${{ inputs.platform_root }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | STEP_INDEX=3 LABEL="Cloning monorepo with submodules" python3 "${{ github.workspace }}/scripts/ci/report-convex-ci-progress.py" set -e sudo apt-get update -qq && sudo apt-get install -y -qq git rm -rf /tmp/fw-checkout git clone "https://x-access-token:${GITHUB_TOKEN}@github.com/${OWNER}/${REPO}.git" /tmp/fw-checkout cd /tmp/fw-checkout git checkout "${REF}" git submodule update --init --recursive SUB="$(pwd)/${PLATFORM_ROOT}" if [ ! -d "$SUB" ]; then echo "platform_root directory missing: ${PLATFORM_ROOT}" exit 1 fi printf '%s\n' "$SUB" > /tmp/fw-src-root.txt mkdir -p "$PLATFORMIO_LIBDEPS_DIR" - name: CI progress — restoring PlatformIO global cache shell: bash env: STEP_INDEX: 4 LABEL: Restoring PlatformIO global cache (toolchains) run: python3 "${{ github.workspace }}/scripts/ci/report-convex-ci-progress.py" - name: Cache PlatformIO global store uses: actions/cache@v4 with: path: | ~/.platformio/.cache ~/.platformio/packages key: platformio-${{ runner.os }}-v1-${{ hashFiles('.github/workflows/custom_build.yml') }} restore-keys: | platformio-${{ runner.os }}-v1- - name: CI progress — restoring PlatformIO libdeps cache shell: bash env: STEP_INDEX: 5 LABEL: Restoring PlatformIO libdeps cache run: python3 "${{ github.workspace }}/scripts/ci/report-convex-ci-progress.py" # Key is owner/repo/env only (not source SHA); bump …-v2 if lib_deps get out of sync. - name: Cache PlatformIO libdeps (per repo + target) uses: actions/cache@v4 with: path: ${{ github.workspace }}/.pio-libdeps/${{ inputs.owner }}/${{ inputs.repo }}/${{ inputs.platform_root == '' && '__root__' || inputs.platform_root }}/${{ inputs.target_env }} key: pio-libdeps-${{ inputs.owner }}-${{ inputs.repo }}-${{ inputs.platform_root == '' && 'root' || inputs.platform_root }}-${{ inputs.target_env }}-v1 - name: Extract firmware source if: ${{ inputs.platform_root == '' }} shell: bash run: | STEP_INDEX=6 LABEL="Extracting firmware source" python3 "${{ github.workspace }}/scripts/ci/report-convex-ci-progress.py" set -e sudo apt-get update -qq && sudo apt-get install -y -qq unzip rm -rf /tmp/src mkdir -p /tmp/src unzip -q /tmp/src.zip -d /tmp/src ROOT=$(find /tmp/src -mindepth 1 -maxdepth 1 -type d | head -1) printf '%s\n' "$ROOT" > /tmp/fw-src-root.txt mkdir -p "$PLATFORMIO_LIBDEPS_DIR" - name: Install PlatformIO shell: bash run: | STEP_INDEX=7 LABEL="Installing PlatformIO" python3 "${{ github.workspace }}/scripts/ci/report-convex-ci-progress.py" set -e ROOT=$(cat /tmp/fw-src-root.txt) cd "$ROOT" python -m pip install -q --upgrade pip pip install -q platformio adafruit-nrfutil - name: Install PlatformIO dependencies shell: bash run: | STEP_INDEX=8 LABEL="Installing firmware dependencies (PlatformIO)" python3 "${{ github.workspace }}/scripts/ci/report-convex-ci-progress.py" set -e ROOT=$(cat /tmp/fw-src-root.txt) cd "$ROOT" pio pkg install -e "${{ inputs.target_env }}" - name: Compile firmware (PlatformIO) shell: bash run: | STEP_INDEX=9 LABEL="Compiling firmware (PlatformIO)" python3 "${{ github.workspace }}/scripts/ci/report-convex-ci-progress.py" set -e ROOT=$(cat /tmp/fw-src-root.txt) cd "$ROOT" MKLITTLEFS_BIN=$(find "$HOME/.platformio/packages" -type f -name mklittlefs 2>/dev/null | head -1) if [ -n "$MKLITTLEFS_BIN" ]; then export PATH="$(dirname "$MKLITTLEFS_BIN"):$PATH" fi command -v mklittlefs >/dev/null 2>&1 || echo "WARNING: mklittlefs not on PATH; LittleFS build may fail" pio run -e "${{ inputs.target_env }}" 2>&1 | tee /tmp/pio.log BUILD_DIR=".pio/build/${{ inputs.target_env }}" if [ ! -d "$BUILD_DIR" ]; then echo "Build output directory missing" exit 1 fi - name: Package and upload firmware bundle id: pio env: CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} R2_BUCKET_NAME: ${{ secrets.R2_BUCKET_NAME }} shell: bash run: | STEP_INDEX=10 LABEL="Packaging and uploading firmware bundle" python3 "${{ github.workspace }}/scripts/ci/report-convex-ci-progress.py" set -e ROOT=$(cat /tmp/fw-src-root.txt) BUILD_DIR_ABS="$ROOT/.pio/build/${{ inputs.target_env }}" ARTIFACT_NAME="firmware-${{ inputs.build_key }}-${{ github.run_id }}.tar.gz" MESHTASTIC_OTA=1 bash "${{ github.workspace }}/scripts/ci/common/fw-bundle-pipeline.sh" "$ROOT" "$BUILD_DIR_ABS" "/tmp/$ARTIFACT_NAME" OBJECT_PATH="${R2_BUCKET_NAME}/${ARTIFACT_NAME}" bunx wrangler r2 object put "$OBJECT_PATH" --file "/tmp/$ARTIFACT_NAME" --remote STEP_INDEX=10 LABEL="Firmware bundle uploaded" python3 "${{ github.workspace }}/scripts/ci/report-convex-ci-progress.py" echo "r2_key=${ARTIFACT_NAME}" >> "$GITHUB_OUTPUT" - name: Notify Convex — success if: success() shell: bash env: R2_KEY: ${{ steps.pio.outputs.r2_key }} run: | curl -sSf -X POST "$CONVEX_URL/ingest-repo-build" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $CONVEX_BUILD_TOKEN" \ -d "{\"repo_build_id\":\"$REPO_BUILD_ID\",\"state\":\"succeeded\",\"github_run_id\":${{ github.run_id }},\"r2ObjectKey\":\"$R2_KEY\"}" - name: Notify Convex — failure if: failure() shell: bash env: GITHUB_RUN_ID: ${{ github.run_id }} run: | python3 -c " import json, os, urllib.request err = open('/tmp/pio.log').read()[-4000:] if os.path.exists('/tmp/pio.log') else 'build failed' body = { 'repo_build_id': os.environ['REPO_BUILD_ID'], 'state': 'failed', 'github_run_id': int(os.environ['GITHUB_RUN_ID']), 'errorSummary': err, } req = urllib.request.Request( os.environ['CONVEX_URL'] + '/ingest-repo-build', data=json.dumps(body).encode(), headers={'Content-Type': 'application/json', 'Authorization': 'Bearer ' + os.environ['CONVEX_BUILD_TOKEN']}, method='POST', ) urllib.request.urlopen(req) "