diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c8c99c5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,61 @@ +# General .travis.yml file for running continuous integration on Travis-CI using +# Docker to test other Ubuntu/ROS versions that just the versions that are +# natively supported by Travis-CI. +# +# Initially based on the .travis.yml file posted by Felix Duvallet for using +# Travis-CI with any ROS package +# +# Almost completely redone by Alex Tomala and Michael Smart. +# +# NOTE: The build lifecycle on Travis.ci is something like this: +# before_install +# install +# before_script +# script +# after_success or after_failure +# after_script +# OPTIONAL before_deploy +# OPTIONAL deploy +# OPTIONAL after_deploy +# +################################################################################ + +# Use ubuntu trusty (14.04) with sudo privileges. +dist: trusty +sudo: required + +# Set build matrix and global CI env variables +env: + global: + - DOCKER_CACHE_DIR=$HOME/docker_cache + - DOCKER_CI_REL_DIR=. + matrix: + - DOCKER_DISTRO=trusty + - DOCKER_DISTRO=xenial + +################################################################################ + +# Have to pull git outside of docker as the container doesn't have an ssh key. +before_install: + - git submodule init + - git submodule -q update + +# Load the cached docker container. Otherwise, delete and rebuild it. +install: + - travis_wait 45 bash ${DOCKER_CI_REL_DIR}/docker-setup-ci.bash + +# Execute the CI script using the docker container +# +# docker-run-ci.sh takes one argument: +# {1}: The relative path to the respository's own CI test script +script: + - bash ${DOCKER_CI_REL_DIR}/docker-run-ci.bash scripts/run-ci-tests.bash + +# Cache the docker container if it was rebuilt above. +before_cache: + - bash ${DOCKER_CI_REL_DIR}/save-docker-cache-ci.bash + +cache: + directories: + - $HOME/docker_cache + timeout: 1200 diff --git a/scripts/create_catkin_workspace.bash b/scripts/create_catkin_workspace.bash new file mode 100644 index 0000000..c5e6827 --- /dev/null +++ b/scripts/create_catkin_workspace.bash @@ -0,0 +1,44 @@ +#!/bin/bash +set -e +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +# get UBUNTU_CODENAME, ROS_DISTRO, REPO_DIR, CATKIN_DIR +source $SCRIPT_DIR/identify_environment.bash + +main() +{ + install_catkin_tools + create_catkin_ws +} + +install_catkin_tools() +{ + # Check if already installed + if type catkin > /dev/null 2>&1; then + echo "Catkin tools is already installed" + else + echo "Installing catkin tools ..." + sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu `lsb_release -sc` main" > /etc/apt/sources.list.d/ros-latest.list' + wget -qO - http://packages.ros.org/ros.key | sudo apt-key add - + sudo apt-get -qq update + sudo apt-get -qq install python-catkin-tools > /dev/null + echo "Catkin tools installed successfully." + fi +} + +create_catkin_ws() +{ + # Check if workspace exists + if [ -e "$CATKIN_DIR/.catkin_workspace" ] || [ -d "$CATKIN_DIR/.catkin_tools" ]; then + echo "Catkin workspace detected at ~/catkin_ws" + else + echo "Creating catkin workspace in $HOME/catkin_ws ..." + source /opt/ros/$ROS_DISTRO/setup.bash + mkdir -p "$HOME/catkin_ws/src" + cd "$HOME/catkin_ws" + catkin init > /dev/null + catkin build --no-status + echo "Catkin workspace created successfully." + fi +} + +main diff --git a/scripts/identify_environment.bash b/scripts/identify_environment.bash new file mode 100644 index 0000000..f71becb --- /dev/null +++ b/scripts/identify_environment.bash @@ -0,0 +1,14 @@ +#!/bin/bash +set -e +export UBUNTU_CODENAME=$(lsb_release -s -c) +case $UBUNTU_CODENAME in + trusty) + export ROS_DISTRO=indigo;; + xenial) + export ROS_DISTRO=kinetic;; + *) + echo "Unsupported version of Ubuntu detected. Only trusty (14.04.*) and xenial (16.04.*) are currently supported." + exit 1 +esac +export REPO_DIR=$(dirname "$SCRIPT_DIR") +export CATKIN_DIR="$HOME/catkin_ws" diff --git a/scripts/install_deps_for_docker_ci.bash b/scripts/install_deps_for_docker_ci.bash new file mode 100644 index 0000000..8d575e8 --- /dev/null +++ b/scripts/install_deps_for_docker_ci.bash @@ -0,0 +1,5 @@ +#!/bin/bash +set -e + +source /scripts/ros_install.bash +source /scripts/create_catkin_workspace.bash diff --git a/scripts/ros_install.bash b/scripts/ros_install.bash new file mode 100644 index 0000000..4023bfd --- /dev/null +++ b/scripts/ros_install.bash @@ -0,0 +1,40 @@ +#!/bin/bash +set -e # exit on first error +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +# get UBUNTU_CODENAME, ROS_DISTRO, REPO_DIR, CATKIN_DIR +source $SCRIPT_DIR/identify_environment.bash + +ROSPACKAGES_DIR="$REPO_DIR/rospackages" + +sudo sh -c "echo \"deb http://packages.ros.org/ros/ubuntu $UBUNTU_CODENAME main\" > /etc/apt/sources.list.d/ros-latest.list" +wget -qO - http://packages.ros.org/ros.key | sudo apt-key add - + +echo "Updating package lists ..." +sudo apt-get -qq update +echo "Installing ROS $ROS_DISTRO ..." +sudo apt-get -qq install python-catkin-pkg python-rosdep python-wstool ros-$ROS_DISTRO-catkin ros-$ROS_DISTRO-desktop > /dev/null +sudo apt-get -qq install ros-$ROS_DISTRO-pcl-ros ros-$ROS_DISTRO-image-transport ros-$ROS_DISTRO-image-transport-plugins ros-$ROS_DISTRO-libg2o > /dev/null + +source /opt/ros/$ROS_DISTRO/setup.bash + +# Prepare rosdep to install dependencies. +echo "Updating rosdep ..." +if [ ! -d /etc/ros/rosdep ]; then + sudo rosdep init > /dev/null +fi + +# Add Dataspeed packages +echo "Setting up Dataspeed apt and rosdep repositories" +bash <(wget -q -O - https://bitbucket.org/DataspeedInc/ros_binaries/raw/default/scripts/setup.bash) + +rosdep update +sudo apt-get -qq install python-rosinstall + +# Install system dependencies listed in ROS packages' package.xml +# Note: dependencies needed on embedded systems must still be included +# separately in the repo or cross-compiled stage. +if [ -d "$ROSPACKAGES_DIR" ]; then + rosdep -q -y install --from-paths "$ROSPACKAGES_DIR" --ignore-src +else + echo "Repository not detected: rosdep did not run" +fi diff --git a/scripts/run-ci-tests.bash b/scripts/run-ci-tests.bash new file mode 100644 index 0000000..03ea6bd --- /dev/null +++ b/scripts/run-ci-tests.bash @@ -0,0 +1,14 @@ +#!/bin/bash +set -e # exit on first error + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +# get UBUNTU_CODENAME, ROS_DISTRO, REPO_DIR, CATKIN_DIR +source $SCRIPT_DIR/identify_environment.bash +source /opt/ros/${ROS_DISTRO}/setup.bash + +sudo apt-get update + +cd ${CATKIN_DIR} + +catkin build --no-status