Module: MswinBuild

Defined in:
lib/mswin-build/upload.rb,
lib/mswin-build/builder.rb,
lib/mswin-build/version.rb,
lib/mswin-build/process_tree.rb

Defined Under Namespace

Modules: ProcessTree Classes: Builder

Constant Summary collapse

VERSION =
"1.3.3"

Class Method Summary collapse

Class Method Details

.add_upload_hook(&block) ⇒ Object



37
38
39
# File 'lib/mswin-build/upload.rb', line 37

def self.add_upload_hook(&block)
  @upload_hooks << block
end

.azure_upload(service, logdir) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/mswin-build/upload.rb', line 79

def self.azure_upload(service, logdir)
  logdir = File.dirname(File.join(logdir, 'dummy'))
  branch = File.basename(logdir)
  container = File.basename(File.dirname(logdir))
  begin
    _res, body = service.get_blob(container, "#{branch}/recent.html")
    server_start_time = body[/^<a href=.*+ name="(\w+)">/, 1]
  rescue Azure::Core::Http::HTTPError => e
    server_start_time = '00000000T000000Z'
    if e.type == 'ContainerNotFound'
      service.create_container(container, :public_access_level => 'container')
    end
  end
  puts "Azure: #{branch} start_time: #{server_start_time}" if $DEBUG

  IO.foreach("#{logdir}/recent.html") do |line|
    break line[/^<a href=.*+ name="(\w+)">/, 1]
  end

  Dir.foreach(File.join(logdir, "log")).each do |file|
    next unless file.end_with?('.gz')
    blobname = File.join(branch, "log", file)
    filepath = File.join(logdir, "log", file)
    if (service.(container, blobname) rescue false)
      File.unlink filepath
      next
    end
    if azure_upload_file(service, container, blobname, filepath)
      File.unlink filepath
    end
  end

  %w"summary.html recent.html".each do |file|
    blobname = File.join(branch, file)
    filepath = File.join(logdir, file)
    azure_upload_file(service, container, blobname, filepath)
  end
end

.azure_upload_file(service, container, blobname, filepath) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/mswin-build/upload.rb', line 118

def self.azure_upload_file(service, container, blobname, filepath)
  unless File.exist?(filepath)
    puts "File '#{filepath}' is not found"
    return false
  end

  options = {}
  case filepath
  when /\.html\.gz\z/
    options[:content_type] = "text/html"
    options[:content_encoding] = "gzip"
  when /\.html\z/
    options[:content_type] = "text/html"
  end

  open(filepath, 'rb') do |f|
    puts "uploading '#{filepath}' as '#{blobname}'..." if $DEBUG
    service.create_block_blob(container, blobname, f, options)
  end
  true
end

.register_azure_upload(logdir) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/mswin-build/upload.rb', line 51

def self.register_azure_upload(logdir)
  ENV['AZURE_STORAGE_ACCOUNT'] ||= 'rubyci'
  raise 'no AZURE_STORAGE_ACCESS_KEY env' unless ENV['AZURE_STORAGE_ACCESS_KEY']

  require 'azure'
  require_relative 'azure-patch'
  service = Azure::BlobService.new
  service.with_filter do |req, _next|
    i = 0
    begin
      next _next.call
    rescue
      case $!
      when Errno::ETIMEOUT
        if i < 3
          i += 1
          retry
        end
      end
      raise $!
    end
  end

  add_upload_hook do
    azure_upload(service, logdir)
  end
end

.run_upload_hooksObject



41
42
43
44
45
46
47
48
49
# File 'lib/mswin-build/upload.rb', line 41

def self.run_upload_hooks
  @upload_hooks.reverse_each do |block|
    begin
      block.call
    rescue Exception
      p $!
    end
  end
end