Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

stuff

  • Loading branch information...
commit bf2e6a407aa56ac808d12f356b986d570a43132f 1 parent 1f84a2e
Sven Fuchs svenfuchs authored
2  lib/travis/build.rb
View
@@ -11,7 +11,7 @@ module Build
BUILD_DIR = '~/build'
LOGS = {
- build: '~/build.log',
+ logs: '~/build.log',
state: '~/state.log'
}
2  lib/travis/build/data.rb
View
@@ -35,7 +35,7 @@ def [](key)
end
def urls
- config[:urls]
+ config[:urls] || {}
end
def timeout?(type)
4 lib/travis/build/script.rb
View
@@ -40,12 +40,12 @@ class Script
def initialize(data)
@data = Data.new({ config: self.class::DEFAULTS }.deep_merge(data.deep_symbolize_keys))
- @stack = [Shell::Script.new(log: true, echo: true, log_file: LOGS[:build])]
+ @stack = [Shell::Script.new(log: true, echo: true, log_file: LOGS[:logs])]
end
def compile
+ raw template 'report.sh'
raw template 'header.sh'
- raw template 'stream.sh'
run_stages
raw template 'footer.sh'
sh.to_s
2  lib/travis/build/script/stages.rb
View
@@ -45,7 +45,7 @@ def stage(stage = nil)
sh.options.update(timeout: timeout_for(stage), assert: assert_stage?(stage))
raw "travis_start '#{stage}'" if announce?(stage)
yield
- raw "travis_end '#{stage}'" if announce?(stage)
+ raw "travis_finish '#{stage}'" if announce?(stage)
}
end
2  lib/travis/build/script/templates/footer.sh
View
@@ -1,2 +1,2 @@
-echo "\n\nDone. Build script exited with $TRAVIS_TEST_RESULT" >> <%= LOGS[:build] %>
+echo "\n\nDone. Build script exited with $TRAVIS_TEST_RESULT" >> <%= LOGS[:logs] %>
exit $TRAVIS_TEST_RESULT
19 lib/travis/build/script/templates/header.sh
View
@@ -1,16 +1,15 @@
travis_start() {
- echo "`date +%s.%N` [$1] start" >> <%= LOGS[:state] %>
+ echo "`date +%s.%N` [$1:start]" >> <%= LOGS[:state] %>
}
-travis_end() {
- echo "`date +%s.%N` [$1] end, result: $?" >> <%= LOGS[:state] %>
+travis_finish() {
+ echo "`date +%s.%N` [$1:finish] result: $?" >> <%= LOGS[:state] %>
}
travis_assert() {
if [ $? != 0 ]; then
- echo "Command did not exit with 0. Exiting." >> <%= LOGS[:build] %>
- echo "`date +%s.%N` Command did not exit with 0. Exiting." >> <%= LOGS[:state] %>
- kill $$
+ echo "Command did not exit with 0. Exiting." >> <%= LOGS[:logs] %>
+ exit 1
fi
}
@@ -19,9 +18,9 @@ travis_timeout() {
local start=$(date +%s)
while ps aux | awk '{print $2 }' | grep -q $pid 2> /dev/null; do
if [ $(expr $(date +%s) - $start) -gt $1 ]; then
- echo "Command timed out after $1 seconds. Exiting." >> <%= LOGS[:build] %>
+ echo "Command timed out after $1 seconds. Exiting." >> <%= LOGS[:logs] %>
kill -9 $pid
- kill $$
+ exit 1
fi
done
wait $pid
@@ -33,3 +32,7 @@ cd <%= BUILD_DIR %>
<%= LOGS.map { |name, path| "touch #{path}; > #{path}" }.join("\n") %>
+trap 'travis_finish build' EXIT
+trap 'travis_finish build' TERM
+
+travis_start build
8 lib/travis/build/script/templates/report.sh
View
@@ -0,0 +1,8 @@
+<% [:logs, :state].each do |type| %>
+ <% if data.urls[type] %>
+ echo <%= Shellwords.escape(template("report_#{type}.rb")) %> > ~/travis_report_<%= type %>
+ chmod +x ~/travis_report_<%= type %>
+ ~/travis_report_<%= type %> <%= LOGS[type] %> <%= data.urls[type] %> &
+ <% end %>
+<% end %>
+
1  lib/travis/build/script/templates/stream.rb → lib/travis/build/script/templates/report_logs.rb
View
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
+
require 'net/http'
require 'uri'
43 lib/travis/build/script/templates/report_state.rb
View
@@ -0,0 +1,43 @@
+#!/usr/bin/env ruby
+
+require 'net/http'
+require 'uri'
+require 'json'
+
+source, target = ARGV
+target = URI.parse(target)
+
+file = File.open(source, 'r+')
+last_state, last_stage = nil, nil
+
+post = ->(data) do
+ p data
+ Net::HTTP.post_form(target, data)
+end
+
+on_start = ->(line) do
+ post.call(event: :start, started_at: Time.now, worker: `hostname`)
+end
+
+on_finish = ->(line, result) do
+ state = last_state == 'start' ? :errored : (result == 0 ? :passed : :failed)
+ data = { event: :finish, state: state, finished_at: Time.now }
+ data[:error] = :"#{last_stage}_failed" if state == :errored
+ post.call(data)
+end
+
+report = ->(line) do
+ case line
+ when /\[build:start\]/
+ on_start.call(line)
+ when /\[build:finish\] result: ([\d]+)/
+ on_finish.call(line, $1.to_i)
+ when /\[(.+):(.+)\]/
+ last_stage, last_state = $1, $2
+ end
+end
+
+loop do
+ sleep 0.1 while file.eof?
+ report.call(file.readline)
+end
10 lib/travis/build/script/templates/stream.sh
View
@@ -1,10 +0,0 @@
-echo <%= Shellwords.escape(template('stream.rb')) %> > ~/travis_stream
-chmod +x ~/travis_stream
-
-<% if data.urls[:logs] %>
- ~/travis_stream <%= LOGS[:build] %> <%= data.urls[:logs] %> &
-<% end %>
-<% if data.urls[:state] %>
- ~/travis_stream <%= LOGS[:state] %> <%= data.urls[:state] %> &
-<% end %>
-
138 play/build.sh
View
@@ -1,16 +1,97 @@
+
+
+ echo \#\!/usr/bin/env\ ruby'
+''
+'require\ \'net/http\''
+'require\ \'uri\''
+''
+'source,\ target,\ interval\ \=\ ARGV'
+'target\ \=\ URI.parse\(target\)'
+'interval\ \|\|\=\ 1'
+''
+'file\ \=\ File.open\(source,\ \'r\+\'\)'
+'buff\ \=\ \'\''
+''
+'post\ \=\ -\>\(data\)\ do'
+'\ \ Net::HTTP.post_form\(target,\ log:\ data\)'
+'end'
+''
+'at_exit\ do'
+'\ \ file.close'
+'\ \ post.call\(buff\)'
+'end'
+''
+'loop\ do'
+'\ \ buff\ \<\<\ file.getc\ until\ file.eof\?'
+'\ \ post.call\(buff\)\ unless\ buff.empty\?'
+'\ \ buff.clear'
+'\ \ sleep\ interval'
+'end'
+''
+' > ~/travis_report_logs
+ chmod +x ~/travis_report_logs
+ ~/travis_report_logs ~/build.log http://localhost:3000/jobs/1/logs &
+
+
+
+ echo \#\!/usr/bin/env\ ruby'
+''
+'require\ \'net/http\''
+'require\ \'uri\''
+'require\ \'json\''
+''
+'source,\ target\ \=\ ARGV'
+'target\ \=\ URI.parse\(target\)'
+''
+'file\ \=\ File.open\(source,\ \'r\+\'\)'
+'last_state,\ last_stage\ \=\ nil,\ nil'
+''
+'post\ \=\ -\>\(data\)\ do'
+'\ \ Net::HTTP.post_form\(target,\ data\)'
+'end'
+''
+'on_start\ \=\ -\>\(line\)\ do'
+'\ \ post.call\(event:\ :start,\ started_at:\ Time.now,\ worker:\ \`hostname\`\)'
+'end'
+''
+'on_finish\ \=\ -\>\(line,\ result\)\ do'
+'\ \ state\ \=\ last_state\ \=\=\ \'start\'\ \?\ :errored\ :\ result\ \=\=\ 0\ \?\ :passed\ :\ :failed'
+'\ \ post.call\(event:\ :finish,\ state:\ state,\ finished_at:\ Time.now\)'
+'end'
+''
+'report\ \=\ -\>\(line\)\ do'
+'\ \ p\ line'
+'\ \ case\ line'
+'\ \ when\ /\\\[build:start\\\]/'
+'\ \ \ \ on_start.call\(line\)'
+'\ \ when\ /\\\[build:finish\\\]\ result:\ \(\[\\d\]\+\)/'
+'\ \ \ \ on_finish.call\(line,\ \$1.to_i\)'
+'\ \ when\ /\\\[\(.\+\):\(.\+\)\\\]/'
+'\ \ \ \ last_stage,\ last_state\ \=\ \$1,\ \$2'
+'\ \ \ \ p\ last_stage'
+'\ \ end'
+'end'
+''
+'loop\ do'
+'\ \ sleep\ 0.1\ while\ file.eof\?'
+'\ \ report.call\(file.readline\)'
+'end'
+' > ~/travis_report_state
+ chmod +x ~/travis_report_state
+ ~/travis_report_state ~/state.log http://localhost:3000/jobs/1/state &
+
travis_start() {
- echo "`date +%s.%N` [$1] start" >> ~/state.log
+ echo "`date +%s.%N` [$1:start]" >> ~/state.log
}
-travis_end() {
- echo "`date +%s.%N` [$1] end, result: $?" >> ~/state.log
+travis_finish() {
+ echo "`date +%s.%N` [$1:finish] result: $?" >> ~/state.log
}
travis_assert() {
if [ $? != 0 ]; then
echo "Command did not exit with 0. Exiting." >> ~/build.log
- echo "`date +%s.%N` Command did not exit with 0. Exiting." >> ~/state.log
- kill $$
+ exit 1
fi
}
@@ -21,7 +102,7 @@ travis_timeout() {
if [ $(expr $(date +%s) - $start) -gt $1 ]; then
echo "Command timed out after $1 seconds. Exiting." >> ~/build.log
kill -9 $pid
- kill $$
+ exit 1
fi
done
wait $pid
@@ -33,38 +114,11 @@ cd ~/build
touch ~/build.log; > ~/build.log
touch ~/state.log; > ~/state.log
-echo \#\!/usr/bin/env\ ruby'
-'require\ \'net/http\''
-'require\ \'uri\''
-''
-'source,\ target,\ interval\ \=\ ARGV'
-'target\ \=\ URI.parse\(target\)'
-'interval\ \|\|\=\ 1'
-''
-'file\ \=\ File.open\(source,\ \'r\+\'\)'
-'buff\ \=\ \'\''
-''
-'post\ \=\ -\>\(data\)\ do'
-'\ \ Net::HTTP.post_form\(target,\ log:\ data\)'
-'end'
-''
-'at_exit\ do'
-'\ \ file.close'
-'\ \ post.call\(buff\)'
-'end'
-''
-'loop\ do'
-'\ \ buff\ \<\<\ file.getc\ until\ file.eof\?'
-'\ \ post.call\(buff\)\ unless\ buff.empty\?'
-'\ \ buff.clear'
-'\ \ sleep\ interval'
-'end'
-''
-' > ~/travis_stream
-chmod +x ~/travis_stream
+trap 'travis_finish build' EXIT
+trap 'travis_finish build' TERM
- ~/travis_stream ~/build.log http://localhost:3000/jobs/1/logs &
+travis_start build
travis_start 'export'
TRAVIS_PULL_REQUEST=false
TRAVIS_SECURE_ENV_VARS=false
@@ -76,7 +130,7 @@ TRAVIS_BRANCH=master
TRAVIS_COMMIT=a214c21
TRAVIS_COMMIT_RANGE=abcdefg..a214c21
TRAVIS_RUBY_VERSION=1.9.3
-travis_end 'export'
+travis_finish 'export'
travis_start 'checkout'
GIT_ASKPASS=echo
@@ -97,7 +151,7 @@ if [[ -s .gitmodules ]]; then
travis_timeout 300
travis_assert
fi
-travis_end 'checkout'
+travis_finish 'checkout'
travis_start 'setup'
echo \$\ rvm\ use\ 1.9.3 >> ~/build.log 2>&1
@@ -106,7 +160,7 @@ travis_assert
if [[ -f Gemfile ]]; then
BUNDLE_GEMFILE=$pwd/Gemfile
fi
-travis_end 'setup'
+travis_finish 'setup'
travis_start 'announce'
echo \$\ java\ -version >> ~/build.log 2>&1
@@ -117,7 +171,7 @@ echo \$\ ruby\ --version >> ~/build.log 2>&1
(ruby --version) >> ~/build.log 2>&1
echo \$\ gem\ --version >> ~/build.log 2>&1
(gem --version) >> ~/build.log 2>&1
-travis_end 'announce'
+travis_finish 'announce'
travis_start 'install'
if [[ -f Gemfile ]]; then
@@ -126,7 +180,7 @@ if [[ -f Gemfile ]]; then
travis_timeout 600
travis_assert
fi
-travis_end 'install'
+travis_finish 'install'
travis_start 'script'
if [[ -f Gemfile ]]; then
@@ -139,7 +193,7 @@ else
travis_timeout 1500
fi
TRAVIS_TEST_RESULT=$?
-travis_end 'script'
+travis_finish 'script'
2  play/compile.rb
View
@@ -6,7 +6,7 @@
data = {
urls: {
logs: 'http://localhost:3000/jobs/1/logs',
- # state: 'http://localhost:3000/jobs/1/state', # not sure about this ...
+ state: 'http://localhost:3000/jobs/1/state', # not sure about this ...
},
repository: {
source_url: 'http://github.com/travis-ci/travis-support.git'
2  spec/spec_helper.rb
View
@@ -16,7 +16,7 @@ def deep_clone
end
Travis::Build::Script::TEMPLATES_PATH.replace 'spec/templates'
-Travis::Build::LOGS.replace(build: 'build.log', state: 'state.log')
+Travis::Build::LOGS.replace(logs: 'build.log', state: 'state.log')
Travis::Build::HOME_DIR.replace('.')
module SpecHelpers
3  travis-build.gemspec
View
@@ -1,11 +1,10 @@
# encoding: utf-8
$:.unshift File.expand_path('../lib', __FILE__)
-require 'travis/build/version'
Gem::Specification.new do |s|
s.name = 'travis-build'
- s.version = Travis::Build::VERSION
+ s.version = '0.0.1'
s.authors = ['Sven Fuchs', 'Josh Kalderimis', 'Michael Klishin']
s.email = 'contact@travis-ci.org'
s.homepage = 'http://github.com/travis-ci/travis-build'
Please sign in to comment.
Something went wrong with that request. Please try again.