Skip to content

Commit b399d72

Browse files
committed
ci: Make script runnable as command.
This makes it easier to run a sequence of ci steps locally. A help message is also provided. Signed-off-by: Jeff Epler <jepler@gmail.com>
1 parent 3adf016 commit b399d72

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

docs/develop/gettingstarted.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,19 @@ tools
328328
examples
329329

330330
Example code for building MicroPython as a library as well as native modules.
331+
332+
Using ci.sh
333+
-----------
334+
335+
To reduce dependence on any specific CI tool, the actual build steps for Unix-based builds are in the file ``tools/ci.sh``.
336+
This can also be used as a script on developer desktops, with caveats.
337+
338+
* For most steps, An Ubuntu/Debian system similar to the one used during CI is assumed
339+
* Some specific steps assume specific Ubuntu versions and even the availability of Python 2.7
340+
* The setup steps may invoke the system package manager to install packages,
341+
download and install software from the internet, etc
342+
343+
To get a usage message including the list of commands, run ``tools/ci.sh --help``.
344+
345+
As an example, you can build and test the unix minimal port with
346+
``tools/ci.sh ci_unix_minimal_build ci_unix_minimal_run_tests``.

tools/ci.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,3 +969,60 @@ function ci_alif_ae3_build {
969969
make ${MAKEOPTS} -C ports/alif BOARD=OPENMV_AE3 MCU_CORE=M55_DUAL
970970
make ${MAKEOPTS} -C ports/alif BOARD=ALIF_ENSEMBLE MCU_CORE=M55_DUAL
971971
}
972+
973+
function _ci_help {
974+
# Note: these lines must be indented with tab characters (required by bash <<-EOF)
975+
cat <<-EOF
976+
ci.sh: Script fragments used during CI
977+
978+
When invoked as a script, runs a sequence of ci steps,
979+
stopping after the first error.
980+
981+
Usage:
982+
${BASH_SOURCE} ci_foo ci_bar
983+
984+
Commands:
985+
EOF
986+
if type -path column > /dev/null 2>&1; then
987+
grep '^function ci_' $0 | awk '{print $2}' | column
988+
else
989+
grep '^function ci_' $0 | awk '{print $2}'
990+
fi
991+
exit
992+
}
993+
994+
function _ci_main {
995+
case "$1" in
996+
(-h|-?|--help)
997+
_ci_help
998+
;;
999+
(*)
1000+
cd $(dirname "$0")/..
1001+
while [ $# -ne 0 ]; do
1002+
$1
1003+
shift
1004+
done
1005+
;;
1006+
esac
1007+
}
1008+
1009+
# https://stackoverflow.com/questions/2683279/how-to-detect-if-a-script-is-being-sourced
1010+
sourced=0
1011+
if [ -n "$ZSH_VERSION" ]; then
1012+
case $ZSH_EVAL_CONTEXT in *:file) sourced=1;; esac
1013+
elif [ -n "$KSH_VERSION" ]; then
1014+
[ "$(cd -- "$(dirname -- "$0")" && pwd -P)/$(basename -- "$0")" != "$(cd -- "$(dirname -- "${.sh.file}")" && pwd -P)/$(basename -- "${.sh.file}")" ] && sourced=1
1015+
elif [ -n "$BASH_VERSION" ]; then
1016+
(return 0 2>/dev/null) && sourced=1
1017+
else # All other shells: examine $0 for known shell binary filenames.
1018+
# Detects `sh` and `dash`; add additional shell filenames as needed.
1019+
case ${0##*/} in sh|-sh|dash|-dash) sourced=1;; esac
1020+
fi
1021+
1022+
if [ $sourced -eq 0 ]; then
1023+
# invoked as a command
1024+
if [ "$#" -eq 0 ]; then
1025+
set -- --help
1026+
fi
1027+
_ci_main "$@"
1028+
fi

0 commit comments

Comments
 (0)