Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created December 22, 2021 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitode909/cba8e689319cc1a67aad734d1c6bd6c4 to your computer and use it in GitHub Desktop.
Save hitode909/cba8e689319cc1a67aad734d1c6bd6c4 to your computer and use it in GitHub Desktop.
def replace_file target_file
system "docker-compose exec app carton exec -- perl script/tools/code/kill-export.pl #{target_file}"
end
def print_result
system "git status"
end
def run_changed_tests
test_target = `echo "$(git diff --name-only t lib/)\n$(git diff --cached --name-only t lib)" | perl -pe 's{^lib/Giga/}{t/}g; s{\.pm$}{.t}g;' | sort | uniq | perl -nlE 'say if -e'`.gsub(/\n/, ' ')
return if test_target.empty?
puts "Running tests #{test_target}"
result = system %Q(docker-compose exec app carton exec -- prove -v #{test_target})
unless result
raise "test failed"
end
end
def commit target_file
system %Q(git commit -a -m "#{target_file} の @export 撲滅\n\npowered by #{$0}")
end
target_files = `git grep --name-only -z -w '@EXPORT' t/lib/`.split(/\0/)
# 利用回数の少ない順に処理していく
used_counts = {}
target_files.each{|target_file|
package = IO.read(target_file).scan(/package ([^; ]+)/).first.first
used_count = `git grep --name-only -z -w 'use #{package}'`.split(/\0/).length
used_counts[target_file] = used_count
}
target_files_order_by_used_count_asc = target_files.sort_by{|target_file|
used_counts[target_file]
}
target_files_order_by_used_count_asc.each{|target_file|
puts "Replacing #{target_file}"
replace_file target_file
print_result
run_changed_tests
commit target_file
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment