Skip to content

Commit 787c424

Browse files
projectgusdpgeorge
authored andcommitted
tools/ci.sh: Fix reference commit for code size comparison.
Previously the code size comparison was between the merge base (i.e. where the PR branched), and the generated merge commit into master. If the PR branch was older than current master, this meant the size comparison could incorrectly include changes already merged on master but missing from the PR branch. This commit changes it to compare the generated merge commit against current master, i.e. the size impact if this PR was to be merged. This commit also disables running the code size check on "push", it now only runs on pull_request events. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <[email protected]>
1 parent 9591b0a commit 787c424

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

.github/workflows/code_size.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
name: Check code size
22

33
on:
4-
push:
54
pull_request:
65
paths:
76
- '.github/workflows/*.yml'

tools/ci.sh

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,37 @@ function ci_code_size_build {
6969
PORTS_TO_CHECK=bmusxpdv
7070
SUBMODULES="lib/asf4 lib/berkeley-db-1.xx lib/btstack lib/cyw43-driver lib/lwip lib/mbedtls lib/micropython-lib lib/nxp_driver lib/pico-sdk lib/stm32lib lib/tinyusb"
7171

72-
# starts off at either the ref/pull/N/merge FETCH_HEAD, or the current branch HEAD
73-
git checkout -b pull_request # save the current location
74-
git remote add upstream https://github.com/micropython/micropython.git
75-
git fetch --depth=100 upstream master
76-
# If the common ancestor commit hasn't been found, fetch more.
77-
git merge-base upstream/master HEAD || git fetch --unshallow upstream master
72+
# Default GitHub pull request sets HEAD to a generated merge commit
73+
# between PR branch (HEAD^2) and base branch (i.e. master) (HEAD^1).
74+
#
75+
# We want to compare this generated commit with the base branch, to see what
76+
# the code size impact would be if we merged this PR.
77+
REFERENCE=$(git rev-parse --short HEAD^1)
78+
COMPARISON=$(git rev-parse --short HEAD)
79+
80+
echo "Comparing sizes of reference ${REFERENCE} to ${COMPARISON}..."
81+
git log --oneline $REFERENCE..$COMPARISON
82+
83+
function code_size_build_step {
84+
COMMIT=$1
85+
OUTFILE=$2
86+
IGNORE_ERRORS=$3
87+
88+
echo "Building ${COMMIT}..."
89+
git checkout --detach $COMMIT
90+
git submodule update --init $SUBMODULES
91+
git show -s
92+
tools/metrics.py clean $PORTS_TO_CHECK
93+
tools/metrics.py build $PORTS_TO_CHECK | tee $OUTFILE || $IGNORE_ERRORS
94+
}
95+
7896
# build reference, save to size0
7997
# ignore any errors with this build, in case master is failing
80-
git checkout `git merge-base --fork-point upstream/master pull_request`
81-
git submodule update --init $SUBMODULES
82-
git show -s
83-
tools/metrics.py clean $PORTS_TO_CHECK
84-
tools/metrics.py build $PORTS_TO_CHECK | tee ~/size0 || true
98+
code_size_build_step $REFERENCE ~/size0 true
8599
# build PR/branch, save to size1
86-
git checkout pull_request
87-
git submodule update --init $SUBMODULES
88-
git log upstream/master..HEAD
89-
tools/metrics.py clean $PORTS_TO_CHECK
90-
tools/metrics.py build $PORTS_TO_CHECK | tee ~/size1
100+
code_size_build_step $COMPARISON ~/size1 false
101+
102+
unset -f code_size_build_step
91103
}
92104

93105
########################################################################################

0 commit comments

Comments
 (0)