Files
jekyll-build-pages/emit_telemetry
Jess Bees 3b1cf2975b
Docker / build (push) Has been cancelled
Move emit_telemetry out of entrypoint
Prepare for emit_telemetry to be invoked as an alternative entrypoint,
rather than as the last command in entrypoint.sh
2022-03-23 14:08:29 -04:00

44 lines
1.2 KiB
Ruby
Executable File

#! /usr/bin/env ruby
require "faraday"
require "faraday/retry"
require "json"
ACTION_NWO = ENV["GITHUB_ACTION_REPOSITORY"]
REPOSITORY_NWO = ENV["GITHUB_REPOSITORY"]
GITHUB_RUN_ID = ENV["GITHUB_RUN_ID"]
GITHUB_TOKEN = ENV["INPUT_TOKEN"]
TELEMETRY_URL = "https://api.github.com/repos/#{REPOSITORY_NWO}/pages/telemetry"
RETRY_COUNT = 3
RETRY_OPTIONS = {
max: RETRY_COUNT,
methods: [:post],
retry_statuses: [500, 502, 503, 504],
interval: 1,
backoff_factor: 2,
}
begin
connection = Faraday.new { |f| f.request :retry, RETRY_OPTIONS }
response = connection.post(
TELEMETRY_URL,
{ github_run_id: GITHUB_RUN_ID }.to_json,
{
Accept: 'application/vnd.github.v3+json',
Authorization: "Bearer #{GITHUB_TOKEN}",
'Content-type': 'application/json',
'User-Agent': "#{ACTION_NWO} Faraday #{Faraday::VERSION}",
},
)
if response.success?
STDERR.puts "Sending telemetry for run id #{GITHUB_RUN_ID}"
else response.success?
STDERR.puts "Failed to emit pages build telemetry to #{TELEMETRY_URL} : returned status code: #{response.status} after #{RETRY_COUNT + 1} attempts"
STDERR.puts response.body if response.body
end
rescue e
STDERR.puts "Failed to emit pages build telemetry: #{e}"
end