feat: add firmware stats extraction and PR commenting

This commit is contained in:
Arthur Tazhitdinov 2026-01-29 02:52:33 +05:00
parent da4d3b5ea5
commit ecc5057a1b

View File

@ -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 = '<!-- firmware-stats -->';
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,
});
}