Github actions improvements #13
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: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
continue-on-error: true | |
strategy: | |
matrix: | |
variant: | |
- hardware-rev0 | |
- esp32dev | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 50 | |
- 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 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' | |
run: git checkout ${{ 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 | |
# 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'); | |
if (report) { | |
github.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: '## Firmware size changes for ${{ matrix.variant }}\n\nCommit ${{ github.sha }}\n```\n' + report + '\n```' | |
}); | |
} |