-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathcleanup_lint_roller.rb
More file actions
30 lines (26 loc) · 1005 Bytes
/
cleanup_lint_roller.rb
File metadata and controls
30 lines (26 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env ruby
# Removes stray Gemfile.lock files shipped inside gems to appease security scanners.
require "rubygems"
# List of gems that ship with Gemfile.lock files that should be removed
GEMS_WITH_LOCKFILES = %w{lint_roller stackprof-webnav}.freeze
def cleanup_gem_lockfile(gem_name)
puts "Cleaning up #{gem_name} Gemfile.lock..."
specs = Gem::Specification.find_all_by_name(gem_name)
if specs.empty?
puts " No #{gem_name} gem installed"
return
end
specs.each do |spec|
gemfile_lock_path = File.join(spec.gem_dir, "Gemfile.lock")
if File.exist?(gemfile_lock_path)
puts " Removing #{gemfile_lock_path}"
File.delete(gemfile_lock_path)
puts " Successfully removed #{gem_name} Gemfile.lock"
else
puts " No Gemfile.lock found in #{spec.gem_dir}"
end
end
rescue StandardError => e
warn " Warning: Failed to clean up #{gem_name} Gemfile.lock: #{e.message}"
end
GEMS_WITH_LOCKFILES.each { |gem_name| cleanup_gem_lockfile(gem_name) }