mirror of
https://github.com/discourse/discourse.git
synced 2024-12-24 22:54:23 +08:00
fc8075c169
Why this change? `github.job` returns the `job_id` per the docs but it doesn't actually return the id of the job but instead returns the job's name strangely. Per https://github.com/orgs/community/discussions/8945, there is no way to get the `job_id` from the existing contexts in the actions run. Therefore, we have to hit Github's API to fetch it. Not ideal but no way around this.
31 lines
667 B
Ruby
31 lines
667 B
Ruby
#!/usr/bin/env ruby
|
|
# frozen_string_literal: true
|
|
|
|
require "net/http"
|
|
require "json"
|
|
|
|
workflow_run_id = ARGV[0]
|
|
run_attempt = ARGV[1]
|
|
job_name = ARGV[2]
|
|
|
|
uri =
|
|
URI.parse(
|
|
"https://api.github.com/repos/discourse/discourse/actions/runs/#{workflow_run_id}/attempts/#{run_attempt}/jobs",
|
|
)
|
|
|
|
request = Net::HTTP::Get.new(uri)
|
|
request["Accept"] = "application/vnd.github+json"
|
|
request["X-Github-Api-Version"] = "2022-11-28"
|
|
|
|
response =
|
|
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.is_a?(URI::HTTPS)) do |http|
|
|
http.request(request)
|
|
end
|
|
|
|
JSON.parse(response.body)["jobs"].each do |job|
|
|
if job["name"] == job_name
|
|
puts job["id"]
|
|
break
|
|
end
|
|
end
|