Skip to content

Commit

Permalink
Updated travis build scripts (from rspec-dev)
Browse files Browse the repository at this point in the history
  • Loading branch information
myronmarston committed Oct 30, 2014
1 parent b9b9ce6 commit 81305b9
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .rubocop_rspec_base.yml
@@ -1,4 +1,4 @@
# This file was generated on 2014-09-26T16:56:14+10:00 from the rspec-dev repo.
# This file was generated on 2014-10-30T08:23:40-07:00 from the rspec-dev repo.
# DO NOT modify it by hand as your changes will get lost the next time it is generated.

# This file contains defaults for RSpec projects. Individual projects
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
@@ -1,4 +1,4 @@
# This file was generated on 2014-09-26T16:56:14+10:00 from the rspec-dev repo.
# This file was generated on 2014-10-30T08:23:40-07:00 from the rspec-dev repo.
# DO NOT modify it by hand as your changes will get lost the next time it is generated.

language: ruby
Expand All @@ -19,6 +19,7 @@ rvm:
- 2.1.1
- 2.1.2
- 2.1.3
- 2.1.4
- ruby-head
- ree
- jruby-18mode
Expand Down
4 changes: 2 additions & 2 deletions script/clone_all_rspec_repos
@@ -1,8 +1,8 @@
#!/bin/bash
# This file was generated on 2014-09-26T16:56:14+10:00 from the rspec-dev repo.
# This file was generated on 2014-10-30T08:23:40-07:00 from the rspec-dev repo.
# DO NOT modify it by hand as your changes will get lost the next time it is generated.

set -e -x
set -e
source script/functions.sh

if is_mri; then
Expand Down
104 changes: 25 additions & 79 deletions script/functions.sh
@@ -1,80 +1,14 @@
# This file was generated on 2014-09-26T16:56:14+10:00 from the rspec-dev repo.
# This file was generated on 2014-10-30T08:23:40-07:00 from the rspec-dev repo.
# DO NOT modify it by hand as your changes will get lost the next time it is generated.

source script/travis_functions.sh
source script/predicate_functions.sh

# idea taken from: http://blog.headius.com/2010/03/jruby-startup-time-tips.html
export JRUBY_OPTS="${JRUBY_OPTS} -X-C" # disable JIT since these processes are so short lived
SPECS_HAVE_RUN_FILE=specs.out
MAINTENANCE_BRANCH=`cat maintenance-branch`

# Taken from:
# https://github.com/travis-ci/travis-build/blob/e9314616e182a23e6a280199cd9070bfc7cae548/lib/travis/build/script/templates/header.sh#L34-L53
travis_retry() {
local result=0
local count=1
while [ $count -le 3 ]; do
[ $result -ne 0 ] && {
echo -e "\n\033[33;1mThe command \"$@\" failed. Retrying, $count of 3.\033[0m\n" >&2
}
"$@"
result=$?
[ $result -eq 0 ] && break
count=$(($count + 1))
sleep 1
done

[ $count -eq 3 ] && {
echo "\n\033[33;1mThe command \"$@\" failed 3 times.\033[0m\n" >&2
}

return $result
}

function is_mri {
if ruby -e "exit(!defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby')"; then
# RUBY_ENGINE only returns 'ruby' on MRI.
# MRI 1.8.7 lacks the constant but all other rubies have it (including JRuby in 1.8 mode)
return 0
else
return 1
fi;
}

function is_mri_192 {
if is_mri; then
if ruby -e "exit(RUBY_VERSION == '1.9.2')"; then
return 0
else
return 1
fi
else
return 1
fi
}

function rspec_support_compatible {
if [ "$MAINTENANCE_BRANCH" != "2-99-maintenance" ] && [ "$MAINTENANCE_BRANCH" != "2-14-maintenance" ]; then
return 0
else
return 1
fi
}

function documentation_enforced {
if [ -x ./bin/yard ]; then
return 0
else
return 1
fi
}

function style_and_lint_enforced {
if [ -x ./bin/rubocop ]; then
return 0
else
return 1
fi
}

function clone_repo {
if [ ! -d $1 ]; then # don't clone if the dir is already there
travis_retry eval "git clone git://github.com/rspec/$1 --depth 1 --branch $MAINTENANCE_BRANCH"
Expand All @@ -90,6 +24,7 @@ function run_specs_and_record_done {
rspec_bin=script/rspec_with_simplecov
fi;

echo "${PWD}/bin/rspec"
$rspec_bin spec --backtrace --format progress --profile --format progress --out $SPECS_HAVE_RUN_FILE
}

Expand All @@ -102,6 +37,8 @@ function run_cukes {
# spec failures in our spec suite due to problems with this mode.
export JAVA_OPTS='-client -XX:+TieredCompilation -XX:TieredStopAtLevel=1'

echo "${PWD}/bin/cucumber"

if is_mri_192; then
# For some reason we get SystemStackError on 1.9.2 when using
# the bin/cucumber approach below. That approach is faster
Expand All @@ -118,17 +55,17 @@ function run_cukes {
}

function run_specs_one_by_one {
echo "Running each spec file, one-by-one..."

for file in `find spec -iname '*_spec.rb'`; do
bin/rspec $file -b --format progress
done
}

function run_spec_suite_for {
if [ ! -f ../$1/$SPECS_HAVE_RUN_FILE ]; then # don't rerun specs that have already run
pushd ../$1
echo
echo "Running specs for $1"
echo
pushd ../$1
unset BUNDLE_GEMFILE
bundle_install_flags=`cat .travis.yml | grep bundler_args | tr -d '"' | grep -o " .*"`
travis_retry eval "bundle install $bundle_install_flags"
Expand All @@ -138,8 +75,11 @@ function run_spec_suite_for {
}

function check_documentation_coverage {
echo "bin/yard stats --list-undoc"

bin/yard stats --list-undoc | ruby -e "
while line = gets
has_warnings ||= line.start_with?('[warn]:')
coverage ||= line[/([\d\.]+)% documented/, 1]
puts line
end
Expand All @@ -148,21 +88,27 @@ function check_documentation_coverage {
puts \"\n\nMissing documentation coverage (currently at #{coverage}%)\"
exit(1)
end
if has_warnings
puts \"\n\nYARD emitted documentation warnings.\"
exit(1)
end
"
}

function check_style_and_lint {
echo "bin/rubucop lib"
bin/rubocop lib
}

function run_all_spec_suites {
run_specs_one_by_one
run_spec_suite_for "rspec-core"
run_spec_suite_for "rspec-expectations"
run_spec_suite_for "rspec-mocks"
run_spec_suite_for "rspec-rails"
fold "one-by-one specs" run_specs_one_by_one
fold "rspec-core specs" run_spec_suite_for "rspec-core"
fold "rspec-expectations specs" run_spec_suite_for "rspec-expectations"
fold "rspec-mocks specs" run_spec_suite_for "rspec-mocks"
fold "rspec-rails specs" run_spec_suite_for "rspec-rails"

if rspec_support_compatible; then
run_spec_suite_for "rspec-support"
fold "rspec-support specs" run_spec_suite_for "rspec-support"
fi
}
48 changes: 48 additions & 0 deletions script/predicate_functions.sh
@@ -0,0 +1,48 @@
# This file was generated on 2014-10-30T08:23:40-07:00 from the rspec-dev repo.
# DO NOT modify it by hand as your changes will get lost the next time it is generated.

function is_mri {
if ruby -e "exit(!defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby')"; then
# RUBY_ENGINE only returns 'ruby' on MRI.
# MRI 1.8.7 lacks the constant but all other rubies have it (including JRuby in 1.8 mode)
return 0
else
return 1
fi;
}

function is_mri_192 {
if is_mri; then
if ruby -e "exit(RUBY_VERSION == '1.9.2')"; then
return 0
else
return 1
fi
else
return 1
fi
}

function rspec_support_compatible {
if [ "$MAINTENANCE_BRANCH" != "2-99-maintenance" ] && [ "$MAINTENANCE_BRANCH" != "2-14-maintenance" ]; then
return 0
else
return 1
fi
}

function documentation_enforced {
if [ -x ./bin/yard ]; then
return 0
else
return 1
fi
}

function style_and_lint_enforced {
if [ -x ./bin/rubocop ]; then
return 0
else
return 1
fi
}
12 changes: 6 additions & 6 deletions script/run_build
@@ -1,24 +1,24 @@
#!/bin/bash
# This file was generated on 2014-09-26T16:56:14+10:00 from the rspec-dev repo.
# This file was generated on 2014-10-30T08:23:40-07:00 from the rspec-dev repo.
# DO NOT modify it by hand as your changes will get lost the next time it is generated.

set -e -x
set -e
source script/functions.sh

# Allow repos to override the default functions and add their own
if [ -f script/custom_build_functions.sh ]; then
source script/custom_build_functions.sh
fi

run_specs_and_record_done
run_cukes
fold "specs" run_specs_and_record_done
fold "cukes" run_cukes

if documentation_enforced; then
check_documentation_coverage
fold "doc check" check_documentation_coverage
fi

if style_and_lint_enforced; then
check_style_and_lint
fold "rubocop" check_style_and_lint
fi

if is_mri; then
Expand Down
66 changes: 66 additions & 0 deletions script/travis_functions.sh
@@ -0,0 +1,66 @@
# This file was generated on 2014-10-30T08:23:40-07:00 from the rspec-dev repo.
# DO NOT modify it by hand as your changes will get lost the next time it is generated.

# Taken from:
# https://github.com/travis-ci/travis-build/blob/e9314616e182a23e6a280199cd9070bfc7cae548/lib/travis/build/script/templates/header.sh#L34-L53
travis_retry() {
local result=0
local count=1
while [ $count -le 3 ]; do
[ $result -ne 0 ] && {
echo -e "\n\033[33;1mThe command \"$@\" failed. Retrying, $count of 3.\033[0m\n" >&2
}
"$@"
result=$?
[ $result -eq 0 ] && break
count=$(($count + 1))
sleep 1
done

[ $count -eq 3 ] && {
echo "\n\033[33;1mThe command \"$@\" failed 3 times.\033[0m\n" >&2
}

return $result
}

# Taken from https://github.com/vcr/vcr/commit/fa96819c92b783ec0c794f788183e170e4f684b2
# and https://github.com/vcr/vcr/commit/040aaac5370c68cd13c847c076749cd547a6f9b1
nano_cmd="$(type -p gdate date | head -1)"
nano_format="+%s%N"
[ "$(uname -s)" != "Darwin" ] || nano_format="${nano_format/%N/000000000}"

travis_time_start() {
travis_timer_id=$(printf %08x $(( RANDOM * RANDOM )))
travis_start_time=$($nano_cmd -u "$nano_format")
printf "travis_time:start:%s\r\e[0m" $travis_timer_id
}

travis_time_finish() {
local travis_end_time=$($nano_cmd -u "$nano_format")
local duration=$(($travis_end_time-$travis_start_time))
printf "travis_time:end:%s:start=%s,finish=%s,duration=%s\r\e[0m" \
$travis_timer_id $travis_start_time $travis_end_time $duration
}

fold() {
local name="$1"
local status=0
shift 1
if [ -n "$TRAVIS" ]; then
printf "travis_fold:start:%s\r\e[0m" "$name"
travis_time_start
fi

"$@" || status=$?

[ -z "$TRAVIS" ] || travis_time_finish

if [ "$status" -eq 0 ]; then
if [ -n "$TRAVIS" ]; then
printf "travis_fold:end:%s\r\e[0m" "$name"
fi
else
STATUS="$status"
fi
}

0 comments on commit 81305b9

Please sign in to comment.