mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-09-25 03:38:22 +08:00
The commit hash compiled into px4_firmware_version_binary() changes its code size, so a PR with no code change reported -8 B on v6x and got a comment. Changes that only touch agent instructions also no longer build the targets. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
245 lines
8.3 KiB
YAML
245 lines
8.3 KiB
YAML
name: FLASH usage analysis
|
|
|
|
permissions:
|
|
contents: read
|
|
pull-requests: write
|
|
issues: write
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- 'main'
|
|
paths-ignore:
|
|
- 'docs/**'
|
|
- '.agents/**'
|
|
- '.claude/**'
|
|
- '**/AGENTS.md'
|
|
- '**/CLAUDE.md'
|
|
pull_request:
|
|
branches:
|
|
- '**'
|
|
paths-ignore:
|
|
- 'docs/**'
|
|
- '.agents/**'
|
|
- '.claude/**'
|
|
- '**/AGENTS.md'
|
|
- '**/CLAUDE.md'
|
|
|
|
jobs:
|
|
analyze_flash:
|
|
name: Analyzing ${{ matrix.target }}
|
|
runs-on: [runs-on,runner=4cpu-linux-x64,image=ubuntu24-full-x64,"run-id=${{ github.run_id }}",spot=false,extras=s3-cache]
|
|
container:
|
|
image: ghcr.io/px4/px4-dev:v1.17.0-rc2
|
|
strategy:
|
|
matrix:
|
|
target: [px4_fmu-v5x, px4_fmu-v6x]
|
|
outputs:
|
|
px4_fmu-v5x-bloaty-output: ${{ steps.gen-output.outputs.px4_fmu-v5x-bloaty-output }}
|
|
px4_fmu-v5x-memory-summary: ${{ steps.gen-output.outputs.px4_fmu-v5x-memory-summary }}
|
|
px4_fmu-v6x-bloaty-output: ${{ steps.gen-output.outputs.px4_fmu-v6x-bloaty-output }}
|
|
px4_fmu-v6x-memory-summary: ${{ steps.gen-output.outputs.px4_fmu-v6x-memory-summary }}
|
|
steps:
|
|
- uses: runs-on/action@v2
|
|
- uses: actions/checkout@v6
|
|
with:
|
|
fetch-depth: 0
|
|
submodules: recursive
|
|
- name: Configure Git Safe Directory
|
|
run: git config --system --add safe.directory '*'
|
|
|
|
- name: Test and preserve memory reporter
|
|
# The baseline checkout may not contain this version of the reporter.
|
|
run: |
|
|
python3 -m unittest discover -s Tools/ci -p test_firmware_size.py
|
|
cp Tools/ci/firmware_size.py "$RUNNER_TEMP/firmware_size.py"
|
|
|
|
- name: Cache - Restore ccache (current)
|
|
id: cache_current
|
|
uses: actions/cache/restore@v5
|
|
with:
|
|
path: ~/.ccache
|
|
key: ccache-flash-${{ matrix.target }}-current-${{ github.ref_name }}-${{ github.sha }}
|
|
restore-keys: |
|
|
ccache-flash-${{ matrix.target }}-current-${{ github.ref_name }}-
|
|
ccache-flash-${{ matrix.target }}-current-
|
|
|
|
- name: Cache - Configure ccache
|
|
run: |
|
|
mkdir -p ~/.ccache
|
|
echo "base_dir = ${GITHUB_WORKSPACE}" > ~/.ccache/ccache.conf
|
|
echo "compression = true" >> ~/.ccache/ccache.conf
|
|
echo "compression_level = 6" >> ~/.ccache/ccache.conf
|
|
echo "max_size = 200M" >> ~/.ccache/ccache.conf
|
|
echo "hash_dir = false" >> ~/.ccache/ccache.conf
|
|
echo "compiler_check = content" >> ~/.ccache/ccache.conf
|
|
ccache -s
|
|
ccache -z
|
|
|
|
- name: Build Target
|
|
run: make ${{ matrix.target }}_flash-analysis
|
|
|
|
- name: Store the ELF with the change
|
|
run: cp ./build/**/*.elf ./with-change.elf
|
|
|
|
- name: Cache - Stats after Current Build
|
|
run: ccache -s
|
|
|
|
- name: Cache - Save ccache (current)
|
|
if: always()
|
|
uses: actions/cache/save@v5
|
|
with:
|
|
path: ~/.ccache
|
|
key: ${{ steps.cache_current.outputs.cache-primary-key }}
|
|
|
|
- name: Clean previous build
|
|
run: |
|
|
make clean
|
|
make distclean
|
|
make submodulesclean
|
|
ccache -C
|
|
|
|
- name: If it's a PR checkout the base of the merge commit
|
|
if: ${{ github.event.pull_request }}
|
|
# The base branch tip may already contain this PR (merged while the job was queued) or unrelated commits.
|
|
run: git checkout ${{ github.sha }}^1
|
|
|
|
- name: If it's a push checkout the previous commit
|
|
if: github.event_name == 'push'
|
|
run: git checkout ${{ github.event.before }}
|
|
|
|
- name: Update submodules
|
|
run: make submodulesupdate
|
|
|
|
- name: Cache - Restore ccache (baseline)
|
|
id: cache_baseline
|
|
uses: actions/cache/restore@v5
|
|
with:
|
|
path: ~/.ccache
|
|
key: ccache-flash-${{ matrix.target }}-baseline-${{ github.sha }}
|
|
restore-keys: |
|
|
ccache-flash-${{ matrix.target }}-baseline-
|
|
|
|
- name: Cache - Reset ccache stats
|
|
run: ccache -z
|
|
|
|
- name: Build
|
|
run: make ${{ matrix.target }}_flash-analysis
|
|
|
|
- name: Store the ELF before the change
|
|
run: cp ./build/**/*.elf ./before-change.elf
|
|
|
|
- name: Cache - Stats after Baseline Build
|
|
run: ccache -s
|
|
|
|
- name: Cache - Save ccache (baseline)
|
|
if: always()
|
|
uses: actions/cache/save@v5
|
|
with:
|
|
path: ~/.ccache
|
|
key: ${{ steps.cache_baseline.outputs.cache-primary-key }}
|
|
|
|
- name: bloaty-action
|
|
uses: PX4/bloaty-action@v1.0.0
|
|
id: bloaty-step
|
|
with:
|
|
bloaty-file-args: ./with-change.elf -- ./before-change.elf
|
|
bloaty-additional-args: -d sections,symbols -s vm -n 20 --domain=vm
|
|
output-to-summary: true
|
|
|
|
- name: Generate output
|
|
id: gen-output
|
|
env:
|
|
BLOATY_OUTPUT: ${{ steps.bloaty-step.outputs.bloaty-output }}
|
|
run: |
|
|
summary=$(python3 "$RUNNER_TEMP/firmware_size.py" \
|
|
--before before-change.elf --after with-change.elf)
|
|
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
|
|
{
|
|
echo "${{ matrix.target }}-memory-summary=$summary"
|
|
echo "${{ matrix.target }}-bloaty-output<<$EOF"
|
|
printf '%s\n' "$BLOATY_OUTPUT"
|
|
echo "$EOF"
|
|
} >> "$GITHUB_OUTPUT"
|
|
|
|
post_pr_comment:
|
|
name: Publish Results
|
|
runs-on: [runs-on,runner=1cpu-linux-x64,image=ubuntu24-full-x64,"run-id=${{ github.run_id }}"]
|
|
needs: [analyze_flash]
|
|
env:
|
|
V5X_FLASH: ${{ fromJSON(needs.analyze_flash.outputs.px4_fmu-v5x-memory-summary).flash }}
|
|
V5X_RAM: ${{ fromJSON(needs.analyze_flash.outputs.px4_fmu-v5x-memory-summary).ram }}
|
|
V5X_CHANGED: ${{ fromJSON(needs.analyze_flash.outputs.px4_fmu-v5x-memory-summary).changed }}
|
|
V6X_FLASH: ${{ fromJSON(needs.analyze_flash.outputs.px4_fmu-v6x-memory-summary).flash }}
|
|
V6X_RAM: ${{ fromJSON(needs.analyze_flash.outputs.px4_fmu-v6x-memory-summary).ram }}
|
|
V6X_CHANGED: ${{ fromJSON(needs.analyze_flash.outputs.px4_fmu-v6x-memory-summary).changed }}
|
|
if: github.event.pull_request
|
|
steps:
|
|
- name: Find Comment
|
|
uses: peter-evans/find-comment@v4
|
|
id: fc
|
|
with:
|
|
issue-number: ${{ github.event.pull_request.number }}
|
|
comment-author: 'github-actions[bot]'
|
|
body-includes: '<!-- pr-comment-poster:flash-analysis -->'
|
|
|
|
- name: Set Build Time
|
|
id: bt
|
|
run: |
|
|
echo "timestamp=$(date +'%Y-%m-%dT%H:%M:%S')" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Write pr-comment artifact
|
|
# Update existing comments even when both deltas return to zero.
|
|
# This can't be moved to the job-level conditions, as GH actions don't allow a job-level if condition to access the env.
|
|
if: |
|
|
steps.fc.outputs.comment-id != '' ||
|
|
env.V5X_CHANGED == 'true' ||
|
|
env.V6X_CHANGED == 'true'
|
|
run: |
|
|
mkdir -p pr-comment
|
|
cat > pr-comment/manifest.json <<EOF
|
|
{
|
|
"pr_number": ${{ github.event.pull_request.number }},
|
|
"marker": "<!-- pr-comment-poster:flash-analysis -->",
|
|
"mode": "upsert"
|
|
}
|
|
EOF
|
|
cat > pr-comment/body.md <<'PR_COMMENT_BODY_EOF'
|
|
<!-- pr-comment-poster:flash-analysis -->
|
|
## 🔎 Flash and RAM Analysis
|
|
|
|
| Target | Flash change | Static RAM change |
|
|
| --- | ---: | ---: |
|
|
| px4_fmu-v5x | ${{ env.V5X_FLASH }} | ${{ env.V5X_RAM }} |
|
|
| px4_fmu-v6x | ${{ env.V6X_FLASH }} | ${{ env.V6X_RAM }} |
|
|
|
|
<details>
|
|
<summary>px4_fmu-v5x — Bloaty section/symbol breakdown</summary>
|
|
|
|
```
|
|
${{ needs.analyze_flash.outputs.px4_fmu-v5x-bloaty-output }}
|
|
```
|
|
</details>
|
|
|
|
<details>
|
|
<summary>px4_fmu-v6x — Bloaty section/symbol breakdown</summary>
|
|
|
|
```
|
|
${{ needs.analyze_flash.outputs.px4_fmu-v6x-bloaty-output }}
|
|
```
|
|
</details>
|
|
|
|
**Updated: _${{ steps.bt.outputs.timestamp }}_**
|
|
PR_COMMENT_BODY_EOF
|
|
|
|
- name: Upload pr-comment artifact
|
|
if: |
|
|
steps.fc.outputs.comment-id != '' ||
|
|
env.V5X_CHANGED == 'true' ||
|
|
env.V6X_CHANGED == 'true'
|
|
uses: actions/upload-artifact@v7
|
|
with:
|
|
name: pr-comment
|
|
path: pr-comment/
|
|
retention-days: 1
|