summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2025-09-03 14:47:06 -0500
committerDamien George <damien@micropython.org>2025-10-08 15:09:34 +1100
commit61988ee8fa86a3b6bf017355b4fb04238112dd35 (patch)
treea1f30515c1f3d099f1d684e109b1e5f3d03dd8e6
parent7778e78843b7e157b164b450ce9965ed4f7f3048 (diff)
tools/ci.sh: Return to old branch after code_size_build.
Signed-off-by: Jeff Epler <jepler@unpythonic.net>
-rwxr-xr-xtools/ci.sh51
1 files changed, 27 insertions, 24 deletions
diff --git a/tools/ci.sh b/tools/ci.sh
index 1e5a7e542..fe71c30c5 100755
--- a/tools/ci.sh
+++ b/tools/ci.sh
@@ -100,30 +100,33 @@ function ci_code_size_build {
echo "Comparing sizes of reference ${REFERENCE} to ${COMPARISON}..."
git log --oneline $REFERENCE..$COMPARISON
- function code_size_build_step {
- COMMIT=$1
- OUTFILE=$2
-
- echo "Building ${COMMIT}..."
- git checkout --detach $COMMIT
- git submodule update --init $SUBMODULES
- git show -s
- tools/metrics.py clean $PORTS_TO_CHECK
- # Allow errors from tools/metrics.py to propagate out of the pipe above.
- (set -o pipefail; tools/metrics.py build $PORTS_TO_CHECK | tee $OUTFILE)
- return $?
- }
-
- # build reference, save to size0
- # ignore any errors with this build, in case master is failing
- code_size_build_step $REFERENCE ~/size0
- # build PR/branch, save to size1
- code_size_build_step $COMPARISON ~/size1
- STATUS=$?
-
- unset -f code_size_build_step
-
- return $STATUS
+ OLD_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
+
+ ( # Execute in a subshell so the trap & code_size_build_step doesn't leak
+ function code_size_build_step {
+ if [ ! -z "$OLD_BRANCH" ]; then
+ trap 'git checkout "$OLD_BRANCH"' RETURN EXIT ERR
+ fi
+
+ COMMIT=$1
+ OUTFILE=$2
+
+ echo "Building ${COMMIT}..."
+ git checkout --detach $COMMIT
+ git submodule update --init $SUBMODULES
+ git show -s
+ tools/metrics.py clean "$PORTS_TO_CHECK"
+ # Allow errors from tools/metrics.py to propagate out of the pipe below.
+ set -o pipefail
+ tools/metrics.py build "$PORTS_TO_CHECK" | tee $OUTFILE
+ }
+
+ # build reference, save to size0
+ # ignore any errors with this build, in case master is failing
+ code_size_build_step $REFERENCE ~/size0
+ # build PR/branch, save to size1
+ code_size_build_step $COMPARISON ~/size1
+ )
}
function ci_code_size_report {