Instantly share code, notes, and snippets.

Embed
What would you like to do?
S3 concat
require 'aws-sdk'
s3 = Aws::S3::Resource.new(region: ENV['AWS_REGION'])
rspec_bucket = s3.bucket(ENV['RSPEC_BUCKET'])
cukes_bucket = s3.bucket(ENV['CUKES_BUCKET'])
rspec_objects = rspec_bucket.objects(prefix: ENV['CI_BUILD_NUMBER'])
cukes_objects = cukes_bucket.objects(prefix: ENV['CI_BUILD_NUMBER'])
test_group_threshold = ENV['TEST_GROUPS'].to_i
# When the number of logs fall below the test group threshold set above,
# use the logs from the init folder instead
rspec_logs = unless rspec_objects.count < test_group_threshold
puts "Using logs from #{ENV['CI_BUILD_NUMBER']} bucket..."
rspec_objects
else
puts "Using logs from #{ENV['LOG_INIT_BUCKET']} bucket..."
rspec_bucket.objects(prefix: ENV['LOG_INIT_BUCKET'])
end
# When the number of logs fall below the test group threshold set above,
# use the logs from the init folder instead
cukes_logs = unless cukes_objects.count < test_group_threshold
puts "Using logs from #{ENV['CI_BUILD_NUMBER']} bucket..."
cukes_objects
else
puts "Using logs from #{ENV['LOG_INIT_BUCKET']} bucket..."
cukes_bucket.objects(prefix: ENV['LOG_INIT_BUCKET'])
end
File.open(ENV['RSPEC_LOG_PATH'], 'wb') do |file|
rspec_logs.each do |obj|
file << obj.get.body.read
end
end
File.open(ENV['CUCUMBER_LOG_PATH'], 'wb') do |file|
cukes_logs.each do |obj|
file << obj.get.body.read
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment