From 0f47e99a087e60da072930f04445dc69c1a3bd9e Mon Sep 17 00:00:00 2001 From: kaczmarczyck <43844792+kaczmarczyck@users.noreply.github.com> Date: Thu, 21 Apr 2022 12:48:04 +0200 Subject: [PATCH] Workflow for cargo bloat (#462) * adds cargo bloat workflow * uses notice instead * warning for bigger sizes, ignore equal sizes * DO NOT MERGE, TEST COMMIT * reverted test commit --- .github/workflows/bloat_formatter.sh | 46 +++++++++++++++++++++++++++ .github/workflows/cargo_bloat.yml | 47 ++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100755 .github/workflows/bloat_formatter.sh create mode 100644 .github/workflows/cargo_bloat.yml diff --git a/.github/workflows/bloat_formatter.sh b/.github/workflows/bloat_formatter.sh new file mode 100755 index 0000000..e95f63b --- /dev/null +++ b/.github/workflows/bloat_formatter.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cd "$(dirname "$0")" + +# New output file is $1 +# Old output file is $2 +TMP=comment.md +WARNING="Note: numbers above are a result of guesswork. They are not 100% correct and never will be." +NEW_SIZE=$(cat "$1" | sed -nr 's/.*100.0% (.*)KiB .text.*/\1/p') +OLD_SIZE=$(cat "$2" | sed -nr 's/.*100.0% (.*)KiB .text.*/\1/p') + +echo " +OLD $OLD_SIZE kiB +NEW $NEW_SIZE kiB" > "$TMP" + +echo " +Output of cargo bloat +====================== +" >> "$TMP" + +echo "Including PR" >> "$TMP" +cat "$1" >> "$TMP" +echo "Base branch" >> "$TMP" +cat "$2" >> "$TMP" + +COMMENT="$(cat $TMP | sed "s/$WARNING//g" | sed 's/%/%25/g' | sed -z 's/\n/%0A/g')" +# No output for equality is intentional. +if (( $(echo "$NEW_SIZE > $OLD_SIZE" | bc -l) )); then + echo "::warning file=.github/workflows/cargo_bloat.yml,title=Binary size::$COMMENT" +fi +if (( $(echo "$NEW_SIZE < $OLD_SIZE" | bc -l) )); then + echo "::notice file=.github/workflows/cargo_bloat.yml,title=Binary size::$COMMENT" +fi diff --git a/.github/workflows/cargo_bloat.yml b/.github/workflows/cargo_bloat.yml new file mode 100644 index 0000000..55f9f48 --- /dev/null +++ b/.github/workflows/cargo_bloat.yml @@ -0,0 +1,47 @@ +name: Binary size report +on: pull_request + +jobs: + cargo_bloat: + runs-on: ubuntu-latest + steps: + # Setup + - uses: actions/setup-python@v1 + with: + python-version: 3.7 + - name: Install Python dependencies + run: python -m pip install --upgrade pip setuptools wheel + - uses: actions-rs/cargo@v1 + with: + command: install + args: cargo-bloat + + # First run: PR + - uses: actions/checkout@v2 + with: + submodules: true + - name: Install Rust toolchain + run: rustup show + - name: Set up OpenSK + run: ./setup.sh + - name: Run bloat on the PR + run: RUSTFLAGS="-C link-arg=-icf=all -C force-frame-pointers=no" cargo bloat --release --target=thumbv7em-none-eabi --features=with_ctap1,vendor_hid --crates >> .github/workflows/bloat_output_new.txt + + # Second run: PR + - uses: actions/checkout@v2 + with: + submodules: true + ref: ${{ github.base_ref }} + path: OpenSK_base + - name: Install old Rust toolchain + working-directory: ./OpenSK_base + run: rustup show + - name: Set up OpenSK + working-directory: ./OpenSK_base + run: ./setup.sh + - name: Run bloat on base + working-directory: ./OpenSK_base + run: RUSTFLAGS="-C link-arg=-icf=all -C force-frame-pointers=no" cargo bloat --release --target=thumbv7em-none-eabi --features=with_ctap1,vendor_hid --crates >> "$GITHUB_WORKSPACE/.github/workflows/bloat_output_old.txt" + + - name: Run output formatter to echo workflow command + run: ./.github/workflows/bloat_formatter.sh bloat_output_new.txt bloat_output_old.txt bloat_comment.md