Skip to content

Commit

Permalink
ci: add bin size comparison
Browse files Browse the repository at this point in the history
Signed-off-by: Haobo Gu <[email protected]>
  • Loading branch information
HaoboGu committed Dec 16, 2024
1 parent 9316a3c commit 1e7f647
Showing 1 changed file with 64 additions and 4 deletions.
68 changes: 64 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ jobs:
- name: Build nrf52832_ble
working-directory: ./examples/use_rust/nrf52832_ble
run: cargo make uf2 --release
- name: Build nrf52840_ble with config
working-directory: ./examples/use_config/nrf52840_ble
run: cargo make uf2 --release
- name: Build nrf52832_ble with config
working-directory: ./examples/use_config/nrf52832_ble
run: cargo make uf2 --release
Expand All @@ -80,4 +77,67 @@ jobs:
- name: Build rp2040 split with config
working-directory: ./examples/use_config/nrf52840_ble_split
run: cargo make uf2 --release

binary-size:
# Copied from sequential-storage: https://github.com/tweedegolf/sequential-storage/blob/master/.github/workflows/ci.yaml
runs-on: ubuntu-latest
permissions:
actions: read
pull-requests: write
steps:
- uses: dtolnay/rust-toolchain@nightly
- uses: actions/cache@v3
id: cache-cargo
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
./example/target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- run: rustup target add thumbv7em-none-eabihf
- run: rustup component add rust-src llvm-tools
- if: steps.cache-cargo.outputs.cache-hit != 'true'
run: cargo install cargo-binutils

- name: Check out the repo with the full git history
uses: actions/checkout@v3
with:
fetch-depth: '0'
- name: Build new binary
working-directory: ./examples/use_config/nrf52840_ble
run: |
echo 'RESULT<<EOF' >> $GITHUB_OUTPUT
cargo size --release >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
id: new-size
- name: Save binary
run: |
mv ./examples/use_config/nrf52840_ble/target/thumbv7em-none-eabihf/release/rmk-nrf52840 ./examples/use_config/nrf52840_ble/target/thumbv7em-none-eabihf/release/original.elf
- name: If it's a PR checkout the base commit
if: ${{ github.event.pull_request }}
run: git checkout ${{ github.event.pull_request.base.sha }}
- name: Rebuild with the base commit
if: ${{ github.event.pull_request }}
working-directory: ./examples/use_config/nrf52840_ble
run: cargo build --release
- name: Run Bloaty to compare both output files
if: ${{ github.event.pull_request }}
id: bloaty-comparison
uses: carlosperate/bloaty-action@v1
with:
bloaty-args: ./examples/use_config/nrf52840_ble/target/thumbv7em-none-eabihf/release/original.elf -- ./examples/use_config/nrf52840_ble/target/thumbv7em-none-eabihf/release/rmk-nrf52840
output-to-summary: true
- name: Add a PR comment with the bloaty diff
if: ${{ github.event.pull_request }}
continue-on-error: true
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `## PR build size\n \`\`\`\n${{ join(steps.new-size.outputs.*, '\n') }}\n\`\`\`\n ### Diff\n\`\`\`\n${{ steps.bloaty-comparison.outputs.bloaty-output-encoded }}\`\`\`\n`
})

0 comments on commit 1e7f647

Please sign in to comment.