Skip to content

Instantly share code, notes, and snippets.

@chussenot
Created February 13, 2017 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chussenot/2e5c76728fc0565d7c6305c43ef7fcca to your computer and use it in GitHub Desktop.
Save chussenot/2e5c76728fc0565d7c6305c43ef7fcca to your computer and use it in GitHub Desktop.
#!/bin/bash
if [[ -s //etc/profile ]]; then
source //etc/profile
fi
if [[ -s $HOME/.bash_profile ]] ; then
source $HOME/.bash_profile
fi
ANSI_RED="\033[31;1m"
ANSI_GREEN="\033[32;1m"
ANSI_RESET="\033[0m"
ANSI_CLEAR="\033[0K"
if [ $TERM = dumb ]; then
unset TERM
fi
: "${SHELL:=/bin/bash}"
: "${TERM:=xterm}"
: "${USER:=travis}"
export SHELL
export TERM
export USER
TRAVIS_TEST_RESULT=
TRAVIS_CMD=
travis_cmd() {
local assert output display retry timing cmd result secure
cmd=$1
TRAVIS_CMD=$cmd
shift
while true; do
case "$1" in
--assert) assert=true; shift ;;
--echo) output=true; shift ;;
--display) display=$2; shift 2;;
--retry) retry=true; shift ;;
--timing) timing=true; shift ;;
--secure) secure=" 2>/dev/null"; shift ;;
*) break ;;
esac
done
if [[ -n "$timing" ]]; then
travis_time_start
fi
if [[ -n "$output" ]]; then
echo "\$ ${display:-$cmd}"
fi
if [[ -n "$retry" ]]; then
travis_retry eval "$cmd $secure"
result=$?
else
eval "$cmd $secure"
result=$?
if [[ -n $secure && $result -ne 0 ]]; then
echo -e "${ANSI_RED}The previous command failed, possibly due to a malformed secure environment variable.${ANSI_CLEAR}
${ANSI_RED}Please be sure to escape special characters such as ' ' and '$'.${ANSI_CLEAR}
${ANSI_RED}For more information, see https://docs.travis-ci.com/user/encryption-keys.${ANSI_CLEAR}"
fi
fi
if [[ -n "$timing" ]]; then
travis_time_finish
fi
if [[ -n "$assert" ]]; then
travis_assert $result
fi
return $result
}
travis_time_start() {
travis_timer_id=$(printf %08x $(( RANDOM * RANDOM )))
travis_start_time=$(travis_nanoseconds)
echo -en "travis_time:start:$travis_timer_id\r${ANSI_CLEAR}"
}
travis_time_finish() {
local result=$?
travis_end_time=$(travis_nanoseconds)
local duration=$(($travis_end_time-$travis_start_time))
echo -en "\ntravis_time:end:$travis_timer_id:start=$travis_start_time,finish=$travis_end_time,duration=$duration\r${ANSI_CLEAR}"
return $result
}
travis_nanoseconds() {
local cmd="date"
local format="+%s%N"
local os=$(uname)
if hash gdate > /dev/null 2>&1; then
cmd="gdate"
elif [[ "$os" = Darwin ]]; then
format="+%s000000000"
fi
$cmd -u $format
}
travis_internal_ruby() {
if ! type rvm &>/dev/null; then
source $HOME/.rvm/scripts/rvm &>/dev/null
fi
local i selected_ruby rubies_array rubies_array_sorted rubies_array_len
rubies_array=( $(
rvm list strings \
| while read -r v; do
if [[ ! "${v}" =~ ^ruby-(2\.[0-2]\.[0-9]|1\.9\.3) ]]; then
continue
fi
v="${v//ruby-/}"
v="${v%%-*}"
echo "$(vers2int "${v}")_${v}"
done
) )
bash_qsort_numeric "${rubies_array[@]}"
rubies_array_sorted=( ${bash_qsort_numeric_ret[@]} )
rubies_array_len="${#rubies_array_sorted[@]}"
i=$(( rubies_array_len - 1 ))
selected_ruby="${rubies_array_sorted[${i}]}"
selected_ruby="${selected_ruby##*_}"
echo "${selected_ruby:-default}"
}
travis_assert() {
local result=${1:-$?}
if [ $result -ne 0 ]; then
echo -e "\n${ANSI_RED}The command \"$TRAVIS_CMD\" failed and exited with $result during $TRAVIS_STAGE.${ANSI_RESET}\n\nYour build has been stopped."
travis_terminate 2
fi
}
travis_result() {
local result=$1
export TRAVIS_TEST_RESULT=$(( ${TRAVIS_TEST_RESULT:-0} | $(($result != 0)) ))
if [ $result -eq 0 ]; then
echo -e "\n${ANSI_GREEN}The command \"$TRAVIS_CMD\" exited with $result.${ANSI_RESET}"
else
echo -e "\n${ANSI_RED}The command \"$TRAVIS_CMD\" exited with $result.${ANSI_RESET}"
fi
}
travis_terminate() {
pkill -9 -P $$ &> /dev/null || true
exit $1
}
travis_wait() {
local timeout=$1
if [[ $timeout =~ ^[0-9]+$ ]]; then
shift
else
timeout=20
fi
local cmd="$@"
local log_file=travis_wait_$$.log
$cmd &>$log_file &
local cmd_pid=$!
travis_jigger $! $timeout $cmd &
local jigger_pid=$!
local result
{
wait $cmd_pid 2>/dev/null
result=$?
ps -p$jigger_pid &>/dev/null && kill $jigger_pid
}
if [ $result -eq 0 ]; then
echo -e "\n${ANSI_GREEN}The command $cmd exited with $result.${ANSI_RESET}"
else
echo -e "\n${ANSI_RED}The command $cmd exited with $result.${ANSI_RESET}"
fi
echo -e "\n${ANSI_GREEN}Log:${ANSI_RESET}\n"
cat $log_file
return $result
}
travis_jigger() {
local cmd_pid=$1
shift
local timeout=$1
shift
local count=0
echo -e "\n"
while [ $count -lt $timeout ]; do
count=$(($count + 1))
echo -ne "Still running ($count of $timeout): $@\r"
sleep 60
done
echo -e "\n${ANSI_RED}Timeout (${timeout} minutes) reached. Terminating \"$@\"${ANSI_RESET}\n"
kill -9 $cmd_pid
}
travis_retry() {
local result=0
local count=1
while [ $count -le 3 ]; do
[ $result -ne 0 ] && {
echo -e "\n${ANSI_RED}The command \"$@\" failed. Retrying, $count of 3.${ANSI_RESET}\n" >&2
}
"$@"
result=$?
[ $result -eq 0 ] && break
count=$(($count + 1))
sleep 1
done
[ $count -gt 3 ] && {
echo -e "\n${ANSI_RED}The command \"$@\" failed 3 times.${ANSI_RESET}\n" >&2
}
return $result
}
travis_fold() {
local action=$1
local name=$2
echo -en "travis_fold:${action}:${name}\r${ANSI_CLEAR}"
}
decrypt() {
echo $1 | base64 -d | openssl rsautl -decrypt -inkey $HOME/.ssh/id_rsa.repo
}
vers2int() {
printf '1%03d%03d%03d%03d' $(echo "$1" | tr '.' ' ')
}
bash_qsort_numeric() {
local pivot i smaller=() larger=()
bash_qsort_numeric_ret=()
(($#==0)) && return 0
pivot=${1}
shift
for i; do
if [[ ${i%%_*} -lt ${pivot%%_*} ]]; then
smaller+=( "$i" )
else
larger+=( "$i" )
fi
done
bash_qsort_numeric "${smaller[@]}"
smaller=( "${bash_qsort_numeric_ret[@]}" )
bash_qsort_numeric "${larger[@]}"
larger=( "${bash_qsort_numeric_ret[@]}" )
bash_qsort_numeric_ret=( "${smaller[@]}" "$pivot" "${larger[@]}" )
}
if [[ -f /etc/apt/sources.list.d/rabbitmq-source.list ]] ; then
sudo rm -f /etc/apt/sources.list.d/rabbitmq-source.list
fi
mkdir -p $HOME/build
cd $HOME/build
travis_fold start system_info
echo -e "\033[33;1mBuild system information\033[0m"
echo -e "Build language: php"
echo -e "Build dist: trusty"
echo -e "Build id: ''"
echo -e "Job id: ''"
if [[ -f /usr/share/travis/system_info ]]; then
cat /usr/share/travis/system_info
fi
travis_fold end system_info
echo
export PATH=$(echo $PATH | sed -e 's/::/:/g')
export PATH=$(echo -n $PATH | perl -e 'print join(":", grep { not $seen{$_}++ } split(/:/, scalar <>))')
echo "options rotate
options timeout:1
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 208.67.222.222
nameserver 208.67.220.220
" | sudo tee /etc/resolv.conf &> /dev/null
sudo sed -e 's/^\(127\.0\.0\.1.*\)$/\1 '`hostname`'/' -i'.bak' /etc/hosts
sudo sed -e 's/^\([0-9a-f:]\+\) localhost/\1/' -i'.bak' /etc/hosts
test -f /etc/mavenrc && sudo sed -e 's/M2_HOME=\(.\+\)$/M2_HOME=${M2_HOME:-\1}/' -i'.bak' /etc/mavenrc
if [ $(command -v sw_vers) ]; then
echo "Fix WWDRCA Certificate"
sudo security delete-certificate -Z 0950B6CD3D2F37EA246A1AAA20DFAADBD6FE1F75 /Library/Keychains/System.keychain
wget -q https://developer.apple.com/certificationauthority/AppleWWDRCA.cer
sudo security add-certificates -k /Library/Keychains/System.keychain AppleWWDRCA.cer
fi
grep '^127\.0\.0\.1' /etc/hosts | sed -e 's/^127\.0\.0\.1 \(.*\)/\1/g' | sed -e 's/localhost \(.*\)/\1/g' | tr "\n" " " > /tmp/hosts_127_0_0_1
sed '/^127\.0\.0\.1/d' /etc/hosts > /tmp/hosts_sans_127_0_0_1
cat /tmp/hosts_sans_127_0_0_1 | sudo tee /etc/hosts > /dev/null
echo -n "127.0.0.1 localhost " | sudo tee -a /etc/hosts > /dev/null
cat /tmp/hosts_127_0_0_1 | sudo tee -a /etc/hosts > /dev/null
# apply :home_paths
for path_entry in $HOME/.local/bin $HOME/bin ; do
if [[ ${PATH%%:*} != $path_entry ]] ; then
export PATH="$path_entry:$PATH"
fi
done
if [ ! $(uname|grep Darwin) ]; then echo update_initramfs=no | sudo tee -a /etc/initramfs-tools/update-initramfs.conf > /dev/null; fi
if [[ "$(sw_vers -productVersion 2>/dev/null | cut -d . -f 2)" -lt 12 ]]; then
mkdir -p $HOME/.ssh
chmod 0700 $HOME/.ssh
touch $HOME/.ssh/config
echo -e "Host *
UseRoaming no
" | cat - $HOME/.ssh/config > $HOME/.ssh/config.tmp && mv $HOME/.ssh/config.tmp $HOME/.ssh/config
fi
function travis_debug() {
echo -e "\033[31;1mThe debug environment is not available. Please contact support.\033[0m"
false
}
if [[ $(command -v sw_vers) ]]; then
travis_cmd rvm\ use --echo
fi
if [[ -L /usr/lib/jvm/java-8-oracle-amd64 ]]; then
echo -e "Removing symlink /usr/lib/jvm/java-8-oracle-amd64"
travis_cmd sudo\ rm\ -f\ /usr/lib/jvm/java-8-oracle-amd64 --echo
if [[ -f $HOME/.jdk_switcher_rc ]]; then
echo -e "Reload jdk_switcher"
travis_cmd source\ \$HOME/.jdk_switcher_rc --echo
fi
if [[ -f /opt/jdk_switcher/jdk_switcher.sh ]]; then
echo -e "Reload jdk_switcher"
travis_cmd source\ /opt/jdk_switcher/jdk_switcher.sh --echo
fi
fi
export GIT_ASKPASS=echo
travis_fold start git.checkout
if [[ ! -d Epiconcept-Paris/Voozanoo4/.git ]]; then
travis_cmd git\ clone\ --depth\=1\ --branch\=\'\'\ git@github.com:Epiconcept-Paris/Voozanoo4.git\ Epiconcept-Paris/Voozanoo4 --assert --echo --retry --timing
if [[ $? -ne 0 ]]; then
echo -e "\033[31;1mFailed to clone from GitHub.\033[0m"
echo -e "Checking GitHub status (https://status.github.com/api/last-message.json):"
curl -sL https://status.github.com/api/last-message.json | jq -r .[]
fi
else
travis_cmd git\ -C\ Epiconcept-Paris/Voozanoo4\ fetch\ origin --assert --echo --retry --timing
travis_cmd git\ -C\ Epiconcept-Paris/Voozanoo4\ reset\ --hard --assert --echo
fi
travis_cmd cd\ Epiconcept-Paris/Voozanoo4 --echo
travis_cmd git\ checkout\ -qf\ --assert --echo
travis_fold end git.checkout
if [[ -f .gitmodules ]]; then
travis_fold start git.submodule
echo Host\ github.com'
'\ StrictHostKeyChecking\ no'
' >> ~/.ssh/config
travis_cmd git\ submodule\ update\ --init\ --recursive --assert --echo --retry --timing
travis_fold end git.submodule
fi
rm -f ~/.ssh/source_rsa
export PS4=+
export TRAVIS=true
export CI=true
export CONTINUOUS_INTEGRATION=true
export PAGER=cat
export HAS_JOSH_K_SEAL_OF_APPROVAL=true
export TRAVIS_ALLOW_FAILURE=''
export TRAVIS_EVENT_TYPE=''
export TRAVIS_PULL_REQUEST=false
export TRAVIS_SECURE_ENV_VARS=false
export TRAVIS_BUILD_ID=''
export TRAVIS_BUILD_NUMBER=''
export TRAVIS_BUILD_DIR=$HOME/build/Epiconcept-Paris/Voozanoo4
export TRAVIS_JOB_ID=''
export TRAVIS_JOB_NUMBER=''
export TRAVIS_BRANCH=''
export TRAVIS_COMMIT=''
export TRAVIS_COMMIT_MESSAGE=$(git log --format=%B -n 1)
export TRAVIS_COMMIT_RANGE=''
export TRAVIS_REPO_SLUG=Epiconcept-Paris/Voozanoo4
export TRAVIS_OS_NAME=''
export TRAVIS_LANGUAGE=php
export TRAVIS_TAG=''
export TRAVIS_SUDO=true
export TRAVIS_PULL_REQUEST_BRANCH=''
export TRAVIS_PULL_REQUEST_SHA=''
export TRAVIS_PULL_REQUEST_SLUG=''
echo
echo -e "\033[33;1mSetting environment variables from .travis.yml\033[0m"
travis_cmd export\ SHORT_APPNAME\=voozanoo-demo --echo
travis_cmd export\ PHP_CS_FIXER_VERSION\=2.0.0 --echo
travis_cmd export\ AWS_DEFAULT_REGION\=us-east-1 --echo
travis_cmd export\ DOCKER_REGISTRY\=925059019146.dkr.ecr.us-east-1.amazonaws.com --echo
echo
export TRAVIS_PHP_VERSION=["5.6", "7.1"]
travis_cmd phpenv\ global\ \[\"5.6\",\ \"7.1\"\]\ 2\>/dev/null --echo --timing
if [[ $? -ne 0 ]]; then
echo -e "\033[33;1m["5.6", "7.1"] is not pre-installed; installing\033[0m"
if [[ $(uname) = 'Linux' ]]; then
travis_host_os=$(lsb_release -is | tr 'A-Z' 'a-z')
travis_rel_version=$(lsb_release -rs)
elif [[ $(uname) = 'Darwin' ]]; then
travis_host_os=osx
travis_rel=$(sw_vers -productVersion)
travis_rel_version=${travis_rel%*.*}
fi
archive_url=https://s3.amazonaws.com/travis-php-archives/binaries/${travis_host_os}/${travis_rel_version}/$(uname -m)/php-["5.6", "7.1"].tar.bz2
echo -e "\033[33;1mDownloading archive: ${archive_url}\033[0m"
travis_cmd curl\ -s\ -o\ archive.tar.bz2\ \$archive_url\ \&\&\ tar\ xjf\ archive.tar.bz2\ --directory\ / --echo --timing
travis_cmd rm\ -f\ archive.tar.bz2 --assert --timing
fi
travis_cmd phpenv\ global\ \[\"5.6\",\ \"7.1\"\] --assert --echo --timing
phpenv rehash
travis_cmd composer\ self-update\ 1.0.0 --echo --timing
travis_cmd composer\ self-update --echo --timing
travis_cmd php\ --version --echo
travis_cmd composer\ --version --echo
echo -e "${ANSI_RESET}"
travis_fold start before_install
travis_cmd ./script/before_install.sh --assert --echo --timing
travis_fold end before_install
travis_fold start install
travis_cmd ./script/install.sh --assert --echo --timing
travis_fold end install
travis_fold start sonarqube.addon
echo -e "\033[33;1mSonarQube addon\033[0m"
echo -e "addon hash: 187bb90a8521235b4b8c8a4e70fb431b"
echo -e "\033[33;1mPreparing SonarQube Scanner CLI\033[0m"
rm -rf $HOME/.sonarscanner
mkdir -p $HOME/.sonarscanner
curl -sSLo $HOME/.sonarscanner/sonar-scanner.zip http://repo1.maven.org/maven2/org/sonarsource/scanner/cli/sonar-scanner-cli/2.8/sonar-scanner-cli-2.8.zip
unzip $HOME/.sonarscanner/sonar-scanner.zip -d $HOME/.sonarscanner
travis_cmd export\ SONAR_SCANNER_HOME\=\$HOME/.sonarscanner/sonar-scanner-2.8 --echo
export PATH="$PATH:$HOME/.sonarscanner/sonar-scanner-2.8/bin"
echo -e "\033[33;1mPreparing build wrapper for SonarSource C/C++ plugin\033[0m"
echo -e "\033[33;1mCan't install SonarSource build wrapper for platform: $TRAVIS_OS_NAME.\033[0m"
echo -e "\033[33;1mSkipping SonarQube Scan because it is not running in a secure environment\033[0m"
travis_cmd export\ SONARQUBE_SKIPPED\=true --echo
export SONARQUBE_SCANNER_PARAMS="{ \"sonar.scanner.skip\" : \"true\" }"
travis_fold end sonarqube.addon
travis_cmd php\ --version --echo --timing
travis_result $?
travis_cmd docker\ -v --echo --timing
travis_result $?
travis_cmd phpunit --echo --timing
travis_result $?
travis_cmd ./script/php_cs_fix.sh\ src --echo --timing
travis_result $?
travis_cmd sonar-scanner --echo --timing
travis_result $?
travis_cmd ./script/tests_docker.sh --echo --timing
travis_result $?
travis_cmd echo\ \"D\ébut\ du\ build\ du\ .deb\" --echo --timing
travis_result $?
travis_cmd sudo\ ./script/deploy_deb.sh\ 12.24.02\ Voo4Skeleton\ 1.0.4 --echo --timing
travis_result $?
travis_cmd echo\ \"Tests\ sur\ le\ .deb\" --echo --timing
travis_result $?
travis_cmd echo\ \"Fin\ du\ build\ du\ .deb\" --echo --timing
travis_result $?
if [[ $TRAVIS_TEST_RESULT = 0 ]]; then
if [[ $- = *e* ]]; then
ERREXIT_SET=true
fi
set +e
travis_fold start before_deploy
travis_cmd ./script/before_deploy.sh --assert --echo --timing
travis_fold end before_deploy
travis_fold start dpl.0
type rvm &>/dev/null || source ~/.rvm/scripts/rvm
travis_cmd rvm\ \$\(travis_internal_ruby\)\ --fuzzy\ do\ ruby\ -S\ gem\ install\ dpl --assert --timing
rm -f dpl-*.gem
travis_fold end dpl.0
type rvm &>/dev/null || source ~/.rvm/scripts/rvm
travis_cmd rvm\ \$\(travis_internal_ruby\)\ --fuzzy\ do\ ruby\ -S\ dpl\ --provider\=\"script\"\ --skip_cleanup\ --script\=\"script/deploy.sh\"\ --fold\;\ if\ \[\ \$\?\ -ne\ 0\ \]\;\ then\ echo\ \"failed\ to\ deploy\"\;\ travis_terminate\ 2\;\ fi --timing
if [[ -n $ERREXIT_SET ]]; then
set -e
fi
fi
echo -e "\nDone. Your build exited with $TRAVIS_TEST_RESULT."
travis_terminate $TRAVIS_TEST_RESULT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment