<commit_before>#!/usr/bin/env ruby

`cp binary-linux/concourse-up-linux-amd64 ./cup`
`chmod +x ./cup`

non_empty = []

buckets = `aws s3 ls | grep -E 'concourse-up-systest' | awk '{print $3}'`

if buckets.empty?
  puts 'No residual systest buckets found'
  exit(0)
end

buckets.each_line do |bucket|
  bucket = bucket.strip
  deployment = bucket.split('-')[0..4].join('-')
  region = bucket.split('-')[5..7].join('-')

  `aws s3 ls s3://#{bucket} > /dev/null`
  if $?.success?
    contents = `aws s3 ls s3://#{bucket}`
    if contents.include?('terraform.tfstate') && contents.include?('director-state.json')
      non_empty.push(bucket)
    else
      puts "#{bucket} is missing key files"
      puts 'Attempting to delete VPC'
      puts '==================================================================='
      puts "MANUAL CLEANUP MAY BE REQUIRED FOR #{bucket}"
      puts '==================================================================='
      vpc_id = `aws ec2 describe-vpcs --filters 'Name=tag:Name,Values=#{deployment}' --region #{region} | jq -r '.Vpcs[0].VpcId'`
      if vpc_id
        `aws --region #{region} ec2 delete-vpc --vpc-id #{vpc_id}`
      else
        puts "vpc for #{deployment} not found"
      end
    end
  else
    printf "#{bucket} doesn't really exist\n"
  end
end

exit(0) if non_empty.empty?

non_empty.each do |bucket|
  if /^concourse-up-systest-[0-9]+/ =~ "#{bucket}"
    deployment = bucket.split('-')[2..3].join('-')
    region = bucket.split('-')[4..6].join('-')
    str = sprintf("./cup destroy --region %s %s", region, deployment)
    `echo #{str} >> to_delete`
  elsif /^concourse-up-systest-[a-zA-Z]+-[0-9]+/ =~ "#{bucket}"
    deployment = bucket.split('-')[2..4].join('-')
    region = bucket.split('-')[5..7].join('-')
    str = sprintf("./cup destroy --region %s %s", region, deployment)
    `echo #{str} >> to_delete`
  else
    puts "Unexpected bucket format #{bucket} -- skipping"<commit_msg>bypass prompts in cup destroy in cleanup script<commit_after>#!/usr/bin/env ruby

`cp binary-linux/concourse-up-linux-amd64 ./cup`
`chmod +x ./cup`

non_empty = []

buckets = `aws s3 ls | grep -E 'concourse-up-systest' | awk '{print $3}'`

if buckets.empty?
  puts 'No residual systest buckets found'
  exit(0)
end

buckets.each_line do |bucket|
  bucket = bucket.strip
  deployment = bucket.split('-')[0..4].join('-')
  region = bucket.split('-')[5..7].join('-')

  `aws s3 ls s3://#{bucket} > /dev/null`
  if $?.success?
    contents = `aws s3 ls s3://#{bucket}`
    if contents.include?('terraform.tfstate') && contents.include?('director-state.json')
      non_empty.push(bucket)
    else
      puts "#{bucket} is missing key files"
      puts 'Attempting to delete VPC'
      puts '==================================================================='
      puts "MANUAL CLEANUP MAY BE REQUIRED FOR #{bucket}"
      puts '==================================================================='
      vpc_id = `aws ec2 describe-vpcs --filters 'Name=tag:Name,Values=#{deployment}' --region #{region} | jq -r '.Vpcs[0].VpcId'`
      if vpc_id
        `aws --region #{region} ec2 delete-vpc --vpc-id #{vpc_id}`
      else
        puts "vpc for #{deployment} not found"
      end
    end
  else
    printf "#{bucket} doesn't really exist\n"
  end
end

exit(0) if non_empty.empty?

non_empty.each do |bucket|
  if /^concourse-up-systest-[0-9]+/ =~ "#{bucket}"
    deployment = bucket.split('-')[2..3].join('-')
    region = bucket.split('-')[4..6].join('-')
    str = sprintf("yes yes | ./cup destroy --region %s %s", region, deployment)
    `echo #{str} >> to_delete`
  elsif /^concourse-up-systest-[a-zA-Z]+-[0-9]+/ =~ "#{bucket}"
    deployment = bucket.split('-')[2..4].join('-')
    region = bucket.split('-')[5..7].join('-')
    str = sprintf("yes yes | ./cup destroy --region %s %s", region, deployment)
    `echo #{str} >> to_delete`
  else
    puts "Unexpected bucket format #{bucket} -- skipping"
{'fraction_non_alphanumeric': 0.2512664640324215, 'fraction_numerical': 0.014690982776089158, 'mean_word_length': 3.228051391862955, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '781263', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1392, 'n_words': 334}