lib/auto_rails_cleanup/runner.rb
###
# capture build targetting specific commit to avoid capturing previous build results
###
capture build targetting specific commit to avoid capturing previous build results
capture build targetting specific commit to avoid capturing previous build results
def capture_build
    cmd =  if ENV['CAPTURE_CURRENTLY_RUNNING']
      "curl 'https://circleci.com/api/v1.1/project/github/#{ORG}/#{PROJECT}/tree/#{BRANCH}?circle-token=#{CIRCLE_TOKEN}&limit=20'"
    else
      "curl 'https://circleci.com/api/v1.1/project/github/#{ORG}/#{PROJECT}/tree/#{BRANCH}?circle-token=#{CIRCLE_TOKEN}&limit=9'"
    end
    puts cmd
    data = `#{cmd}`
    data = JSON.parse(data)
    if ENV['CAPTURE_CURRENTLY_RUNNING']
      data.reject!{ |i| (i['all_commit_details'].first==nil || !i['all_commit_details'].last['commit'].starts_with?(ENV['CAPTURE_CURRENTLY_RUNNING'])) }
    else
      data.reject!{ |i| i['start_time'].nil? || Time.iso8601(i['start_time']).to_i < (@last_built_at + 10) }
    end
    tests_jobs = data.select{ |job| JOBS.include?(job['workflows']['job_name']) }
    metric_job = data.select{ |job| job['workflows']['job_name']==JOBS.first }.first
    raise "one of the jobs isn't running yet" unless tests_jobs.length == JOBS.length
    tests_jobs.each do |job|
       raise "still running #{job}" unless (job['outcome']=='success' || job['outcome']=='failed')
    end
    outcome = if JOBS_ALL_PASS
                tests_jobs.select { |job| job['outcome']=='success' }.length == JOBS.length ? 'success' : 'failed'
              else
                metric_job['outcome']
              end
    puts "recording: #{outcome}"
    @stats << outcome
    @times << Time.iso8601(metric_job['stop_time']) - Time.iso8601(metric_job['start_time'])
  rescue => err
    puts "waiting, #{err}"
    sleep(15)
    retry
  end
def capture_build cmd = if ENV [ 'CAPTURE_CURRENTLY_RUNNING' ] "curl 'https://circleci.com/api/v1.1/project/github/#{ORG}/#{PROJECT}/tree/#{BRANCH}?circle-token=#{CIRCLE_TOKEN}&limit=20'" else "curl 'https://circleci.com/api/v1.1/project/github/#{ORG}/#{PROJECT}/tree/#{BRANCH}?circle-token=#{CIRCLE_TOKEN}&limit=9'" end puts cmd data = ` #{ cmd } ` data = JSON . parse ( data ) if ENV [ 'CAPTURE_CURRENTLY_RUNNING' ] data . reject! { | i | ( i [ 'all_commit_details' ] . first == nil || ! i [ 'all_commit_details' ] . last [ 'commit' ] . starts_with? ( ENV [ 'CAPTURE_CURRENTLY_RUNNING' ] ) ) } else data . reject! { | i | i [ 'start_time' ] . nil? || Time . iso8601 ( i [ 'start_time' ] ) . to_i < ( @last_built_at + 10 ) } end tests_jobs = data . select { | job | JOBS . include? ( job [ 'workflows' ] [ 'job_name' ] ) } metric_job = data . select { | job | job [ 'workflows' ] [ 'job_name' ] == JOBS . first } . first raise "one of the jobs isn't running yet" unless tests_jobs . length == JOBS . length tests_jobs . each do | job | raise "still running #{job}" unless ( job [ 'outcome' ] == 'success' || job [ 'outcome' ] == 'failed' ) end outcome = if JOBS_ALL_PASS tests_jobs . select { | job | job [ 'outcome' ] == 'success' } . length == JOBS . length ? 'success' : 'failed' else metric_job [ 'outcome' ] end puts "recording: #{outcome}" @stats << outcome @times << Time . iso8601 ( metric_job [ 'stop_time' ] ) - Time . iso8601 ( metric_job [ 'start_time' ] ) rescue => err puts "waiting, #{err}" sleep ( 15 ) retry end
capture build targetting specific commit to avoid capturing previous build results
capture build targetting specific commit to avoid capturing previous build results
# limit is current HB total workflow #TODO dont need increased limit # ignore all builds that aren't the current git sha