Sha256: e69d837f8192c7d0f6359330887af9ccb668b0cc32774b29ee5f531ea83b1ae9

Contents?: true

Size: 938 Bytes

Versions: 1

Compression:

Stored size: 938 Bytes

Contents

require "travis_parallel_sentinel/version"
require 'open-uri'
require 'json'

TRAVIS_JOB_NUMBER = ENV['TRAVIS_JOB_NUMBER'].to_s.strip
TRAVIS_BUILD_ID   = ENV['TRAVIS_BUILD_ID'].to_s.strip

module TravisParallelSentinel
  def status(include_deployer=false)
    return :deploy  if TRAVIS_JOB_NUMBER == '' # no build matrix, so good to go
    return :ok      unless TRAVIS_JOB_NUMBER =~ /\.1$/ # first job in the sequence is the deployment container

    while true
      builds = JSON.parse(open("https://api.travis-ci.org/builds/#{TRAVIS_BUILD_ID}").read)
      jobs = status['matrix'].select{|job| job['number'] != TRAVIS_JOB_NUMBER || include_deployer}.collect{|job| job['result']}
      if jobs.detect{|s| s.nil?}
        puts "waiting... #{jobs.inspect}"
        sleep 5
      elsif jobs.detect{|s| s != 0}
        throw "One or more jobs failed"
      else
        return :deploy
      end
    end
  end
  module_function :status
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
travis_parallel_sentinel-0.1.5 lib/travis_parallel_sentinel.rb