diff options
author | Riku Isokoski <riksu9000@gmail.com> | 2023-01-07 18:15:37 +0200 |
---|---|---|
committer | Riku Isokoski <riksu9000@gmail.com> | 2023-01-07 18:56:15 +0200 |
commit | 028d40860dc32a96ce70bf820053ec93bd52f36d (patch) | |
tree | bbdd064d377572ed732a49268dcc7fd7a87886cc /.github/workflows | |
parent | 499f0875d35970d8040152405a774511e9aed884 (diff) |
workflows: Add build size comparison workflow
Add .github/workflows/getSize.sh to extract sizes of sections from the
objfile
build-firmware uses getSize.sh to output the section sizes.
get-base-ref-size job added, which builds the base branch of the PR and
outputs the section sizes. Caches are used to avoid unnecessary builds
when the base branch hasn't been updated.
leave-build-size-comment job added, which creates or updates a comment
on the PR with the build size information from other jobs.
Diffstat (limited to '.github/workflows')
-rwxr-xr-x | .github/workflows/getSize.sh | 19 | ||||
-rw-r--r-- | .github/workflows/main.yml | 106 |
2 files changed, 122 insertions, 3 deletions
diff --git a/.github/workflows/getSize.sh b/.github/workflows/getSize.sh new file mode 100755 index 00000000..52a86132 --- /dev/null +++ b/.github/workflows/getSize.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +# Requires environment variables from docker/build.sh + +set -e + +SIZE_BIN="$TOOLS_DIR/$GCC_ARM_PATH/bin/arm-none-eabi-size" +[ ! -x "$SIZE_BIN" ] && exit 1 + +[ -z "$1" ] && exit 1 +SIZE_OUTPUT=$($SIZE_BIN "$1" | tail -n1) + +TEXT_SIZE=$(echo "$SIZE_OUTPUT" | cut -f 1 |tr -d '[:blank:]') +DATA_SIZE=$(echo "$SIZE_OUTPUT" | cut -f 2 |tr -d '[:blank:]') +BSS_SIZE=$(echo "$SIZE_OUTPUT" | cut -f 3 |tr -d '[:blank:]') + +echo "text_size=$TEXT_SIZE" +echo "data_size=$DATA_SIZE" +echo "bss_size=$BSS_SIZE" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7dc588cc..c2570627 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,12 +13,19 @@ on: - 'doc/**' - '**.md' - jobs: build-firmware: runs-on: ubuntu-latest container: image: infinitime/infinitime-build + outputs: + text_size: ${{ steps.output-sizes.outputs.text_size }} + data_size: ${{ steps.output-sizes.outputs.data_size }} + bss_size: ${{ steps.output-sizes.outputs.bss_size }} + env: + # InfiniTime sources are downloaded to the current directory. + # Override SOURCES_DIR in build.sh + SOURCES_DIR: . steps: - name: Checkout source files uses: actions/checkout@v3 @@ -26,9 +33,12 @@ jobs: submodules: recursive - name: Build shell: bash - env: - SOURCES_DIR: . run: /opt/build.sh all + - name: Output build size + id: output-sizes + run: | + . /opt/build.sh + .github/workflows/getSize.sh "$BUILD_DIR"/src/pinetime-app-*.out >> $GITHUB_OUTPUT # Unzip the package because Upload Artifact will zip up the files - name: Unzip DFU package run: unzip ./build/output/pinetime-mcuboot-app-dfu-*.zip -d ./build/output/pinetime-mcuboot-app-dfu @@ -87,3 +97,93 @@ jobs: with: name: infinisim-${{ github.head_ref }} path: build_lv_sim/infinisim + + get-base-ref-size: + if: github.event_name == 'pull_request' + runs-on: ubuntu-22.04 + container: + image: infinitime/infinitime-build + outputs: + text_size: ${{ steps.output-sizes.outputs.text_size }} + data_size: ${{ steps.output-sizes.outputs.data_size }} + bss_size: ${{ steps.output-sizes.outputs.bss_size }} + env: + # InfiniTime sources are downloaded to the current directory. + # Override SOURCES_DIR in build.sh + SOURCES_DIR: . + steps: + - name: Cache sources + id: cache-sources + uses: actions/cache@v3 + with: + path: . + key: source-files-${{ github.event.pull_request.base.sha }} + + - if: ${{ steps.cache-sources.outputs.cache-hit != 'true' }} + name: Checkout source files + uses: actions/checkout@v3 + with: + ref: ${{ github.base_ref }} + submodules: recursive + + - if: ${{ steps.cache-sources.outputs.cache-hit != 'true' }} + name: Build + shell: bash + # Only pinetime-app target is needed, but post_build.sh fails + run: /opt/build.sh all + + - name: Output build size + id: output-sizes + run: | + . /opt/build.sh + .github/workflows/getSize.sh "$BUILD_DIR"/src/pinetime-app-*.out >> $GITHUB_OUTPUT + + leave-build-size-comment: + if: github.event_name == 'pull_request' + needs: [build-firmware, get-base-ref-size] + runs-on: ubuntu-latest + steps: + - name: Compare build size + id: output-sizes-diff + run: | + TEXT_SIZE=${{ needs.build-firmware.outputs.text_size }} + DATA_SIZE=${{ needs.build-firmware.outputs.data_size }} + BSS_SIZE=${{ needs.build-firmware.outputs.bss_size }} + + echo "text_size=$TEXT_SIZE" >> $GITHUB_OUTPUT + echo "data_size=$DATA_SIZE" >> $GITHUB_OUTPUT + echo "bss_size=$BSS_SIZE" >> $GITHUB_OUTPUT + + TEXT_SIZE_BASE=${{ needs.get-base-ref-size.outputs.text_size }} + DATA_SIZE_BASE=${{ needs.get-base-ref-size.outputs.data_size }} + BSS_SIZE_BASE=${{ needs.get-base-ref-size.outputs.bss_size }} + + TEXT_SIZE_DIFF=$((TEXT_SIZE - TEXT_SIZE_BASE)) + DATA_SIZE_DIFF=$((DATA_SIZE - DATA_SIZE_BASE)) + BSS_SIZE_DIFF=$((BSS_SIZE - BSS_SIZE_BASE)) + + echo "text_diff=$TEXT_SIZE_DIFF" >> $GITHUB_OUTPUT + echo "data_diff=$DATA_SIZE_DIFF" >> $GITHUB_OUTPUT + echo "bss_diff=$BSS_SIZE_DIFF" >> $GITHUB_OUTPUT + + - name: Find Comment + uses: peter-evans/find-comment@v2 + id: build-size-comment + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'github-actions[bot]' + body-includes: Build size and comparison to + + - name: Create or update comment + uses: peter-evans/create-or-update-comment@v2 + with: + comment-id: ${{ steps.build-size-comment.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + body: | + Build size and comparison to ${{ github.base_ref }}: + | Section | Size | Difference | + | ------- | ---- | ---------- | + | text | ${{ needs.build-firmware.outputs.text_size }}B | ${{ steps.output-sizes-diff.outputs.text_diff }}B | + | data | ${{ needs.build-firmware.outputs.data_size }}B | ${{ steps.output-sizes-diff.outputs.data_diff }}B | + | bss | ${{ needs.build-firmware.outputs.bss_size }}B | ${{ steps.output-sizes-diff.outputs.bss_diff }}B | + edit-mode: replace |