Class: DiffuxCIUploader
- Inherits:
-
Object
- Object
- DiffuxCIUploader
- Defined in:
- lib/diffux_ci_uploader.rb
Instance Method Summary collapse
-
#initialize ⇒ DiffuxCIUploader
constructor
A new instance of DiffuxCIUploader.
- #upload_diffs ⇒ Object
Constructor Details
#initialize ⇒ DiffuxCIUploader
Returns a new instance of DiffuxCIUploader.
6 7 8 9 10 |
# File 'lib/diffux_ci_uploader.rb', line 6 def initialize @s3_access_key_id = DiffuxCIUtils.config['s3_access_key_id'] @s3_secret_access_key = DiffuxCIUtils.config['s3_secret_access_key'] @s3_bucket_name = DiffuxCIUtils.config['s3_bucket_name'] end |
Instance Method Details
#upload_diffs ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/diffux_ci_uploader.rb', line 12 def upload_diffs result_summary = YAML.load(File.read(File.join( DiffuxCIUtils.config['snapshots_folder'], 'result_summary.yaml'))) return [] if result_summary[:diff_examples].empty? && result_summary[:new_examples].empty? bucket = find_or_build_bucket dir = SecureRandom.uuid diff_images = result_summary[:diff_examples].map do |diff| image = bucket.objects.build( "#{dir}/#{diff[:description]}_#{diff[:viewport]}.png") image.content = open(DiffuxCIUtils.path_to(diff[:description], diff[:viewport], 'diff.png')) image.content_type = 'image/png' image.save diff[:url] = image.url diff end new_images = result_summary[:new_examples].map do |example| image = bucket.objects.build( "#{dir}/#{example[:description]}_#{example[:viewport]}.png") image.content = open(DiffuxCIUtils.path_to(example[:description], example[:viewport], 'baseline.png')) image.content_type = 'image/png' image.save example[:url] = image.url example end html = bucket.objects.build("#{dir}/index.html") path = File.( File.join(File.dirname(__FILE__), 'diffux_ci-diffs.html.erb')) html.content = ERB.new(File.read(path)).result(binding) html.content_type = 'text/html' html.save html.url end |