This repository has been archived by the owner on Nov 1, 2017. It is now read-only.
/
gem_builder.rb
64 lines (55 loc) · 1.91 KB
/
gem_builder.rb
1
2
3
4
5
6
7
8
9
10
11
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
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env ruby
require 'rubygems/specification'
require 'rubygems/builder'
require 'rubygems/package'
require 'fileutils'
class GemBuildError < StandardError
end
Gem::Builder.class_eval do
def build(repository)
@spec.mark_version
@signer = sign
write_package_with_git(repository)
end
def write_package_with_git(repository)
tmp_path = File.join('/data/github/gems', 'tmp', @spec.file_name)
gem_path = File.join('/data/github/gems', 'gems', @spec.file_name)
open(tmp_path, 'wb') do |gem_io|
Gem::Package.open(gem_io, 'w', @signer) do |pkg|
pkg.metadata = @spec.to_yaml
@spec.files.each do |file|
obj = repository.git.tree('master', file).contents.first rescue nil
next if obj.nil? || obj.is_a?(Grit::Tree)
mode = 0
obj.mode.each_byte { |i| mode = (mode << 3) | i-'0'[0] }
pkg.add_file_simple file, mode & 0777, obj.size do |tar_io|
tar_io.write obj.data
end
end
end
end
FileUtils.mv(tmp_path, gem_path, :force => true)
end
end
def process(repository, path)
return unless content = repository.git.tree('master', path).contents.first
data = content.data
if data !~ %r{!ruby/object:Gem::Specification}
url = URI.parse("http://gem_evaler:4567/")
res = Net::HTTP.post_form(url, { 'repo' => repository.name_with_owner, 'data' => data })
data = res.body
if data.include?('ERROR: ')
data = data.sub('ERROR: ', '')
Message.create \
:to => repository.owner,
:from => (User / :github),
:subject => "[#{repository}] Gem Build Failure",
:body => "The gem build failed with the following error:\n\n#{data}"
raise GemBuildError.new(data)
end
end
spec = Gem::Specification.from_yaml(data)
name = spec.name.gsub(' ', '-')
spec.name = "#{repository.owner}-#{name}"
Gem::Builder.new(spec).build(repository)
end