Make ci script more understandable and robust, hopefully

This commit is contained in:
Brandon W Maister 2019-09-20 11:15:57 -04:00
parent ffcd0f9c19
commit 9a3e48931b
1 changed files with 60 additions and 45 deletions

View File

@ -2,6 +2,12 @@
# This is the script that's executed by travis, you can run it yourself to run # This is the script that's executed by travis, you can run it yourself to run
# the exact same suite # the exact same suite
#
# When running it locally the most important thing to set is the CHANNEL env
# var, otherwise it will run tests against every version of rust that it knows
# about (nightly, beta, stable, 1.13.0):
#
# $ CHANNEL=stable ./ci/travis.sh
set -e set -e
@ -9,8 +15,8 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
main() { main() {
if [[ -n $CHANNEL ]] ; then if [[ -n "$CHANNEL" ]] ; then
if [[ $CHANNEL == 1.13.0 ]]; then if [[ "$CHANNEL" == 1.13.0 ]]; then
banner "Building $CHANNEL" banner "Building $CHANNEL"
build_only build_only
else else
@ -22,7 +28,7 @@ main() {
else else
CHANNEL=nightly CHANNEL=nightly
matching_banner "Test $CHANNEL" matching_banner "Test $CHANNEL"
if [ "x${CLIPPY}" = xy ] ; then if [[ "${CLIPPY}" = y ]] ; then
run_clippy run_clippy
else else
build_and_test build_and_test
@ -43,44 +49,6 @@ main() {
fi fi
} }
channel() {
channel_run cargo "$@"
}
channel_run() {
if channel_matches ; then
pwd
local the_cmd="$ $*"
underline "$the_cmd"
"$@"
else
pwd
local cmd="$1"
shift
if [[ $cmd == cargo || $cmd == rustc ]] ; then
underline "$ $cmd +${CHANNEL} $*"
"$cmd" "+${CHANNEL}" "$@"
else
underline "$ $cmd $*"
"$cmd" "$@"
fi
fi
}
channel_matches() {
if [ -n "${TRAVIS}" ]; then
if [ "${TRAVIS_RUST_VERSION}" = "${CHANNEL}" ]; then
return 0
fi
elif [ -n "${APPVEYOR}" ]; then
if [ "${APPVEYOR_RUST_CHANNEL}" = "${CHANNEL}" ]; then
return 0
fi
else
return 1
fi
}
build_and_test() { build_and_test() {
# interleave building and testing in hope that it saves time # interleave building and testing in hope that it saves time
# also vary the local time zone to (hopefully) catch tz-dependent bugs # also vary the local time zone to (hopefully) catch tz-dependent bugs
@ -172,6 +140,8 @@ check_readme() {
(set -x; git diff --exit-code -- README.md) ; echo $? (set -x; git diff --exit-code -- README.md) ; echo $?
} }
# script helpers
banner() { banner() {
echo "======================================================================" echo "======================================================================"
echo "$*" echo "$*"
@ -184,13 +154,58 @@ underline() {
} }
matching_banner() { matching_banner() {
if channel_matches || [[ -z $TRAVIS && -z $APPVEYOR ]] ; then if channel_matches || ! is_ci ; then
banner "$*" banner "$*"
echo_versions
fi fi
} }
echo_versions() {
channel_run rustc --version channel_run rustc --version
channel_run cargo --version channel_run cargo --version
node --version node --version
}
channel() {
channel_run cargo "$@"
}
channel_run() {
if channel_matches ; then
pwd
local the_cmd="$ $*"
underline "$the_cmd"
"$@"
elif ! is_ci ; then
pwd
local cmd="$1"
shift
if [[ $cmd == cargo || $cmd == rustc ]] ; then
underline "$ $cmd +${CHANNEL} $*"
"$cmd" "+${CHANNEL}" "$@"
else
underline "$ $cmd $*"
"$cmd" "$@"
fi
fi
}
channel_matches() {
if is_ci ; then
if [[ "${TRAVIS_RUST_VERSION}" = "${CHANNEL}"
|| "${APPVEYOR_RUST_CHANNEL}" = "${CHANNEL}" ]] ; then
return 0
fi
fi
return 1
}
is_ci() {
if [[ -n "$TRAVIS" || -n "$APPVEYOR" ]] ; then
return 0
else
return 1
fi
}
main main