prune-old-flaky-specs 1009 Bytes
Newer Older
1 2
#!/usr/bin/env ruby

3 4 5 6 7
# lib/rspec_flaky/flaky_examples_collection.rb is requiring
# `active_support/hash_with_indifferent_access`, and we install the `activesupport`
# gem manually on the CI
require 'rubygems'

8 9 10
# In newer Ruby, alias_method is not private then we don't need __send__
singleton_class.__send__(:alias_method, :require_dependency, :require) # rubocop:disable GitlabSecurity/PublicSend
$:.unshift(File.expand_path('../lib', __dir__))
11 12

require 'rspec_flaky/report'
13 14 15 16 17 18 19 20

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
21
report = RspecFlaky::Report.load(report_file)
22
puts "Loading #{report_file}..."
23
puts "Current report has #{report.size} entries."
24

25
new_report = report.prune_outdated
26

27 28
puts "New report has #{new_report.size} entries: #{report.size - new_report.size} entries older than 90 days were removed."
puts "Saved #{new_report_file}." if new_report.write(new_report_file)