diff --git a/.travis.yml b/.travis.yml index 1b410b0cd..81b31b417 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,26 +39,24 @@ env: - ROS_DISTRO=indigo USE_DEB=true # Checking backup compatibility with UPSTREAM_WORKSPACE - ROS_DISTRO=indigo USE_DEB=false # Checking backup compatibility with UPSTREAM_WORKSPACE - ROS_DISTRO=indigo ADDITIONAL_DEBS="ros-indigo-opencv3" VERBOSE_OUTPUT='false' - - ROS_DISTRO=indigo ADDITIONAL_DEBS="ros-hydro-opencv3" DEBUG_BASH='false' # This should fail (trying from a wrong distro). + - ROS_DISTRO=indigo ADDITIONAL_DEBS="ros-hydro-opencv3" DEBUG_BASH='false' EXPECT_EXIT_CODE=100 # This should fail (trying from a wrong distro). - ROS_DISTRO=jade APTKEY_STORE_SKS=hkp://ha.pool.sks-keyservers.vet # Passing wrong SKS URL as a break test. Should still pass. - ROS_DISTRO=jade UPSTREAM_WORKSPACE=file ROSINSTALL_FILENAME=.ci.rosinstall # Testing arbitrary file name without ROS_DISTRO suffix. As of 6/3/2016 this fails due to https://github.com/ros-industrial/industrial_core/pull/144#issuecomment-223186764 - - ROS_DISTRO=jade PRERELEASE=true PRERELEASE_REPONAME=i_do_not_exist PRERELEASE_DOWNSTREAM_DEPTH=1 # Intended to fail, to test the capability of capturing Prerelease Test failure. - - ROS_DISTRO=kinetic + - ROS_DISTRO=jade PRERELEASE=true PRERELEASE_REPONAME=i_do_not_exist EXPECT_EXIT_CODE=1 PRERELEASE_DOWNSTREAM_DEPTH=1 # Intended to fail, to test the capability of capturing Prerelease Test failure. + - ROS_DISTRO=kinetic AFTER_SCRIPT='catkin --version' - ROS_DISTRO=kinetic NOT_TEST_BUILD='true' DEBUG_BASH='false' VERBOSE_OUTPUT='false' matrix: allow_failures: - env: ROS_DISTRO=indigo NOT_TEST_BUILD='true' NOT_TEST_INSTALL='true' POST_PROCESS='I_am_supposed_to_fail' - env: ROS_DISTRO=indigo UPSTREAM_WORKSPACE=file USE_DEB=true # Expected to fail. See https://github.com/ros-industrial/industrial_ci/pull/74 - - env: ROS_DISTRO=indigo ADDITIONAL_DEBS="ros-hydro-opencv3" DEBUG_BASH='false' # This should fail (trying from a wrong distro). - - env: ROS_DISTRO=jade PRERELEASE=true PRERELEASE_REPONAME=i_do_not_exist PRERELEASE_DOWNSTREAM_DEPTH=1 # Intended to fail (as of Apr 2016), to test the capability of capturing Prerelease Test failure. - env: ROS_DISTRO=jade UPSTREAM_WORKSPACE=file ROSINSTALL_FILENAME=.ci.rosinstall before_script: - CI_DIR=. - - export BEFORE_SCRIPT="rm -fr common_travis/CATKIN_IGNORE; ${BEFORE_SCRIPT}" + - "export BEFORE_SCRIPT='echo current dir: $(pwd)'" - if [ "${USE_CATKIN_MAKE}" == "true" ] ;then sed -i 's@catkin build -i -v --limit-status-rate 0.001@catkin_make@' $CI_DIR/travis.sh; fi - if [ "${USE_CATKIN_MAKE}" == "true" ] ;then sed -i 's@catkin run_tests --no-deps --limit-status-rate 0.001@catkin_make run_tests@' $CI_DIR/travis.sh; fi - if [ "${USE_CATKIN_MAKE}" == "true" ] ;then export CATKIN_PARALLEL_JOBS="--no-color" ; fi script: - - source $CI_DIR/travis.sh + - $CI_DIR/travis.sh - if ! [ -z "$POST_PROCESS" ]; then $POST_PROCESS; fi diff --git a/README.rst b/README.rst index f4a0a9e81..287032061 100644 --- a/README.rst +++ b/README.rst @@ -110,7 +110,7 @@ With the following few short steps, you can start in your client repository usin before_config: - git clone https://github.com/ros-industrial/industrial_ci.git .ci_config script: - - source .ci_config/travis.sh + - .ci_config/travis.sh * Note that `.ci_config` is the required name of the cloned folder; it is hardcoded so you need to use this name. * Example of entire file `.travis.yml` can be found in `industrial_core/.travis.yml `_. @@ -147,12 +147,14 @@ Optional environment variables Note that some of these currently tied only to a single option, but we still leave them for the future when more options become available (e.g. ament with BUILDER). * `ADDITIONAL_DEBS` (default: not set): More DEBs to be used. List the name of DEB(s delimitted by whitespace if multiple DEBs specified). Needs to be full-qualified Ubuntu package name. E.g.: "ros-indigo-roslint ros-indigo-gazebo-ros" (without quotation). +* `AFTER_SCRIPT`: (default: not set): Used to specify shell commands that run after all source tests. * `BEFORE_SCRIPT`: (default: not set): Used to specify shell commands that run before building packages. * `BUILD_PKGS_WHITELIST` (default: not set): Packages to be built can be explicitly specified with this, in ROS package name format (i.e. using underscore. No hyphen). This is useful when your repo contains some packages that you don't want to be used upon testing. Downstream packages, if necessary, should be also specified using this. Also these packages are to be built when `NOT_TEST_INSTALL` is set. Finally, packages specified with this will be built together with those speicified using unimplmented `USE_DEB`. * `BUILDER` (default: catkin): Currently only `catkin` is implemented (and with that `catkin_tools` is used instead of `catkin_make`. See `this discussion `_). * `CATKIN_PARALLEL_JOBS` (default: -p4): Maximum number of packages to be built in parallel that is passed to underlining build tool. As of Jan 2016, this is only enabled with `catkin_tools`. See for more detail about `number of build jobs `_ and `documentation of catkin_tools `_ that this env variable is passed to internally in `catkin-tools`. * `CATKIN_PARALLEL_TEST_JOBS` (default: -p4): Maximum number of packages which could be examined in parallel during the test run. If not set it's filled by `ROS_PARALLEL_JOBS`. * `CI_PARENT_DIR` (default: .ci_config): (NOT recommended to specify) This is the folder name that is used in downstream repositories in order to point to this repo. +* `EXPECT_EXIT_CODE` (default: 0): exit code must match this value for test to succeed * `NOT_TEST_BUILD` (default: not set): If true, tests in `build` space won't be run. * `NOT_TEST_INSTALL` (default: not set): If true, tests in `install` space won't be run. * `PRERELEASE` (default: false): If `true`, run `Prerelease Test on docker that emulates ROS buildfarm `_. The usage of Prerelease Test feature is `explained more in this section `_. @@ -187,8 +189,8 @@ Sometimes CI config stored in `industrial_ci` repo may not be sufficient for you :: script: - - source .ci_config/travis.sh - - source ./travis.sh + - .ci_config/travis.sh + - ./travis.sh 2. Create `travis.sh` file and define the checks you wish to add. NOTE: this `.sh` file you add here is a normal shell script, so this shouldn't be written in `travis CI` grammar. @@ -220,8 +222,8 @@ This standard `git submodule` command: :: script: - - source .ci_config/travis.sh - #- source ./travis.sh # Optional. Explained later + - .ci_config/travis.sh + #- ./travis.sh # Optional. Explained later Also, the example of entire file `.travis.yml` can be found in `industrial_core/.travis.yml `_. @@ -287,16 +289,27 @@ You may want to add custom steps prior to the setup defined in `./travis.sh <./t * You want to run `ros_lint` (`thi discussion `_ may be of your interest). -In this case, add `source`d scripts before `travis.sh` gets called (see below for an example). +In this case, add scripts before `travis.sh` gets called (see below for an example). :: script: - - source ./your_custom_PREprocess.sh - - source .ci_config/travis.sh - - source ./your_custom_POSTprocess.sh + - ./your_custom_PREprocess.sh + - .ci_config/travis.sh + - ./your_custom_POSTprocess.sh -In the above case, in both `.ci_config/travis.sh` and `your_custom_POSTprocess.sh` the environment is kept from previous script(s), so whatever is done in previous scripts remains. +Please note: the environment is NOT kept between script(s). + +If code needs to be executed in `travis.sh` context, `BEFORE_SCRIPT` and `AFTER_SCRIPT` can be used: + +:: + + env: + global: + - BEFORE_SCRIPT:'./your_custom_PREprocess.sh' + - AFTER_SCRIPT:'./your_custom_POSTprocess.sh' + script: + - .ci_config/travis.sh (Optional) Build depended packages from source ---------------------------------------------- diff --git a/industrial_ci/ci_main.sh b/industrial_ci/ci_main.sh index a31213505..8f07ec339 100755 --- a/industrial_ci/ci_main.sh +++ b/industrial_ci/ci_main.sh @@ -52,8 +52,7 @@ export HIT_ENDOFSCRIPT=false source ${ICI_PKG_PATH}/util.sh -trap error ERR -trap success SIGTERM # So that this script won't terminate without verifying that all necessary steps are done. +trap ici_exit EXIT # install industrial_ci exit handler # Start prerelease, and once it finishs then finish this script too. if [ "$PRERELEASE" == true ]; then @@ -63,8 +62,13 @@ else source ${ICI_PKG_PATH}/source_tests.sh fi +ici_time_start after_script + + cd $TARGET_REPO_PATH + if [ "${AFTER_SCRIPT// }" != "" ]; then sh -e -c "${AFTER_SCRIPT}"; fi + +ici_time_end # after_script + cd $TARGET_REPO_PATH # cd back to the repository's home directory with travis -pwd -if [ "$DEBUG_BASH" ] && [ "$DEBUG_BASH" == true ]; then set +x; fi # disable command printing at end of script, TODO: factor out into function -# exit with code 0 +ici_exit 0 diff --git a/industrial_ci/docker.env b/industrial_ci/docker.env index 88b0461c1..042cf3562 100644 --- a/industrial_ci/docker.env +++ b/industrial_ci/docker.env @@ -1,4 +1,5 @@ ADDITIONAL_DEBS +AFTER_SCRIPT APTKEY_STORE_HTTPS APTKEY_STORE_SKS BEFORE_SCRIPT @@ -9,6 +10,7 @@ CATKIN_PARALLEL_JOBS CATKIN_PARALLEL_TEST_JOBS CATKIN_TEST_RESULTS_CMD DEBUG_BASH +EXPECT_EXIT_CODE HASHKEY_SKS HAVE_MONGO_DB NOT_TEST_BUILD diff --git a/industrial_ci/ros_pre-release.sh b/industrial_ci/ros_pre-release.sh index 2a58ac5a9..9cd601a46 100755 --- a/industrial_ci/ros_pre-release.sh +++ b/industrial_ci/ros_pre-release.sh @@ -53,9 +53,6 @@ case "$ROS_DISTRO" in esac if [ ! "$PRERELEASE_OS_CODENAME" ]; then PRERELEASE_OS_CODENAME=$os_code_name; fi -# File-global vars and -RESULT_PRERELEASE=-1 - function setup_environment() { # ROS Buildfarm for prerelease http://wiki.ros.org/regression_tests#How_do_I_setup_my_system_to_run_a_prerelease.3F sudo -E sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' @@ -86,11 +83,10 @@ function run_ros_prerelease() { ici_time_end # run_prerelease ici_time_start show_testresult - catkin_test_results --verbose && { echo 'ROS Prerelease Test went successful.'; RESULT_PRERELEASE=0; } || { RESULT_PRERELEASE=1; error; } + catkin_test_results --verbose || error 'ROS Prerelease Test failed' + echo 'ROS Prerelease Test went successful.' ici_time_end # show_testresult cd $TRAVIS_BUILD_DIR # cd back to the repository's home directory with travis pwd - - return $RESULT_PRERELEASE } diff --git a/industrial_ci/source_tests.sh b/industrial_ci/source_tests.sh index 27cbbad7c..042ab71e9 100755 --- a/industrial_ci/source_tests.sh +++ b/industrial_ci/source_tests.sh @@ -57,6 +57,7 @@ if [[ "$ROS_DISTRO" == "kinetic" ]] && ! [ "$IN_DOCKER" ]; then /bin/bash -c "cd $docker_ici_pkg_path; source ./ci_main.sh;" docker cp ~/.ssh run-industrial-ci:/root/ # pass SSH settings to container docker start -a run-industrial-ci + unset AFTER_SCRIPT # do not run AFTER_SCRIPT again return fi @@ -64,9 +65,6 @@ ici_time_start init_ici_environment # Define more env vars BUILDER=catkin ROSWS=wstool -# For compatibilility with hydro catkin, which has no --verbose flag -CATKIN_TEST_RESULTS_CMD="catkin_test_results" -if [ catkin_test_results --verbose 1>/dev/null 2>/dev/null; then CATKIN_TEST_RESULTS_CMD="catkin_test_results --verbose"; fi if [ ! "$CATKIN_PARALLEL_JOBS" ]; then export CATKIN_PARALLEL_JOBS="-p4"; fi if [ ! "$CATKIN_PARALLEL_TEST_JOBS" ]; then export CATKIN_PARALLEL_TEST_JOBS="$CATKIN_PARALLEL_JOBS"; fi @@ -96,20 +94,26 @@ ici_time_start setup_ros echo "Testing branch $TRAVIS_BRANCH of $TARGET_REPO_NAME" # $TARGET_REPO_NAME is the repo where this job is triggered from, and the variable is expected to be passed externally (industrial_ci/travis.sh should be taking care of it) # Set apt repo +lsb_release -a sudo -E sh -c 'echo "deb $ROS_REPOSITORY_PATH `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list' # Common ROS install preparation # apt key acquisition. Since keyserver may often become accessible, backup method is added. -sudo apt-key adv --keyserver $APTKEY_STORE_SKS --recv-key $HASHKEY_SKS || ((echo 'Fetching apt key from SKS keyserver somehow failed. Trying to get one from alternative.\n'; wget $APTKEY_STORE_HTTPS -O - | sudo apt-key add -) || (echo 'Fetching apt key by an alternative method failed too. Exiting since ROS cannot be installed.'; error)) -lsb_release -a -sudo apt-get -qq update || (echo "ERROR: apt server not responding. This is a rare situation, and usually just waiting for a while clears this. See https://github.com/ros-industrial/industrial_ci/pull/56 for more of the discussion"; error) +sudo apt-key adv --keyserver $APTKEY_STORE_SKS --recv-key $HASHKEY_SKS \ + || { echo 'Fetching apt key from SKS keyserver somehow failed. Trying to get one from alternative.\n'; wget $APTKEY_STORE_HTTPS -O - | sudo apt-key add -; } \ + || error 'Fetching apt key by an alternative method failed too. Exiting since ROS cannot be installed.' + +sudo apt-get -qq update || error "ERROR: apt server not responding. This is a rare situation, and usually just waiting for a while clears this. See https://github.com/ros-industrial/industrial_ci/pull/56 for more of the discussion" + sudo apt-get -qq install -y python-catkin-tools python-rosdep python-wstool ros-$ROS_DISTRO-rosbash ros-$ROS_DISTRO-rospack # If more DEBs needed during preparation, define ADDITIONAL_DEBS variable where you list the name of DEB(S, delimitted by whitespace) if [ "$ADDITIONAL_DEBS" ]; then - sudo apt-get install -q -qq -y $ADDITIONAL_DEBS - if [[ $? > 0 ]]; then - echo "One or more additional deb installation is failed. Exiting."; error - fi + sudo apt-get install -q -qq -y $ADDITIONAL_DEBS || error "One or more additional deb installation is failed. Exiting." fi + +# For compatibilility with hydro catkin, which has no --verbose flag +CATKIN_TEST_RESULTS_CMD="catkin_test_results" +if catkin_test_results --verbose 1>/dev/null 2>/dev/null; then CATKIN_TEST_RESULTS_CMD="catkin_test_results --verbose"; fi + # MongoDB hack - I don't fully understand this but its for moveit_warehouse dpkg -s mongodb || echo "ok"; export HAVE_MONGO_DB=$? if [ $HAVE_MONGO_DB == 0 ]; then @@ -153,8 +157,9 @@ ici_time_start setup_rosws ## BEGIN: travis' install: # Use this to install any prerequisites or dependencies necessary to run your build ## # Create workspace -mkdir -p ~/ros/ws_$TARGET_REPO_NAME/src -cd ~/ros/ws_$TARGET_REPO_NAME/src +CATKIN_WORKSPACE=~/catkin_ws +mkdir -p $CATKIN_WORKSPACE/src +cd $CATKIN_WORKSPACE/src case "$UPSTREAM_WORKSPACE" in debian) echo "Obtain deb binary for upstream packages." @@ -187,8 +192,7 @@ ln -s $TARGET_REPO_PATH . if [ "${USE_MOCKUP// }" != "" ]; then if [ ! -d "$TARGET_REPO_PATH/$USE_MOCKUP" ]; then - echo "mockup directory '$USE_MOCKUP' does not exist" - error + error "mockup directory '$USE_MOCKUP' does not exist" fi ln -s "$TARGET_REPO_PATH/$USE_MOCKUP" . fi @@ -208,24 +212,28 @@ ici_time_start before_script ## BEGIN: travis' before_script: # Use this to prepare your build for testing e.g. copy database configurations, environment variables, etc. source /opt/ros/$ROS_DISTRO/setup.bash # re-source setup.bash for setting environmet vairable for package installed via rosdep -if [ "${BEFORE_SCRIPT// }" != "" ]; then sh -c "${BEFORE_SCRIPT}"; fi + +# execute BEFORE_SCRIPT in repository, exit on errors +cd $TARGET_REPO_PATH +if [ "${BEFORE_SCRIPT// }" != "" ]; then sh -e -c "${BEFORE_SCRIPT}"; fi ici_time_end # before_script ici_time_start rosdep_install -sudo rosdep install -q --from-paths . --ignore-src --rosdistro $ROS_DISTRO -y +sudo rosdep install -q --from-paths $CATKIN_WORKSPACE --ignore-src --rosdistro $ROS_DISTRO -y ici_time_end # rosdep_install ici_time_start wstool_info $ROSWS --version -$ROSWS info -t . -cd ../ +$ROSWS info -t $CATKIN_WORKSPACE/src ici_time_end # wstool_info ici_time_start catkin_build +cd $CATKIN_WORKSPACE + ## BEGIN: travis' script: # All commands must exit with code 0 on success. Anything else is considered failure. source /opt/ros/$ROS_DISTRO/setup.bash # re-source setup.bash for setting environmet vairable for package installed via rosdep # for catkin @@ -296,7 +304,7 @@ if [ "$NOT_TEST_INSTALL" != "true" ]; then fi -ici_time_start after_script +ici_time_start test_results ## BEGIN: travis' after_script PATH=/usr/local/bin:$PATH # for installed catkin_test_results @@ -304,7 +312,7 @@ PYTHONPATH=/usr/local/lib/python2.7/dist-packages:$PYTHONPATH if [ "${ROS_LOG_DIR// }" == "" ]; then export ROS_LOG_DIR=~/.ros/test_results; fi # http://wiki.ros.org/ROS/EnvironmentVariables#ROS_LOG_DIR if [ "$BUILDER" == catkin -a -e $ROS_LOG_DIR ]; then $CATKIN_TEST_RESULTS_CMD --all $ROS_LOG_DIR || error; fi -if [ "$BUILDER" == catkin -a -e ~/ros/ws_$TARGET_REPO_NAME/build/ ]; then $CATKIN_TEST_RESULTS_CMD --all ~/ros/ws_$TARGET_REPO_NAME/build/ || error; fi +if [ "$BUILDER" == catkin -a -e $CATKIN_WORKSPACE/build/ ]; then $CATKIN_TEST_RESULTS_CMD --all $CATKIN_WORKSPACE/build/ || error; fi if [ "$BUILDER" == catkin -a -e ~/.ros/test_results/ ]; then $CATKIN_TEST_RESULTS_CMD --all ~/.ros/test_results/ || error; fi -ici_time_end # after_script +ici_time_end # test_results diff --git a/industrial_ci/util.sh b/industrial_ci/util.sh index b40fdbaa4..289149f3e 100644 --- a/industrial_ci/util.sh +++ b/industrial_ci/util.sh @@ -34,6 +34,21 @@ ## util.sh ## This is a script where the functions commonly used within the industrial_ci repo are defined. +####################################### +# Starts a timer section on Travis CI +# +# Globals: +# DEBUG_BASH (read-only) +# TRAVIS_FOLD_NAME (write-only) +# TRAVIS_TIME_ID (write-only) +# TRAVIS_START_TIME (write-only) +# Arguments: +# color_wrap (default: 32): Color code for the section delimitter text. +# exit_code (default: $?): Exit code for display +# Returns: +# (None) +####################################### + function ici_time_start { if [ "$DEBUG_BASH" ] && [ "$DEBUG_BASH" == true ]; then set +x; fi TRAVIS_START_TIME=$(date +%s%N) @@ -48,96 +63,84 @@ function ici_time_start { # Wraps up the timer section on Travis CI (that's started mostly by ici_time_start function). # # Globals: -# (None) +# DEBUG_BASH (read-only) +# TRAVIS_FOLD_NAME (from ici_time_start, read-write) +# TRAVIS_TIME_ID (from ici_time_start, read-only) +# TRAVIS_START_TIME (from ici_time_start, read-only) # Arguments: # color_wrap (default: 32): Color code for the section delimitter text. +# exit_code (default: $?): Exit code for display # Returns: # (None) ####################################### function ici_time_end { if [ "$DEBUG_BASH" ] && [ "$DEBUG_BASH" == true ]; then set +x; fi - color_wrap=${2:-32} + local color_wrap=${1:-32} + local exit_code=${2:-$?} if [ -z $TRAVIS_START_TIME ]; then echo '[ici_time_end] var TRAVIS_START_TIME is not set. You need to call `ici_time_start` in advance. Rerutning.'; return; fi TRAVIS_END_TIME=$(date +%s%N) TIME_ELAPSED_SECONDS=$(( ($TRAVIS_END_TIME - $TRAVIS_START_TIME)/1000000000 )) echo -e "ici_time:end:$TRAVIS_TIME_ID:start=$TRAVIS_START_TIME,finish=$TRAVIS_END_TIME,duration=$(($TRAVIS_END_TIME - $TRAVIS_START_TIME))\e[0K" echo -e "ici_fold:end:$TRAVIS_FOLD_NAME\e[${color_wrap}m<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\e[0m" - echo -e "\e[0K\e[${color_wrap}mFunction $TRAVIS_FOLD_NAME took $(( $TIME_ELAPSED_SECONDS / 60 )) min $(( $TIME_ELAPSED_SECONDS % 60 )) sec\e[0m" + echo -e "\e[0K\e[${color_wrap}mFunction $TRAVIS_FOLD_NAME returned with code '${exit_code}' after $(( $TIME_ELAPSED_SECONDS / 60 )) min $(( $TIME_ELAPSED_SECONDS % 60 )) sec \e[0m" unset $TRAVIS_FOLD_NAME if [ "$DEBUG_BASH" ] && [ "$DEBUG_BASH" == true ]; then set -x; fi } ####################################### -# This private function can exit the shell process, as well as wrapping up the timer section on Travis CI. Internally this does: -# -# * wraps the section that is started by ici_time_start function. -# * resets signal handler for ERR to the bash default one, when `exit_code` is any error code that exits the shell. This allows subsequent signal handlers for ERR if any to be unaffected by any handlers defined beforehand. -# * exits the process if non -1 value is passed to `exit_code`. +# exit function with handling for EXPECT_EXIT_CODE, ends the current fold if necessary # +# Globals: +# EXPECT_EXIT_CODE (read-only) +# TRAVIS_FOLD_NAME (from ici_time_start, read-only) # Arguments: -# exit_code (default: -1): Unix signal. If -1 then the process continues without exiting. -# color_wrap (default: 32): Color code for the section delimitter text. +# exit_code (default: $?) +# Returns: +# (None) ####################################### -function _end_fold_script { - if [ "$DEBUG_BASH" ] && [ "$DEBUG_BASH" == true ]; then set +x; fi - exit_code=${1:--1} # If 1st arg is not passed, set -1. - color_wrap=${2:-32} +function ici_exit { + local exit_code=${1:-$?} # If 1st arg is not passed, set last error code. + trap - EXIT # Reset signal handler since the shell is about to exit. - if [ $exit_code -eq "1" ]; then color_wrap=31; fi # Red color - if [ -z $TRAVIS_FOLD_NAME ]; then - ici_time_end $color_wrap - else - echo "Previous Travis fold name not found. It might be either successful termination of the script, or wrong call. Skipping 'ici_time_end' anyway." + # end fold if needed + if [ -n "$TRAVIS_FOLD_NAME" ]; then + if [ $exit_code -ne "0" ]; then color_wrap=31; fi # Red color for errors + ici_time_end "$color_wrap" "$exit_code" fi - if [ $exit_code -eq "1" ]; then trap - ERR; fi # Reset signal handler since the shell is about to exit. - if [ "$DEBUG_BASH" ] && [ "$DEBUG_BASH" == true ]; then set -x; fi - if [ $exit_code -ne "-1" ]; then exit $exit_code; fi -} + if [ "$exit_code" == "${EXPECT_EXIT_CODE:-0}" ]; then + exit 0 + elif [ "$exit_code" == "0" ]; then # 0 was not expected + exit 1 + fi -####################################### -# This calls "exit 1", along with the following. When your script on Travis CI already uses other functions from this file (util.sh), using this is recommended over calling directly "exit 1". -# -# * wraps the section that is started by ici_time_start function with the echo color red (31). -# * reset signal handler for ERR to the bash default one. Subsequent signal handlers for ERR if any are unaffected by any handlers defined prior. -# -# Globals: -# (None) -# Arguments: -# (None) -# Returns: -# (None) -####################################### -function error { - _end_fold_script 1 31 + exit $exit_code } ####################################### -# Similar to `error` function, this lets you "exit 0" and take care of other things as following, when your script on Travis CI already uses other functions from this file (util.sh). +# Print an error message and calls "exit" # -# * wraps the section that is started by ici_time_start function with the echo color green. -# * reset signal handler for ERR to the bash default one. Subsequent signal handlers for ERR if any are unaffected by any handlers defined prior. +# * Wraps the section that is started by ici_time_start function with the echo color red (31). +# * exit_code is taken from second argument or from the previous comman. +# * If the final exit_code is 0, this function will exit 1 instead to enforce a test failure # # Globals: # (None) # Arguments: -# _exit_code (default: 0): Unix signal. If -1 passed then the process continues without exiting. +# message (optional) +# exit_code (default: $?) # Returns: # (None) ####################################### -function success { - _FUNC_MSG_PREFIX="[fuction success]" - _exit_code=${1:-0} # If 1st arg is not passed, set 0. - HIT_ENDOFSCRIPT=${HIT_ENDOFSCRIPT:-false} - if [ $HIT_ENDOFSCRIPT = false ]; then - if [ $_exit_code -eq 0 ]; then - echo "${_FUNC_MSG_PREFIX} Arg HIT_ENDOFSCRIPT must be true when this function exit with 0. Turn _exit_code to 1."; _exit_code=1; - else - echo "${_FUNC_MSG_PREFIX} _exit_code cannot be 0 for this func. Make sure you are calling this in a right context."; _exit_code=1; - fi +function error { + local exit_code=${2:-$?} # + if [ -n $1 ]; then + echo "\e[31m$1\e0m" # print error in red + fi + if [ "$exit_code" == "0" ]; then # 0 is not error + exit 1 fi - if [ $_exit_code -ne "-1" ] && [ $_exit_code -ne "0" ]; then echo "${_FUNC_MSG_PREFIX} error: arg _exit_code must be either empty, -1 or 0. Returning."; return; fi - _end_fold_script $_exit_code + ici_exit $exit_code } diff --git a/travis.sh b/travis.sh index 9d9a4753a..ea42926cd 100755 --- a/travis.sh +++ b/travis.sh @@ -37,7 +37,12 @@ DIR_THIS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" export TARGET_REPO_PATH=$(pwd) export TARGET_REPO_NAME=${PWD##*/} -# Call the "core" executable of this repo to run all kinds of tests. -cd $DIR_THIS/industrial_ci -source ./ci_main.sh -cd $DIR_THIS # Moves back to the repository root dir. +function main { + # Call the "core" executable of this repo to run all kinds of tests. + cd $DIR_THIS/industrial_ci + local ret=0 + ./ci_main.sh || ret=$? + cd $TARGET_REPO_PATH # Moves back to the repository root dir. + return $ret +} +main # result of main function if resul of script \ No newline at end of file