Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More fixes for error handling #103

Merged
merged 16 commits into from
Jan 18, 2017
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 23 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/ros-industrial/industrial_core/blob/indigo-devel/.travis.yml>`_.
Expand Down Expand Up @@ -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 <https://github.com/ros-industrial/industrial_ci/issues/3>`_).
* `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 <http://catkin-tools.readthedocs.org/en/latest/verbs/catkin_build.html#controlling-the-number-of-build-jobs>`_ and `documentation of catkin_tools <https://catkin-tools.readthedocs.org/en/latest/verbs/catkin_build.html#full-command-line-interface>`_ 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 <http://wiki.ros.org/bloom/Tutorials/PrereleaseTest/>`_. The usage of Prerelease Test feature is `explained more in this section <https://github.com/ros-industrial/industrial_ci/blob/add/dockerbased_prerelease/README.rst#optional-run-ros-prerelease-test>`_.
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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 <https://github.com/ros-industrial/industrial_core/.travis.yml>`_.

Expand Down Expand Up @@ -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 <https://github.com/ros-industrial/industrial_ci/issues/58#issuecomment-223601916>`_ 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
----------------------------------------------
Expand Down
14 changes: 9 additions & 5 deletions industrial_ci/ci_main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 2 additions & 0 deletions industrial_ci/docker.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ADDITIONAL_DEBS
AFTER_SCRIPT
APTKEY_STORE_HTTPS
APTKEY_STORE_SKS
BEFORE_SCRIPT
Expand All @@ -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
Expand Down
8 changes: 2 additions & 6 deletions industrial_ci/ros_pre-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
}
50 changes: 29 additions & 21 deletions industrial_ci/source_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,14 @@ 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

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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -296,15 +304,15 @@ 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
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
Loading