-
Notifications
You must be signed in to change notification settings - Fork 26
/
diff.rb
43 lines (34 loc) · 974 Bytes
/
diff.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
# frozen_string_literal: true
require "diffy"
module Buildkite::Config
module Diff
def self.compare
head = generated_pipeline(Dir.pwd)
main = generated_pipeline(File.expand_path("tmp/buildkite-config", Dir.pwd))
Diffy::Diff.new(main, head, context: 4)
end
def self.generated_pipeline(repo)
File.symlink(repo, "tmp/rails/.buildkite")
Dir.chdir("tmp/rails") do
bin = if File.exist?(".buildkite/bin/pipeline-generate")
".buildkite/bin/pipeline-generate"
else
".buildkite/pipeline-generate"
end
command = ["ruby", bin]
pipeline = "rails-ci"
command.push(pipeline)
io = IO.popen(command)
output = io.read
io.close
unless $?.success?
$stderr.puts "Failed to generate pipeline for #{repo}"
return ""
end
output
end
ensure
File.unlink("tmp/rails/.buildkite")
end
end
end