mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
Can specify workflow run id with --run-id
[skip ci]
This commit is contained in:
+30
-14
@@ -12,7 +12,7 @@ require 'pry'
|
||||
require 'rest-client'
|
||||
require 'yaml'
|
||||
|
||||
GITHUB_API_OPENPROJECT_PREFIX = "https://api.github.com/repos/opf/openproject"
|
||||
GITHUB_API_OPENPROJECT_PREFIX = 'https://api.github.com/repos/opf/openproject'.freeze
|
||||
RAILS_ROOT = Pathname.new(__dir__).dirname
|
||||
SPEC_PATTERN = %r{^\S+ (?:rspec (\S+) #.+|An error occurred while loading (\S+)\.\r?)$}
|
||||
|
||||
@@ -45,6 +45,11 @@ def parse_options
|
||||
options[:compact] = true
|
||||
end
|
||||
|
||||
parser.on("-r RUN_ID", "--run-id RUN_ID", Integer,
|
||||
"The workflow run id to use (in github url: actions/runs/{id})") do |value|
|
||||
options[:run_id] = value
|
||||
end
|
||||
|
||||
parser.on("-h", "--help", "Prints this help") do
|
||||
puts parser
|
||||
exit
|
||||
@@ -55,8 +60,8 @@ def parse_options
|
||||
end
|
||||
|
||||
# Returns current branch
|
||||
def branch_name
|
||||
@branch_name ||= `git rev-parse --abbrev-ref HEAD`.strip
|
||||
def current_branch_name
|
||||
@current_branch_name ||= `git rev-parse --abbrev-ref HEAD`.strip
|
||||
end
|
||||
|
||||
def get_http(path)
|
||||
@@ -175,7 +180,7 @@ def last_with_status(workflow_runs, status)
|
||||
.max_by { |entry| entry['run_number'] }
|
||||
end
|
||||
|
||||
def get_last_test_action
|
||||
def get_last_workflow_run(branch_name)
|
||||
test_workflow_runs =
|
||||
get_json("actions/runs?branch=#{CGI.escape(branch_name)}")
|
||||
.then { |response| response['workflow_runs'] }
|
||||
@@ -184,26 +189,37 @@ def get_last_test_action
|
||||
last_completed = last_with_status(test_workflow_runs, 'completed')
|
||||
last_in_progress = last_with_status(test_workflow_runs, 'in_progress')
|
||||
|
||||
last_completed || last_in_progress
|
||||
last_completed || last_in_progress or raise "No workflow run found for branch #{branch_name}"
|
||||
end
|
||||
|
||||
def get_workflow_run(run_id)
|
||||
if run_id
|
||||
warn "Looking for the workflow run with id #{run_id.to_s.bold}"
|
||||
get_json("actions/runs/#{CGI.escape(run_id.to_s)}")
|
||||
else
|
||||
warn "Looking for the last 'Test suite' workflow run in current branch #{current_branch_name.bold}"
|
||||
get_last_workflow_run(current_branch_name)
|
||||
end
|
||||
end
|
||||
|
||||
def display_workflow_run_info(workflow_run)
|
||||
warn " Branch: #{workflow_run['head_branch'].bold}"
|
||||
warn " Commit SHA: #{workflow_run['head_sha'].bold}"
|
||||
warn " Commit message: #{commit_message(workflow_run).bold}"
|
||||
end
|
||||
|
||||
##########
|
||||
|
||||
options = parse_options
|
||||
|
||||
warn "Looking for the last 'Test suite' workflow run in branch #{branch_name}"
|
||||
workflow_run = get_workflow_run(options[:run_id])
|
||||
|
||||
last_test_action = get_last_test_action
|
||||
|
||||
raise "No action run found for branch #{branch_name}" unless last_test_action
|
||||
|
||||
warn " Commit SHA: #{last_test_action['head_sha']}"
|
||||
warn " Commit message: #{commit_message(last_test_action)}"
|
||||
display_workflow_run_info(workflow_run)
|
||||
|
||||
errors = []
|
||||
is_successful = true
|
||||
warn " #{status_line(last_test_action)}"
|
||||
get_jobs(last_test_action)
|
||||
warn " #{status_line(workflow_run)}"
|
||||
get_jobs(workflow_run)
|
||||
.then { |jobs_response| jobs_response['jobs'] }
|
||||
.sort_by { _1['name'] }
|
||||
.each { |job| warn " #{status_line(job)}" }
|
||||
|
||||
Reference in New Issue
Block a user