Commit 4b8a9c0d authored by Mark Lapierre's avatar Mark Lapierre

Merge branch 'acunskis-add-knapsack-log' into 'master'

Fix moving regenerated knapsack report

See merge request gitlab-org/gitlab!77771
parents d344d378 f5e22d6f
......@@ -9,6 +9,7 @@ module QA
PROJECT = "gitlab-qa-resources"
BUCKET = "knapsack-reports"
FALLBACK_REPORT = "knapsack/master_report.json"
def_delegators :new, :configure!, :move_regenerated_report, :download_report, :upload_report
......@@ -35,9 +36,9 @@ module QA
file = client.get_object(BUCKET, report_file)
File.write(report_path, file[:body])
rescue StandardError => e
ENV["KNAPSACK_REPORT_PATH"] = "knapsack/master_report.json"
ENV["KNAPSACK_REPORT_PATH"] = FALLBACK_REPORT
logger.warn("Failed to fetch latest knapsack report: #{e}")
logger.warn("Falling back to 'knapsack/master_report.json'")
logger.warn("Falling back to '#{FALLBACK_REPORT}'")
end
# Rename and move new regenerated report to a separate folder used to indicate report name
......@@ -46,11 +47,13 @@ module QA
def move_regenerated_report
return unless ENV["KNAPSACK_GENERATE_REPORT"] == "true"
path = "tmp/knapsack/#{report_name}"
FileUtils.mkdir_p(path)
tmp_path = "tmp/knapsack/#{report_name}"
FileUtils.mkdir_p(tmp_path)
# Use path from knapsack config in case of fallback to master_report.json
FileUtils.cp(Knapsack.report.report_path, "#{path}/#{ENV['CI_NODE_INDEX']}.json")
knapsack_report_path = Knapsack.report.report_path
logger.debug("Moving regenerated #{knapsack_report_path} to save as artifact")
FileUtils.cp(knapsack_report_path, "#{tmp_path}/#{ENV['CI_NODE_INDEX']}.json")
end
# Merge and upload knapsack report to gcs bucket
......@@ -73,6 +76,8 @@ module QA
report = jsons
.map { |json| JSON.parse(File.read(json)) }
.reduce({}, :merge)
.sort_by { |k, v| v } # sort report by execution time
.to_h
next logger.warn("Knapsack generated empty report for '#{name}', skipping upload!") if report.empty?
logger.info("Uploading latest knapsack report '#{file}'")
......
......@@ -65,12 +65,14 @@ RSpec.configure do |config|
end
config.after(:suite) do |suite|
QA::Tools::KnapsackReport.move_regenerated_report if QA::Runtime::Env.knapsack?
# If any tests failed, leave the resources behind to help troubleshoot
QA::Resource::ReusableProject.remove_all_via_api! unless suite.reporter.failed_examples.present?
end
config.append_after(:suite) do
QA::Tools::KnapsackReport.move_regenerated_report if QA::Runtime::Env.knapsack?
end
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment