<commit_before>desc "Run Kokoro tests"

include :exec, e: true
include :fileutils
include :terminal, styled: true

def run
  run_setup
  run_tests
  report_results
  exit 1 unless @failures.empty?
ensure
  run_cleanup
end

####
# Toplevel steps
####

def run_setup
  @failures = []
  @project = ""
  @kill_on_cleanup = []
  gimme_proj
  setup_env
  setup_workarounds
  list_products
  filter_by_ruby_versions
  filter_by_changed_paths if presubmit?
  start_app_engine_services
  start_cloud_sql_services
end

def run_tests
  configure_exec e: false
  test_globals
  @products.each do |dir|
    test_product dir
  end
end

def report_results
  if @failures.empty?
    puts "ALL TESTS PASSED!", :green, :bold
    return
  end
  puts "Failures:", :red, :bold
  @failures.each do |failure|
    puts failure, :red, :bold
  end
  puts "Search these logs for the red test names listed above to see details."
  if !presubmit? && !ENV["KOKORO_BUILD_ID"]
    chmod "+x", "#{gfile_dir}/linux_amd64/flakybot"
    exec ["#{gfile_dir}/linux_amd64/flakybot"]
  end<commit_msg>chore: Call flakybot on nightly runs (#996)<commit_after>desc "Run Kokoro tests"

include :exec, e: true
include :fileutils
include :terminal, styled: true

def run
  run_setup
  run_tests
  report_results
  exit 1 unless @failures.empty?
ensure
  run_cleanup
end

####
# Toplevel steps
####

def run_setup
  @failures = []
  @project = ""
  @kill_on_cleanup = []
  gimme_proj
  setup_env
  setup_workarounds
  list_products
  filter_by_ruby_versions
  filter_by_changed_paths if presubmit?
  start_app_engine_services
  start_cloud_sql_services
end

def run_tests
  configure_exec e: false
  test_globals
  @products.each do |dir|
    test_product dir
  end
end

def report_results
  if @failures.empty?
    puts "ALL TESTS PASSED!", :green, :bold
    return
  end
  puts "Failures:", :red, :bold
  @failures.each do |failure|
    puts failure, :red, :bold
  end
  puts "Search these logs for the red test names listed above to see details."
  unless presubmit?
    chmod "+x", "#{gfile_dir}/linux_amd64/flakybot"
    exec ["#{gfile_dir}/linux_amd64/flakybot"]
  end
{'fraction_non_alphanumeric': 0.09116541353383459, 'fraction_numerical': 0.006109022556390977, 'mean_word_length': 4.0570071258907365, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2050318', 'n_tokens_mistral': 781, 'n_tokens_neox': 770, 'n_words': 212}