-
Notifications
You must be signed in to change notification settings - Fork 62
/
entrypoint.rb
executable file
·47 lines (40 loc) · 1.55 KB
/
entrypoint.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
#!/usr/bin/env ruby
require "net/http"
require "uri"
require "json"
REPO = ENV["GITHUB_REPOSITORY"]
def query_check_status(ref, check_name, token)
uri = URI.parse("https://api.github.com/repos/#{REPO}/commits/#{ref}/check-runs?check_name=#{check_name}")
request = Net::HTTP::Get.new(uri)
request["Accept"] = "application/vnd.github.antiope-preview+json"
request["Authorization"] = "token #{token}"
req_options = {
use_ssl: uri.scheme == "https"
}
response = Net::HTTP.start(uri.hostname, uri.port, req_options) { |http|
http.request(request)
}
parsed = JSON.parse(response.body)
return [nil, nil] if parsed["total_count"].zero?
[
parsed["check_runs"][0]["status"],
parsed["check_runs"][0]["conclusion"]
]
end
# check_name is the name of the "job" key in a workflow, or the full name if the "name" key
# is provided for job. Probably, the "name" key should be kept empty to keep things short
ref, check_name, token, wait = ARGV
wait = wait.to_i
current_status, conclusion = query_check_status(ref, check_name, token)
if current_status.nil?
puts "The requested check was never run against this ref, exiting..."
exit(false)
end
while current_status == "queued" || current_status == "in_progress"
puts "The requested check hasn't completed yet, will check back in #{wait} seconds..."
sleep(wait)
current_status, conclusion = query_check_status(ref, check_name, token)
end
puts "Check completed with a status #{current_status}, and conclusion #{conclusion}"
# Bail if check is not success
exit(false) unless conclusion == "success"