Github actions improvements with matrixes #5
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Compare firmware sizes | |
on: | |
workflow_dispatch: | |
pull_request: | |
push: | |
paths: | |
- 'src/**' | |
- 'conf/**' | |
- 'include/**' | |
- 'platformio.ini' | |
- '.github/workflows/sizes.yml' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
continue-on-error: true | |
strategy: | |
matrix: | |
variant: | |
- hardware-rev0 | |
- esp32dev | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- uses: actions/cache@v4 | |
with: | |
path: | | |
~/.cache/pip | |
~/.platformio/.cache | |
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 .pio/build/firmware.map.latest | |
# Now build the previous version after checkout | |
- name: Checkout previous commit | |
run: git checkout HEAD^ | |
- 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) | |
run: pio run --environment ${{ matrix.variant }} | |
- name: Copy previous MAP file | |
run: cp .pio/build/${{ matrix.variant }}/firmware.map .pio/build/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=.pio/build/firmware.map.previous .pio/build/firmware.map.latest -o size_report.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 | |
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@v4 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const fs = require('fs'); | |
const report = fs.readFileSync('size_report.txt', 'utf8'); | |
const lines = report.split('\n'); | |
const comment = lines.filter(line => line.startsWith(' ')).join('\n'); | |
if (comment) { | |
github.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: '## Firmware size changes\n\n```\n' + comment + '\n```' | |
}); | |
} |