Skip to content

Cpp23 best practices #126

Cpp23 best practices

Cpp23 best practices #126

Workflow file for this run

name: Compare firmware sizes (Pull request)
on:
workflow_dispatch:
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
size_report:
runs-on: ubuntu-latest
continue-on-error: true
strategy:
matrix:
variant:
- hardware-rev0-it_IT
- esp32-devboard
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 50
- uses: actions/cache@v4
with:
path: |
~/.cache/pip
~/.platformio/.cache
~/.platformio/packages
key: ${{ runner.os }}-size-${{ matrix.variant }}
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install PlatformIO Core
run: pip install --upgrade platformio
- name: Use secrets.hpp.example as base for the build
run: cp conf/secrets.hpp.example conf/secrets.hpp
- name: Build PlatformIO Project (current version)
run: pio run --environment ${{ matrix.variant }}
- name: Copy latest MAP file
run: cp .pio/build/${{ matrix.variant }}/firmware.map ../firmware.map.latest
# Now build the previous version after checkout if not run by pull request
- name: Checkout previous commit
if: github.event_name != 'pull_request'
run: git checkout HEAD^
# Get the PR head if run by pull request
- name: Checkout PR head
if: github.event_name == 'pull_request'
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref }}
# Now build as usual...
- name: Use secrets.hpp.example as base for the build
run: cp conf/secrets.hpp.example conf/secrets.hpp
- name: Build PlatformIO Project (previous version ${{ github.event.pull_request.base.ref }})
run: pio run --environment ${{ matrix.variant }}
- name: Copy previous MAP file
run: cp .pio/build/${{ matrix.variant }}/firmware.map ../firmware.map.previous
# Now compares both MAP files with esp_idf_size
- name: Compare MAP files
run: python -m esp_idf_size --format=text --diff=../firmware.map.previous ../firmware.map.latest -o size_report.txt
# Detailed report
- name: Compare MAP files
run: python -m esp_idf_size --archives --format=text --diff=../firmware.map.previous ../firmware.map.latest -o size_report_details.txt
# Upload the size report as an artifact
- name: Upload size report
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.variant }}_size_report
path: |
size_report.txt
size_report_details.txt
retention-days: 90
# If this comes from a pull request, comment the size changes
- name: Comment size changes
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const report = fs.readFileSync('size_report.txt', 'utf8');
if (report) {
// Delete previous comments
github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
}).then(comments => {
comments.data.forEach(comment => {
if (comment.user.login === 'github-actions[bot]' && !comment.body.includes('${{ github.event.pull_request.head.sha }}')) {
github.rest.issues.deleteComment({
comment_id: comment.id,
owner: context.repo.owner,
repo: context.repo.repo
});
}
});
});
// Truncate report if it exceeds maximum comment length
const truncatedReport = report.length > 63*1024 ?
report.substring(0, 63*1024) + '... (truncated)' :
report;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '## Firmware size changes for ${{ matrix.variant }}\n\nCommit CURRENT ${{ github.event.pull_request.head.sha }} vs REFERENCE ${{ github.event.pull_request.base.sha }}\n```\n' + truncatedReport + '\n```'
});
}