Skip to content

Commit

Permalink
Add build test.
Browse files Browse the repository at this point in the history
  • Loading branch information
at-wat committed Sep 30, 2017
1 parent aedb8bc commit 2a677e3
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .travis.scripts/deps.rosinstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- git:
local-name: yp-spur
uri: https://github.com/openspur/yp-spur.git
version: master
14 changes: 14 additions & 0 deletions .travis.scripts/load_cache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -o errexit
set -o verbose

sudo apt-get -qq update
sudo apt-get install -y liblz4-tool

echo ${DOCKER_CACHE_FILE}

if [ -f ${DOCKER_CACHE_FILE} ]; then
lz4 -dc ${DOCKER_CACHE_FILE} | docker load || true
fi

15 changes: 15 additions & 0 deletions .travis.scripts/save_cache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -o errexit
set -o verbose

if [[ ${TRAVIS_BRANCH} == "master" ]] && [[ ${TRAVIS_PULL_REQUEST} == "false" ]];
then
mkdir -p $(dirname ${DOCKER_CACHE_FILE})
docker save $(docker history -q ${PACKAGE_NAME}:latest | grep -v '<missing>') | lz4 -zcf - > ${DOCKER_CACHE_FILE}

echo "------------"
ls -lh $(dirname ${DOCKER_CACHE_FILE})
echo "------------"
fi

12 changes: 12 additions & 0 deletions .travis.scripts/setup_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -o errexit
set -o verbose

echo 'DOCKER_OPTS="-H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock -s overlay2"' \
| sudo tee /etc/default/docker > /dev/null
sudo service docker restart

sleep 5
docker info

52 changes: 52 additions & 0 deletions .travis.scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

set -o errexit
set -o verbose

scriptdir=`dirname "${0}"`

wget -q -P /tmp https://raw.githubusercontent.com/at-wat/gh-pr-comment/master/gh-pr-comment.sh
source /tmp/gh-pr-comment.sh

source /opt/ros/${ROS_DISTRO}/setup.bash
source /catkin_ws/devel/setup.bash

cd /catkin_ws

if [ -f $scriptdir/deps.rosinstall ];
then
wstool init src $scriptdir/deps.rosinstall
fi

apt-get -qq update && \
apt-get install libxml2-utils && \
rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

catkin_make || (gh-pr-comment FAILED '```catkin_make``` failed'; false)
catkin_make tests --cmake-args -DMCL_3DL_EXTRA_TESTS:=ON || (gh-pr-comment FAILED '```catkin_make tests``` failed'; false)
catkin_make run_tests --cmake-args -DMCL_3DL_EXTRA_TESTS:=ON || (gh-pr-comment FAILED '```catkin_make run_tests``` failed'; false)

if [ catkin_test_results ];
then
result_text="
\`\`\`
`catkin_test_results --all || true`
\`\`\`
"
else
result_text="
\`\`\`
`catkin_test_results --all || true`
\`\`\`
`find build/test_results/ -name *.xml | xargs -n 1 -- bash -c 'echo; echo \#\#\# $0; echo; echo \\\`\\\`\\\`; xmllint --format $0; echo \\\`\\\`\\\`;'`
"
fi
catkin_test_results || (gh-pr-comment FAILED "Test failed$result_text"; false)

gh-pr-comment PASSED "All tests passed$result_text"

cd ..
rm -rf /catkin_ws || true

24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
sudo: required
services: docker

cache:
directories:
- /home/travis/docker/
env:
global:
- DOCKER_CACHE_FILE=/home/travis/docker/cache.tar.lz4
- PACKAGE_NAME=ypspur_ros
branches:
only:
- master

before_install:
- .travis.scripts/setup_docker.sh
- .travis.scripts/load_cache.sh

install: true

script:
- docker build -t ${PACKAGE_NAME}:latest --pull=true ${TRAVIS_BUILD_DIR} --build-arg TRAVIS_PULL_REQUEST=${TRAVIS_PULL_REQUEST} --build-arg TRAVIS_REPO_SLUG=${TRAVIS_REPO_SLUG} --build-arg TRAVIS_BOT_GITHUB_TOKEN=${TRAVIS_BOT_GITHUB_TOKEN}
- .travis.scripts/save_cache.sh

21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM ros:kinetic

RUN apt-get -qq update && \
apt-get install -y --no-install-recommends sudo wget curl && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN rosdep update && \
mkdir -p /catkin_ws/src && \
bash -c "cd /catkin_ws/src && . /opt/ros/${ROS_DISTRO}/setup.bash && catkin_init_workspace && cd .. && catkin_make"

ARG TRAVIS_PULL_REQUEST=false
ARG TRAVIS_REPO_SLUG=""
ARG TRAVIS_BOT_GITHUB_TOKEN=""

ENV TRAVIS_PULL_REQUEST=$TRAVIS_PULL_REQUEST
ENV TRAVIS_REPO_SLUG=$TRAVIS_REPO_SLUG
ENV TRAVIS_BOT_GITHUB_TOKEN=$TRAVIS_BOT_GITHUB_TOKEN

COPY ./ /catkin_ws/src/$PACKAGE_NAME
RUN /catkin_ws/src/$PACKAGE_NAME/.travis.scripts/test.sh

0 comments on commit 2a677e3

Please sign in to comment.