Sha256: 84fd8893390c20b16b8f2da72609d2adf8f3dd0c09caf95435518ae715c673f2

Contents?: true

Size: 856 Bytes

Versions: 2

Compression:

Stored size: 856 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?}
        sleep 5
      else
        return jobs.detect{|s| s != 0} ? :failed : :deploy
      end
    end
  end
  module_function :status
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
travis_parallel_sentinel-0.1.4 lib/travis_parallel_sentinel.rb
travis_parallel_sentinel-0.1.2 lib/travis_parallel_sentinel.rb