Skip to content

Commit 028d408

Browse files
committed
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.
1 parent 499f087 commit 028d408

File tree

2 files changed

+122
-3
lines changed

2 files changed

+122
-3
lines changed

.github/workflows/getSize.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
3+
# Requires environment variables from docker/build.sh
4+
5+
set -e
6+
7+
SIZE_BIN="$TOOLS_DIR/$GCC_ARM_PATH/bin/arm-none-eabi-size"
8+
[ ! -x "$SIZE_BIN" ] && exit 1
9+
10+
[ -z "$1" ] && exit 1
11+
SIZE_OUTPUT=$($SIZE_BIN "$1" | tail -n1)
12+
13+
TEXT_SIZE=$(echo "$SIZE_OUTPUT" | cut -f 1 |tr -d '[:blank:]')
14+
DATA_SIZE=$(echo "$SIZE_OUTPUT" | cut -f 2 |tr -d '[:blank:]')
15+
BSS_SIZE=$(echo "$SIZE_OUTPUT" | cut -f 3 |tr -d '[:blank:]')
16+
17+
echo "text_size=$TEXT_SIZE"
18+
echo "data_size=$DATA_SIZE"
19+
echo "bss_size=$BSS_SIZE"

.github/workflows/main.yml

Lines changed: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,32 @@ on:
1313
- 'doc/**'
1414
- '**.md'
1515

16-
1716
jobs:
1817
build-firmware:
1918
runs-on: ubuntu-latest
2019
container:
2120
image: infinitime/infinitime-build
21+
outputs:
22+
text_size: ${{ steps.output-sizes.outputs.text_size }}
23+
data_size: ${{ steps.output-sizes.outputs.data_size }}
24+
bss_size: ${{ steps.output-sizes.outputs.bss_size }}
25+
env:
26+
# InfiniTime sources are downloaded to the current directory.
27+
# Override SOURCES_DIR in build.sh
28+
SOURCES_DIR: .
2229
steps:
2330
- name: Checkout source files
2431
uses: actions/checkout@v3
2532
with:
2633
submodules: recursive
2734
- name: Build
2835
shell: bash
29-
env:
30-
SOURCES_DIR: .
3136
run: /opt/build.sh all
37+
- name: Output build size
38+
id: output-sizes
39+
run: |
40+
. /opt/build.sh
41+
.github/workflows/getSize.sh "$BUILD_DIR"/src/pinetime-app-*.out >> $GITHUB_OUTPUT
3242
# Unzip the package because Upload Artifact will zip up the files
3343
- name: Unzip DFU package
3444
run: unzip ./build/output/pinetime-mcuboot-app-dfu-*.zip -d ./build/output/pinetime-mcuboot-app-dfu
@@ -87,3 +97,93 @@ jobs:
8797
with:
8898
name: infinisim-${{ github.head_ref }}
8999
path: build_lv_sim/infinisim
100+
101+
get-base-ref-size:
102+
if: github.event_name == 'pull_request'
103+
runs-on: ubuntu-22.04
104+
container:
105+
image: infinitime/infinitime-build
106+
outputs:
107+
text_size: ${{ steps.output-sizes.outputs.text_size }}
108+
data_size: ${{ steps.output-sizes.outputs.data_size }}
109+
bss_size: ${{ steps.output-sizes.outputs.bss_size }}
110+
env:
111+
# InfiniTime sources are downloaded to the current directory.
112+
# Override SOURCES_DIR in build.sh
113+
SOURCES_DIR: .
114+
steps:
115+
- name: Cache sources
116+
id: cache-sources
117+
uses: actions/cache@v3
118+
with:
119+
path: .
120+
key: source-files-${{ github.event.pull_request.base.sha }}
121+
122+
- if: ${{ steps.cache-sources.outputs.cache-hit != 'true' }}
123+
name: Checkout source files
124+
uses: actions/checkout@v3
125+
with:
126+
ref: ${{ github.base_ref }}
127+
submodules: recursive
128+
129+
- if: ${{ steps.cache-sources.outputs.cache-hit != 'true' }}
130+
name: Build
131+
shell: bash
132+
# Only pinetime-app target is needed, but post_build.sh fails
133+
run: /opt/build.sh all
134+
135+
- name: Output build size
136+
id: output-sizes
137+
run: |
138+
. /opt/build.sh
139+
.github/workflows/getSize.sh "$BUILD_DIR"/src/pinetime-app-*.out >> $GITHUB_OUTPUT
140+
141+
leave-build-size-comment:
142+
if: github.event_name == 'pull_request'
143+
needs: [build-firmware, get-base-ref-size]
144+
runs-on: ubuntu-latest
145+
steps:
146+
- name: Compare build size
147+
id: output-sizes-diff
148+
run: |
149+
TEXT_SIZE=${{ needs.build-firmware.outputs.text_size }}
150+
DATA_SIZE=${{ needs.build-firmware.outputs.data_size }}
151+
BSS_SIZE=${{ needs.build-firmware.outputs.bss_size }}
152+
153+
echo "text_size=$TEXT_SIZE" >> $GITHUB_OUTPUT
154+
echo "data_size=$DATA_SIZE" >> $GITHUB_OUTPUT
155+
echo "bss_size=$BSS_SIZE" >> $GITHUB_OUTPUT
156+
157+
TEXT_SIZE_BASE=${{ needs.get-base-ref-size.outputs.text_size }}
158+
DATA_SIZE_BASE=${{ needs.get-base-ref-size.outputs.data_size }}
159+
BSS_SIZE_BASE=${{ needs.get-base-ref-size.outputs.bss_size }}
160+
161+
TEXT_SIZE_DIFF=$((TEXT_SIZE - TEXT_SIZE_BASE))
162+
DATA_SIZE_DIFF=$((DATA_SIZE - DATA_SIZE_BASE))
163+
BSS_SIZE_DIFF=$((BSS_SIZE - BSS_SIZE_BASE))
164+
165+
echo "text_diff=$TEXT_SIZE_DIFF" >> $GITHUB_OUTPUT
166+
echo "data_diff=$DATA_SIZE_DIFF" >> $GITHUB_OUTPUT
167+
echo "bss_diff=$BSS_SIZE_DIFF" >> $GITHUB_OUTPUT
168+
169+
- name: Find Comment
170+
uses: peter-evans/find-comment@v2
171+
id: build-size-comment
172+
with:
173+
issue-number: ${{ github.event.pull_request.number }}
174+
comment-author: 'github-actions[bot]'
175+
body-includes: Build size and comparison to
176+
177+
- name: Create or update comment
178+
uses: peter-evans/create-or-update-comment@v2
179+
with:
180+
comment-id: ${{ steps.build-size-comment.outputs.comment-id }}
181+
issue-number: ${{ github.event.pull_request.number }}
182+
body: |
183+
Build size and comparison to ${{ github.base_ref }}:
184+
| Section | Size | Difference |
185+
| ------- | ---- | ---------- |
186+
| text | ${{ needs.build-firmware.outputs.text_size }}B | ${{ steps.output-sizes-diff.outputs.text_diff }}B |
187+
| data | ${{ needs.build-firmware.outputs.data_size }}B | ${{ steps.output-sizes-diff.outputs.data_diff }}B |
188+
| bss | ${{ needs.build-firmware.outputs.bss_size }}B | ${{ steps.output-sizes-diff.outputs.bss_diff }}B |
189+
edit-mode: replace

0 commit comments

Comments
 (0)