-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
52 lines (45 loc) · 1.27 KB
/
Rakefile
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# frozen_string_literal: true
require 'colorize'
require 'filemagic'
task default: [:help]
desc 'Display the list of available rake tasks'
task :help do
system('rake -T')
end
begin
require 'rubocop/rake_task'
RuboCop::RakeTask.new(:rubocop) do |task|
task.options = ['-D', '-S', '-E']
end
rescue LoadError
desc 'ERROR: rubocop missing'
task :rubocop do
raise 'ERROR: rubocop missing'
end
end
desc 'Validate shell scripts in the files subdirectory'
task :shellcheck do
puts 'Running shellcheck...'
begin
sh 'shellcheck --version >/dev/null', verbose: false
rescue RuntimeError
print 'shellcheck command not found! See '.red
puts 'https://github.com/koalaman/shellcheck#installing to install it'.red
raise
end
scripts = SortedSet.new
Dir['**/*'].each do |file|
mime = FileMagic.new(FileMagic::MAGIC_MIME).file(file)
full = FileMagic.new(FileMagic::MAGIC_CONTINUE).file(file)
scripts.add?(file) if file =~ /.sh$/
scripts.add?(file) if mime =~ /x-shellscript/
scripts.add?(file) if full =~ /(ba)?sh script/
end
sh "shellcheck #{scripts.to_a.join(' ')}" if scripts.count > 0
end
desc 'Run all tests'
task :precommit do
Rake::Task[:shellcheck].invoke
Rake::Task[:rubocop].invoke
end
# vim: set tw=80 ts=2 sw=2 sts=2 et: