Skip to content

Commit

Permalink
Lets Travis build and publish
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-j-h committed Mar 16, 2017
1 parent fa4f035 commit 5af45d4
Show file tree
Hide file tree
Showing 5 changed files with 257 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ before_install:
- echo "Using ${JOBS} jobs"
- source ./scripts/install_node.sh 4
- npm install -g "npm@>=3" # Upgrade to npm >v2 to reduce size of downloaded dependencies
- npm install
- npm install --ignore-scripts
# Bootstrap cmake to be able to run mason
- CMAKE_URL="https://mason-binaries.s3.amazonaws.com/${TRAVIS_OS_NAME}-x86_64/cmake/${CMAKE_VERSION}.tar.gz"
- CMAKE_DIR="mason_packages/${TRAVIS_OS_NAME}-x86_64/cmake/${CMAKE_VERSION}"
Expand Down Expand Up @@ -213,3 +213,9 @@ after_success:
if [ -n "${ENABLE_COVERAGE}" ]; then
bash <(curl -s https://codecov.io/bash)
fi
- |
nvm install 4
nvm use 4
source ./scripts/build.sh
./scripts/travis/publish.sh
97 changes: 97 additions & 0 deletions scripts/travis/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/env bash

set -eu
set -o pipefail

# defaults
export ENABLE_COVERAGE=${ENABLE_COVERAGE:-"Off"}
export BUILD_TYPE=${BUILD_TYPE:-"Release"}
export NODE=${NODE:-4}

export CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

export DEPS_DIR="$(pwd)/deps"
export PATH=${DEPS_DIR}/bin:${PATH}
mkdir -p ${DEPS_DIR}

export CLANG_VERSION="${CLANG_VERSION:-4.0.0}"
export CCACHE_VERSION=3.3.1
export CMAKE_VERSION=3.7.2

source ${CURRENT_DIR}/travis_helper.sh

# ensure we start inside the root directory (two level up)
cd ${CURRENT_DIR}/../../

if [[ ! $(which wget) ]]; then
echo "echo wget must be installed";
exit 1;
fi;

SYSTEM_NAME=$(uname -s)
if [[ "${SYSTEM_NAME}" == "Darwin" ]]; then
OS_NAME="osx"
elif [[ "${SYSTEM_NAME}" == "Linux" ]]; then
OS_NAME="linux"
fi

# FIXME This should be replaced by proper calls to mason but we currently have a chicken-egg problem
# since we rely on osrm-backend to ship mason for us. Once we merged this into osrm-backend this will not be needed.
CMAKE_URL="https://s3.amazonaws.com/mason-binaries/${OS_NAME}-x86_64/cmake/${CMAKE_VERSION}.tar.gz"
echo "Downloading cmake from ${CMAKE_URL} ..."
wget --quiet -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C ${DEPS_DIR} || exit 1
CCACHE_URL="https://s3.amazonaws.com/mason-binaries/${OS_NAME}-x86_64/ccache/${CCACHE_VERSION}.tar.gz"
echo "Downloading ccache from ${CCACHE_URL} ..."
wget --quiet -O - ${CCACHE_URL} | tar --strip-components=1 -xz -C ${DEPS_DIR} || exit 1
# install clang for linux but use the xcode version on OSX
if [[ "${OS_NAME}" != "osx" ]]; then
CLANG_URL="https://s3.amazonaws.com/mason-binaries/${OS_NAME}-x86_64/clang++/${CLANG_VERSION}.tar.gz"
echo "Downloading clang from ${CLANG_URL} ..."
wget --quiet -O - ${CLANG_URL} | tar --strip-components=1 -xz -C ${DEPS_DIR} || exit 1
export CCOMPILER='clang'
export CXXCOMPILER='clang++'
export CC='clang'
export CXX='clang++'
fi

if [[ "${OS_NAME}" == "osx" ]]; then
if [[ -f /etc/sysctl.conf ]] && [[ $(grep shmmax /etc/sysctl.conf) ]]; then
echo "Note: found shmmax setting in /etc/sysctl.conf, not modifying"
else
echo "WARNING: Did not find shmmax setting in /etc/sysctl.conf, adding now (requires sudo and restarting)..."
sudo sysctl -w kern.sysv.shmmax=4294967296
sudo sysctl -w kern.sysv.shmall=1048576
sudo sysctl -w kern.sysv.shmseg=128
fi
fi


echo "Now build node-osrm and dependencies"
export VERBOSE=1
if [[ "${ENABLE_COVERAGE}" == "On" ]]; then
mapbox_time "make" make -j${JOBS} coverage
else
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DENABLE_NODE_BINDINGS=On -DENABLE_MASON=On
mapbox_time "make" make -j${JOBS}
fi

# run tests, with backtrace support
if [[ "${OS_NAME}" == "linux" ]]; then
ulimit -c unlimited -S
RESULT=0
mapbox_time "make-test" make tests || RESULT=$?
for i in $(find ./ -maxdepth 1 -name 'core*' -print);
do gdb $(which node) $i -ex "thread apply all bt" -ex "set pagination 0" -batch;
done;
if [[ ${RESULT} != 0 ]]; then exit $RESULT; fi
else
# todo: coredump support on OS X
RESULT=0
mapbox_time "make-test" make tests || RESULT=$?
if [[ ${RESULT} != 0 ]]; then exit $RESULT; fi
fi


set +eu
set +o pipefail
27 changes: 27 additions & 0 deletions scripts/travis/is_pr_merge.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

set -eu pipefail

: '
This script is designed to detect if a gitsha represents a normal
push commit (to any branch) or whether it represents travis attempting
to merge between the origin and the upstream branch.
For more details see: https://docs.travis-ci.com/user/pull-requests
'

# Get the commit message via git log
# This should always be the exact text the developer provided
COMMIT_LOG=$(git log --format=%B --no-merges -n 1 | tr -d '\n')

# Get the commit message via git show
# If the gitsha represents a merge then this will
# look something like "Merge e3b1981 into 615d2a3"
# Otherwise it will be the same as the "git log" output
COMMIT_SHOW=$(git show -s --format=%B | tr -d '\n')

if [[ "${COMMIT_LOG}" != "${COMMIT_SHOW}" ]]; then
echo true
fi
51 changes: 51 additions & 0 deletions scripts/travis/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

set -eu
set -o pipefail

# should be set for debug builds
export NPM_FLAGS=${NPM_FLAGS:-}

echo "node version is:"
which node
node -v

echo "dumping binary meta..."
./node_modules/.bin/node-pre-gyp reveal ${NPM_FLAGS}

# enforce that binary has proper ORIGIN flags so that
# it can portably find libtbb.so in the same directory
if [[ $(uname -s) == 'Linux' ]]; then
readelf -d ./lib/binding/node-osrm.node > readelf-output.txt
if grep -q 'Flags: ORIGIN' readelf-output.txt; then
echo "Found ORIGIN flag in readelf output"
cat readelf-output.txt
else
echo "*** Error: Could not found ORIGIN flag in readelf output"
cat readelf-output.txt
exit 1
fi
fi

echo "determining publishing status..."

if [[ $(./scripts/travis/is_pr_merge.sh) ]]; then
echo "Skipping publishing because this is a PR merge commit"
else
echo "This is a push commit, continuing to package..."
./node_modules/.bin/node-pre-gyp package ${NPM_FLAGS}

export COMMIT_MESSAGE=$(git log --format=%B --no-merges | head -n 1 | tr -d '\n')
echo "Commit message: ${COMMIT_MESSAGE}"

if [[ ${COMMIT_MESSAGE} =~ "[publish binary]" ]]; then
echo "Publishing"
./node_modules/.bin/node-pre-gyp publish ${NPM_FLAGS}
elif [[ ${COMMIT_MESSAGE} =~ "[republish binary]" ]]; then
echo "*** Error: Republishing is disallowed for this repository"
exit 1
#./node_modules/.bin/node-pre-gyp unpublish publish ${NPM_FLAGS}
else
echo "Skipping publishing"
fi;
fi
75 changes: 75 additions & 0 deletions scripts/travis/travis_helper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env bash

# This script is sourced, so do not set -e or -o pipefail here. Doing so would
# bleed into Travis' wrapper script, which messes with their workflow, e.g.
# preventing after_failure scripts to be triggered.

function mapbox_time_start {
local name=$1
mapbox_timer_name=$name

mapbox_fold start $name

mapbox_timer_id=$(printf %08x $(( RANDOM * RANDOM )))
eval "mapbox_start_time_$mapbox_timer_id=$(mapbox_nanoseconds)"
echo -en "travis_time:start:$mapbox_timer_id\n"
}

function mapbox_time_finish {
local name=${1:-$mapbox_timer_name}
local timer_id=${2:-$mapbox_timer_id}
local timer_start="mapbox_start_time_$timer_id"
eval local start_time=\${$timer_start}
local end_time=$(mapbox_nanoseconds)
local duration=$(($end_time-$start_time))
echo -en "travis_time:end:$timer_id:start=$start_time,finish=$end_time,duration=$duration\n"
}

function mapbox_time {
local name=$1 ; shift
mapbox_time_start $name
local timer_id=$mapbox_timer_id
echo "\$ $@"
# note: we capture the return code here
# so that we can ensure mapbox_time_finish is called
# and an error is trickled up correctly
local RESULT=0
$@ || RESULT=$?
mapbox_time_finish $name $timer_id
if [[ ${RESULT} != 0 ]]; then
echo "$name failed with ${RESULT}"
# note: we use false here instead of exit this this script is sourced
# and exit would abort the shell which we don't want
false
else
mapbox_fold end $name
fi
}

function mapbox_fold {
local action=$1
local name=$2
local ANSI_CLEAR="\e[0m"
echo -en "travis_fold:${action}:${name}\r${ANSI_CLEAR}"
}

function mapbox_nanoseconds {
local cmd="date"
local format="+%s%N"
local os=$(uname -s)

if hash gdate > /dev/null 2>&1; then
cmd="gdate" # use gdate if available
elif [[ "$os" = Darwin ]]; then
format="+%s000000000" # fallback to second precision on darwin (does not support %N)
fi

$cmd -u $format
}

export JOBS
export -f mapbox_fold
export -f mapbox_nanoseconds
export -f mapbox_time
export -f mapbox_time_start
export -f mapbox_time_finish

0 comments on commit 5af45d4

Please sign in to comment.