Commit 732e30a4 authored by Rémy Coutable's avatar Rémy Coutable

Introduce scripts/prune-old-flaky-specs to prune outdated flaky specs from the report

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent a5c567d2
......@@ -472,6 +472,7 @@ update-tests-metadata:
- scripts/merge-reports ${KNAPSACK_SPINACH_SUITE_REPORT_PATH} knapsack/${CI_PROJECT_NAME}/spinach-pg_node_*.json
- scripts/merge-reports ${EE_KNAPSACK_RSPEC_SUITE_REPORT_PATH} knapsack/${CI_PROJECT_NAME}/rspec-pg-ee_node_*.json
- scripts/merge-reports ${FLAKY_RSPEC_SUITE_REPORT_PATH} rspec_flaky/all_*_*.json
- scripts/prune-old-flaky-specs ${FLAKY_RSPEC_SUITE_REPORT_PATH}
- '[[ -z ${TESTS_METADATA_S3_BUCKET} ]] || scripts/sync-reports put $TESTS_METADATA_S3_BUCKET $KNAPSACK_RSPEC_SUITE_REPORT_PATH $KNAPSACK_SPINACH_SUITE_REPORT_PATH'
- '[[ -z ${TESTS_METADATA_S3_BUCKET} ]] || scripts/sync-reports put $TESTS_METADATA_S3_BUCKET $EE_KNAPSACK_RSPEC_SUITE_REPORT_PATH'
- '[[ -z ${TESTS_METADATA_S3_BUCKET} ]] || scripts/sync-reports put $TESTS_METADATA_S3_BUCKET $FLAKY_RSPEC_SUITE_REPORT_PATH'
......
#!/usr/bin/env ruby
require 'json'
require 'time'
def days_from_now(days)
Time.now - (3600 * 24 * days)
end
report_file = ARGV.shift
unless report_file
puts 'usage: prune-old-flaky-specs <report-file> <new-report-file>'
exit 1
end
new_report_file = ARGV.shift || report_file
puts "Loading #{report_file}..."
report = JSON.parse(File.read(report_file))
old_report_size = report.size
puts "Current report has #{report.size} entries."
report.delete_if { |uid, hash| Time.parse(hash['last_flaky_at']).to_i < days_from_now(90).to_i }
puts "New report has #{report.size} entries: #{old_report_size - report.size} entries older than 90 days were removed."
File.write(new_report_file, JSON.pretty_generate(report))
puts "Saved #{new_report_file}."
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