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 <angus@redyak.com.au>
This commit is contained in:
Angus Gratton 2024-10-31 10:47:47 +11:00 committed by Damien George
parent 9591b0a53c
commit 787c424cfc
2 changed files with 28 additions and 17 deletions

View file

@ -1,7 +1,6 @@
name: Check code size name: Check code size
on: on:
push:
pull_request: pull_request:
paths: paths:
- '.github/workflows/*.yml' - '.github/workflows/*.yml'

View file

@ -69,25 +69,37 @@ function ci_code_size_build {
PORTS_TO_CHECK=bmusxpdv PORTS_TO_CHECK=bmusxpdv
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" 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"
# starts off at either the ref/pull/N/merge FETCH_HEAD, or the current branch HEAD # Default GitHub pull request sets HEAD to a generated merge commit
git checkout -b pull_request # save the current location # between PR branch (HEAD^2) and base branch (i.e. master) (HEAD^1).
git remote add upstream https://github.com/micropython/micropython.git #
git fetch --depth=100 upstream master # We want to compare this generated commit with the base branch, to see what
# If the common ancestor commit hasn't been found, fetch more. # the code size impact would be if we merged this PR.
git merge-base upstream/master HEAD || git fetch --unshallow upstream master REFERENCE=$(git rev-parse --short HEAD^1)
COMPARISON=$(git rev-parse --short HEAD)
echo "Comparing sizes of reference ${REFERENCE} to ${COMPARISON}..."
git log --oneline $REFERENCE..$COMPARISON
function code_size_build_step {
COMMIT=$1
OUTFILE=$2
IGNORE_ERRORS=$3
echo "Building ${COMMIT}..."
git checkout --detach $COMMIT
git submodule update --init $SUBMODULES
git show -s
tools/metrics.py clean $PORTS_TO_CHECK
tools/metrics.py build $PORTS_TO_CHECK | tee $OUTFILE || $IGNORE_ERRORS
}
# build reference, save to size0 # build reference, save to size0
# ignore any errors with this build, in case master is failing # ignore any errors with this build, in case master is failing
git checkout `git merge-base --fork-point upstream/master pull_request` code_size_build_step $REFERENCE ~/size0 true
git submodule update --init $SUBMODULES
git show -s
tools/metrics.py clean $PORTS_TO_CHECK
tools/metrics.py build $PORTS_TO_CHECK | tee ~/size0 || true
# build PR/branch, save to size1 # build PR/branch, save to size1
git checkout pull_request code_size_build_step $COMPARISON ~/size1 false
git submodule update --init $SUBMODULES
git log upstream/master..HEAD unset -f code_size_build_step
tools/metrics.py clean $PORTS_TO_CHECK
tools/metrics.py build $PORTS_TO_CHECK | tee ~/size1
} }
######################################################################################## ########################################################################################