From ecc5057a1b2d6b7b780c6ad5fea25a5569382330 Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Thu, 29 Jan 2026 02:52:33 +0500 Subject: [PATCH 01/15] 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, + }); + } From baebb3b2e2da28d23fa37ce4cf9f86fd6af99239 Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Thu, 29 Jan 2026 03:08:02 +0500 Subject: [PATCH 02/15] Adjust condition for commenting PR with firmware stats --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 05060400..57c7c2de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,7 +57,7 @@ jobs: } >> "$GITHUB_STEP_SUMMARY" - name: Comment PR with firmware stats - if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false + if: github.event_name == 'pull_request' uses: actions/github-script@v7 with: script: | From 873611b98996e30c14f744d70693aa2b73aaa2c5 Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Thu, 29 Jan 2026 03:21:36 +0500 Subject: [PATCH 03/15] chore: update CI workflows and add labeler configuration --- .github/labeler.yml | 38 +++++++++++++++++ .github/workflows/ci.yml | 52 ++++++++++++++++++----- .github/workflows/pr-formatting-check.yml | 39 +++++++++++++++++ 3 files changed, 118 insertions(+), 11 deletions(-) create mode 100644 .github/labeler.yml diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 00000000..eae3f875 --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,38 @@ +firmware: + - changed-files: + - any-glob-to-any-file: + - src/** + - lib/** + - open-x4-sdk/** + +ui: + - changed-files: + - any-glob-to-any-file: + - src/activities/** + - src/network/html/** + - docs/images/** + +epub: + - changed-files: + - any-glob-to-any-file: + - lib/Epub/** + +network: + - changed-files: + - any-glob-to-any-file: + - src/network/** + - src/util/UrlUtils.* + - lib/OpdsParser/** + +docs: + - changed-files: + - any-glob-to-any-file: + - docs/** + - README* + - CHANGELOG* + +tests: + - changed-files: + - any-glob-to-any-file: + - test/** + - scripts/** diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57c7c2de..e12c26a1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,34 @@ permissions: pull-requests: write jobs: - build: + label: + runs-on: ubuntu-latest + steps: + - uses: actions/labeler@v5 + + clang-format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + with: + submodules: recursive + + - uses: actions/setup-python@v6 + with: + python-version: '3.14' + + - name: Install clang-format-21 + run: | + wget https://apt.llvm.org/llvm.sh + chmod +x llvm.sh + sudo ./llvm.sh 21 + sudo apt-get update + sudo apt-get install -y clang-format-21 + + - name: Run clang-format + 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) + + cppcheck: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 @@ -23,19 +50,22 @@ jobs: - name: Install PlatformIO Core run: pip install --upgrade platformio - - name: Install clang-format-21 - run: | - wget https://apt.llvm.org/llvm.sh - chmod +x llvm.sh - sudo ./llvm.sh 21 - sudo apt-get update - sudo apt-get install -y clang-format-21 - - name: Run cppcheck run: pio check --fail-on-defect low --fail-on-defect medium --fail-on-defect high - - name: Run clang-format - 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) + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + with: + submodules: recursive + + - uses: actions/setup-python@v6 + with: + python-version: '3.14' + + - name: Install PlatformIO Core + run: pip install --upgrade platformio - name: Build CrossPoint run: | diff --git a/.github/workflows/pr-formatting-check.yml b/.github/workflows/pr-formatting-check.yml index 044b7b64..fd9c4d02 100644 --- a/.github/workflows/pr-formatting-check.yml +++ b/.github/workflows/pr-formatting-check.yml @@ -9,6 +9,7 @@ on: permissions: statuses: write + pull-requests: write jobs: title-check: @@ -21,6 +22,44 @@ jobs: egress-policy: audit - name: Check PR Title + id: title_check uses: amannn/action-semantic-pull-request@v6 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Comment with changelog hint on failure + if: failure() + uses: actions/github-script@v7 + with: + script: | + const marker = ''; + const error = + `${{ steps.title_check.outputs.error_message || steps.title_check.outputs.error || '' }}`.trim(); + const details = error ? `\n\n**Error:** ${error}` : '\n\n**Error:** See workflow logs.'; + const body = `${marker} + **PR title check failed** + + Please use a Conventional Commit-style prefix (e.g., \`feat:\`, \`fix:\`, \`docs:\`, \`chore:\`). + If this change should appear in release notes, ensure the title reflects the correct category.${details}`; + + 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, + }); + } From 826ccb2d255a1dbc4b2e38dc3e27e13bb49255c5 Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Thu, 29 Jan 2026 03:22:09 +0500 Subject: [PATCH 04/15] fix: format firmware stats in PR comment as code block --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e12c26a1..344bc945 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -94,7 +94,7 @@ jobs: 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 body = `${marker}\n**Firmware build stats**\n\n\`\`\`\n${ram || 'RAM: not found'}\n${flash || 'Flash: not found'}\n\`\`\``; const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, From cb95ddbd04161633faf4d5e816efc2a827f5470e Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Fri, 30 Jan 2026 22:24:51 +0500 Subject: [PATCH 05/15] feat: enhance PR commenting with firmware stats and upload firmware artifact --- .github/workflows/ci.yml | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 344bc945..514bc98c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -86,7 +86,14 @@ jobs: if [ -n "$flash_line" ]; then echo "- ${flash_line}"; else echo "- Flash: not found"; fi } >> "$GITHUB_STEP_SUMMARY" - - name: Comment PR with firmware stats + - name: Upload firmware.bin artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ github.event_name == 'pull_request' && format('firmware-bin-pr-{0}-{1}', github.event.pull_request.number, github.sha) || format('firmware-bin-{0}', github.sha) }} + path: .pio/build/default/firmware.bin + if-no-files-found: error + + - name: Comment PR with firmware stats and firmware.bin if: github.event_name == 'pull_request' uses: actions/github-script@v7 with: @@ -94,7 +101,27 @@ jobs: 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\`\`\`\n${ram || 'RAM: not found'}\n${flash || 'Flash: not found'}\n\`\`\``; + const prNumber = context.payload.pull_request?.number; + const artifactName = prNumber + ? `firmware-bin-pr-${prNumber}-${context.sha}` + : `firmware-bin-${context.sha}`; + let firmwareLine = 'Firmware: artifact not found'; + try { + const { data: artifacts } = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.runId, + }); + const firmwareArtifact = artifacts.artifacts.find((artifact) => artifact.name === artifactName); + if (firmwareArtifact) { + firmwareLine = `Firmware: [firmware.bin artifact](${firmwareArtifact.archive_download_url})`; + } else { + firmwareLine = `Firmware: artifact not found (${artifactName})`; + } + } catch (error) { + firmwareLine = `Firmware: artifact lookup failed (${error.message})`; + } + const body = `${marker}\n**Firmware build stats**\n\n\`\`\`\n${ram || 'RAM: not found'}\n${flash || 'Flash: not found'}\n\`\`\`\n\n**Firmware binary**\n${firmwareLine}`; const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, From c008d238d5f42891beefe7afd09c23cc28c49b8c Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Fri, 30 Jan 2026 22:32:27 +0500 Subject: [PATCH 06/15] fix: update firmware artifact link in PR comment to point to the UI --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 514bc98c..1a34f9c1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -114,7 +114,8 @@ jobs: }); const firmwareArtifact = artifacts.artifacts.find((artifact) => artifact.name === artifactName); if (firmwareArtifact) { - firmwareLine = `Firmware: [firmware.bin artifact](${firmwareArtifact.archive_download_url})`; + const artifactUiUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/artifacts/${firmwareArtifact.id}`; + firmwareLine = `Firmware: [firmware.bin artifact](${artifactUiUrl})`; } else { firmwareLine = `Firmware: artifact not found (${artifactName})`; } From a540edd437b0346fe90a84cf1a15032a4a2e572f Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Fri, 30 Jan 2026 22:51:28 +0500 Subject: [PATCH 07/15] feat: capture short SHA for firmware artifact naming in PR comments --- .github/workflows/ci.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a34f9c1..20b4ec74 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,6 +72,10 @@ jobs: set -euo pipefail pio run | tee pio.log + - name: Capture short SHA + id: short_sha + run: echo "short=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT" + - name: Extract firmware stats id: fw_stats run: | @@ -89,7 +93,7 @@ jobs: - name: Upload firmware.bin artifact uses: actions/upload-artifact@v4 with: - name: ${{ github.event_name == 'pull_request' && format('firmware-bin-pr-{0}-{1}', github.event.pull_request.number, github.sha) || format('firmware-bin-{0}', github.sha) }} + name: ${{ github.event_name == 'pull_request' && format('firmware-bin-pr-{0}-{1}', github.event.pull_request.number, steps.short_sha.outputs.short) || format('firmware-bin-{0}', steps.short_sha.outputs.short) }} path: .pio/build/default/firmware.bin if-no-files-found: error @@ -102,9 +106,10 @@ jobs: const ram = `${{ steps.fw_stats.outputs.ram_line }}`.trim(); const flash = `${{ steps.fw_stats.outputs.flash_line }}`.trim(); const prNumber = context.payload.pull_request?.number; + const shortSha = `${{ steps.short_sha.outputs.short }}`.trim() || context.sha.substring(0, 7); const artifactName = prNumber - ? `firmware-bin-pr-${prNumber}-${context.sha}` - : `firmware-bin-${context.sha}`; + ? `firmware-bin-pr-${prNumber}-${shortSha}` + : `firmware-bin-${shortSha}`; let firmwareLine = 'Firmware: artifact not found'; try { const { data: artifacts } = await github.rest.actions.listWorkflowRunArtifacts({ @@ -115,7 +120,7 @@ jobs: const firmwareArtifact = artifacts.artifacts.find((artifact) => artifact.name === artifactName); if (firmwareArtifact) { const artifactUiUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/artifacts/${firmwareArtifact.id}`; - firmwareLine = `Firmware: [firmware.bin artifact](${artifactUiUrl})`; + firmwareLine = `Firmware: [${artifactName}](${artifactUiUrl})`; } else { firmwareLine = `Firmware: artifact not found (${artifactName})`; } From 328d504cb00a5d8d711a33680ebda3b36972b872 Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Sun, 1 Feb 2026 16:46:26 +0500 Subject: [PATCH 08/15] try repository-projects: write --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 20b4ec74..6480c0f3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,8 @@ name: CI permissions: contents: read pull-requests: write + repository-projects: write + jobs: label: From e3c799e05cb0640359289a679f7eb56125629809 Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Sun, 1 Feb 2026 16:51:19 +0500 Subject: [PATCH 09/15] Update .github/workflows/pr-formatting-check.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/pr-formatting-check.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-formatting-check.yml b/.github/workflows/pr-formatting-check.yml index fd9c4d02..7808fd71 100644 --- a/.github/workflows/pr-formatting-check.yml +++ b/.github/workflows/pr-formatting-check.yml @@ -37,10 +37,10 @@ jobs: `${{ steps.title_check.outputs.error_message || steps.title_check.outputs.error || '' }}`.trim(); const details = error ? `\n\n**Error:** ${error}` : '\n\n**Error:** See workflow logs.'; const body = `${marker} - **PR title check failed** +**PR title check failed** - Please use a Conventional Commit-style prefix (e.g., \`feat:\`, \`fix:\`, \`docs:\`, \`chore:\`). - If this change should appear in release notes, ensure the title reflects the correct category.${details}`; +Please use a Conventional Commit-style prefix (e.g., \`feat:\`, \`fix:\`, \`docs:\`, \`chore:\`). +If this change should appear in release notes, ensure the title reflects the correct category.${details}`; const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, From eebf9a7c9fbc73d3bc4a79c5904180d735393463 Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Sun, 1 Feb 2026 16:52:59 +0500 Subject: [PATCH 10/15] revert repository-projects: write --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6480c0f3..730a4455 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,6 @@ name: CI permissions: contents: read pull-requests: write - repository-projects: write jobs: From ce204d1a8fb785d28e0384bcf774291c041e68b8 Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Sun, 1 Feb 2026 17:00:57 +0500 Subject: [PATCH 11/15] try issues: write --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 730a4455..43e29df9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,7 @@ name: CI permissions: contents: read + issues: write pull-requests: write From 7f08cc36672700ffbb2b0f9d74e30357ad889058 Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Sun, 1 Feb 2026 17:07:10 +0500 Subject: [PATCH 12/15] try github-script v8 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43e29df9..b7976d66 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -101,7 +101,7 @@ jobs: - name: Comment PR with firmware stats and firmware.bin if: github.event_name == 'pull_request' - uses: actions/github-script@v7 + uses: actions/github-script@v8 with: script: | const marker = ''; From e8e067da5548948c821f90e5ed69cd384ddb38a4 Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Sun, 1 Feb 2026 17:11:27 +0500 Subject: [PATCH 13/15] try permissions write-all --- .github/workflows/ci.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b7976d66..643d1dba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,10 +4,13 @@ name: CI branches: [master] pull_request: -permissions: - contents: read - issues: write - pull-requests: write +# permissions: +# contents: read +# issues: write +# pull-requests: write + +permissions: + write-all jobs: From c572f4fffeafd8916a6b127a1eaaf1e7d053eff8 Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Sun, 1 Feb 2026 17:15:31 +0500 Subject: [PATCH 14/15] try with no permissions --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 643d1dba..5aae91ed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,8 +9,8 @@ name: CI # issues: write # pull-requests: write -permissions: - write-all +# permissions: +# write-all jobs: From 55d2c985c1a9ecb160cc438b0ccb6867fa477d6c Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Sun, 1 Feb 2026 21:18:11 +0300 Subject: [PATCH 15/15] add pr-writer --- .github/workflows/ci.yml | 96 +++++---------------- .github/workflows/pr-writer.yml | 145 ++++++++++++++++++++++++++++++++ 2 files changed, 167 insertions(+), 74 deletions(-) create mode 100644 .github/workflows/pr-writer.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5aae91ed..5a8cb085 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,32 +1,22 @@ -name: CI -'on': +name: CI (build) + +on: push: branches: [master] pull_request: -# permissions: -# contents: read -# issues: write -# pull-requests: write - -# permissions: -# write-all - +permissions: + contents: read jobs: - label: - runs-on: ubuntu-latest - steps: - - uses: actions/labeler@v5 - clang-format: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v4 with: submodules: recursive - - uses: actions/setup-python@v6 + - uses: actions/setup-python@v5 with: python-version: '3.14' @@ -39,16 +29,18 @@ jobs: sudo apt-get install -y clang-format-21 - name: Run clang-format - 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) + 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) cppcheck: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v4 with: submodules: recursive - - uses: actions/setup-python@v6 + - uses: actions/setup-python@v5 with: python-version: '3.14' @@ -61,11 +53,11 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v4 with: submodules: recursive - - uses: actions/setup-python@v6 + - uses: actions/setup-python@v5 with: python-version: '3.14' @@ -95,62 +87,18 @@ jobs: if [ -n "$flash_line" ]; then echo "- ${flash_line}"; else echo "- Flash: not found"; fi } >> "$GITHUB_STEP_SUMMARY" + # Upload both the binary and the stats/log so Stage 2 can read them without checkout. - name: Upload firmware.bin artifact uses: actions/upload-artifact@v4 with: - name: ${{ github.event_name == 'pull_request' && format('firmware-bin-pr-{0}-{1}', github.event.pull_request.number, steps.short_sha.outputs.short) || format('firmware-bin-{0}', steps.short_sha.outputs.short) }} + name: firmware-bin path: .pio/build/default/firmware.bin if-no-files-found: error - - name: Comment PR with firmware stats and firmware.bin - if: github.event_name == 'pull_request' - uses: actions/github-script@v8 + - name: Upload build metadata artifact + uses: actions/upload-artifact@v4 with: - script: | - const marker = ''; - const ram = `${{ steps.fw_stats.outputs.ram_line }}`.trim(); - const flash = `${{ steps.fw_stats.outputs.flash_line }}`.trim(); - const prNumber = context.payload.pull_request?.number; - const shortSha = `${{ steps.short_sha.outputs.short }}`.trim() || context.sha.substring(0, 7); - const artifactName = prNumber - ? `firmware-bin-pr-${prNumber}-${shortSha}` - : `firmware-bin-${shortSha}`; - let firmwareLine = 'Firmware: artifact not found'; - try { - const { data: artifacts } = await github.rest.actions.listWorkflowRunArtifacts({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: context.runId, - }); - const firmwareArtifact = artifacts.artifacts.find((artifact) => artifact.name === artifactName); - if (firmwareArtifact) { - const artifactUiUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/artifacts/${firmwareArtifact.id}`; - firmwareLine = `Firmware: [${artifactName}](${artifactUiUrl})`; - } else { - firmwareLine = `Firmware: artifact not found (${artifactName})`; - } - } catch (error) { - firmwareLine = `Firmware: artifact lookup failed (${error.message})`; - } - const body = `${marker}\n**Firmware build stats**\n\n\`\`\`\n${ram || 'RAM: not found'}\n${flash || 'Flash: not found'}\n\`\`\`\n\n**Firmware binary**\n${firmwareLine}`; - 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, - }); - } + name: build-meta + path: | + pio.log + if-no-files-found: error \ No newline at end of file diff --git a/.github/workflows/pr-writer.yml b/.github/workflows/pr-writer.yml new file mode 100644 index 00000000..fec4f42b --- /dev/null +++ b/.github/workflows/pr-writer.yml @@ -0,0 +1,145 @@ +comment_firmware: + runs-on: ubuntu-latest + steps: + - name: Find the matching CI run for this PR SHA + id: find_run + uses: actions/github-script@v8 + with: + script: | + const owner = context.repo.owner; + const repo = context.repo.repo; + const pr = context.payload.pull_request; + const headSha = pr.head.sha; + + const { data } = await github.rest.actions.listWorkflowRunsForRepo({ + owner, + repo, + event: "pull_request", + per_page: 50, + }); + + const run = data.workflow_runs.find(r => r.head_sha === headSha && r.name === "CI (build)"); + if (!run) core.setFailed(`No matching CI (build) run found for head_sha=${headSha}.`); + + core.setOutput("run_id", String(run.id)); + core.setOutput("run_html_url", run.html_url); + + - name: Locate artifact IDs in the CI run + id: artifacts + uses: actions/github-script@v8 + with: + script: | + const owner = context.repo.owner; + const repo = context.repo.repo; + const runId = Number("${{ steps.find_run.outputs.run_id }}"); + + const { data } = await github.rest.actions.listWorkflowRunArtifacts({ + owner, + repo, + run_id: runId, + per_page: 100, + }); + + const artifacts = data.artifacts || []; + const fw = artifacts.find(a => a.name === "firmware-bin"); + const meta = artifacts.find(a => a.name === "build-meta"); + + if (!meta) core.setFailed("build-meta artifact not found in CI run artifacts."); + // firmware-bin is nice-to-have for linking; fail if you want. + core.setOutput("fw_id", fw ? String(fw.id) : ""); + core.setOutput("meta_id", String(meta.id)); + + - name: Download build-meta artifact zip and extract pio.log + id: parse_log + shell: bash + env: + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} + META_ID: ${{ steps.artifacts.outputs.meta_id }} + GH_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + + # Download artifact zip via GitHub API (will redirect to blob storage; -L follows) + api="https://api.github.com/repos/${OWNER}/${REPO}/actions/artifacts/${META_ID}/zip" + curl -sSL \ + -H "Authorization: Bearer ${GH_TOKEN}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + -o build-meta.zip \ + "${api}" + + mkdir -p build-meta + unzip -q build-meta.zip -d build-meta + + if [[ ! -f build-meta/pio.log ]]; then + echo "pio.log not found inside build-meta artifact" + echo "ram_line=" >> "$GITHUB_OUTPUT" + echo "flash_line=" >> "$GITHUB_OUTPUT" + exit 0 + fi + + ram_line="$(grep -E "RAM:\s" -m1 build-meta/pio.log || true)" + flash_line="$(grep -E "Flash:\s" -m1 build-meta/pio.log || true)" + + echo "ram_line=${ram_line}" >> "$GITHUB_OUTPUT" + echo "flash_line=${flash_line}" >> "$GITHUB_OUTPUT" + + - name: Post/update PR comment with RAM/Flash + artifact links + uses: actions/github-script@v8 + with: + script: | + const owner = context.repo.owner; + const repo = context.repo.repo; + const prNumber = context.payload.pull_request.number; + + const runId = Number("${{ steps.find_run.outputs.run_id }}"); + const runUrl = "${{ steps.find_run.outputs.run_html_url }}"; + + const marker = ''; + const ram = `${{ steps.parse_log.outputs.ram_line }}`.trim(); + const flash = `${{ steps.parse_log.outputs.flash_line }}`.trim(); + + const fwId = `${{ steps.artifacts.outputs.fw_id }}`.trim(); + const metaId = `${{ steps.artifacts.outputs.meta_id }}`.trim(); + + const fwUrl = fwId ? `https://github.com/${owner}/${repo}/actions/runs/${runId}/artifacts/${fwId}` : null; + const metaUrl = metaId ? `https://github.com/${owner}/${repo}/actions/runs/${runId}/artifacts/${metaId}` : null; + + const body = +`${marker} +**Firmware build stats** + +\`\`\` +${ram || "RAM: not found"} +${flash || "Flash: not found"} +\`\`\` + +**Artifacts** +- CI run: ${runUrl} +- Firmware binary: ${fwUrl ? `[firmware-bin](${fwUrl})` : "artifact not found"} +- Build logs: ${metaUrl ? `[build-meta](${metaUrl})` : "artifact not found"} +`; + + const { data: comments } = await github.rest.issues.listComments({ + owner, + repo, + issue_number: prNumber, + per_page: 100, + }); + + const existing = comments.find(c => (c.body || "").includes(marker)); + if (existing) { + await github.rest.issues.updateComment({ + owner, + repo, + comment_id: existing.id, + body, + }); + } else { + await github.rest.issues.createComment({ + owner, + repo, + issue_number: prNumber, + body, + }); + } \ No newline at end of file