From ecc5057a1b2d6b7b780c6ad5fea25a5569382330 Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Thu, 29 Jan 2026 02:52:33 +0500 Subject: [PATCH] feat: add firmware stats extraction and PR commenting --- .github/workflows/ci.yml | 53 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 286f14aa..05060400 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,6 +4,10 @@ name: CI branches: [master] pull_request: +permissions: + contents: read + pull-requests: write + jobs: build: runs-on: ubuntu-latest @@ -34,4 +38,51 @@ jobs: run: PATH="/usr/lib/llvm-21/bin:$PATH" ./bin/clang-format-fix && git diff --exit-code || (echo "Please run 'bin/clang-format-fix' to fix formatting issues" && exit 1) - name: Build CrossPoint - run: pio run + run: | + set -euo pipefail + pio run | tee pio.log + + - name: Extract firmware stats + id: fw_stats + run: | + set -euo pipefail + ram_line="$(grep -E "RAM:\\s" -m1 pio.log || true)" + flash_line="$(grep -E "Flash:\\s" -m1 pio.log || true)" + echo "ram_line=${ram_line}" >> "$GITHUB_OUTPUT" + echo "flash_line=${flash_line}" >> "$GITHUB_OUTPUT" + { + echo "## Firmware build stats" + if [ -n "$ram_line" ]; then echo "- ${ram_line}"; else echo "- RAM: not found"; fi + if [ -n "$flash_line" ]; then echo "- ${flash_line}"; else echo "- Flash: not found"; fi + } >> "$GITHUB_STEP_SUMMARY" + + - name: Comment PR with firmware stats + if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false + uses: actions/github-script@v7 + with: + script: | + const marker = ''; + const ram = `${{ steps.fw_stats.outputs.ram_line }}`.trim(); + const flash = `${{ steps.fw_stats.outputs.flash_line }}`.trim(); + const body = `${marker}\n**Firmware build stats**\n\n- ${ram || 'RAM: not found'}\n- ${flash || 'Flash: not found'}`; + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + }); + const existing = comments.find((comment) => comment.body && comment.body.includes(marker)); + if (existing) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: existing.id, + body, + }); + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body, + }); + }