CI runs lint on shell scripts in lib/support
This commit is contained in:
parent
8abdabdb3a
commit
62ae61ed96
|
@ -243,6 +243,7 @@ rubocop:
|
|||
|
||||
rake haml_lint: *exec
|
||||
rake scss_lint: *exec
|
||||
rake config_lint: *exec
|
||||
rake brakeman: *exec
|
||||
rake flay: *exec
|
||||
license_finder: *exec
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
module ConfigLint
|
||||
def self.run(files)
|
||||
failures = files.reject do |file|
|
||||
yield(file)
|
||||
end
|
||||
|
||||
if failures.present?
|
||||
puts failures
|
||||
exit failures.count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc "Checks syntax for shell scripts and nginx config files in 'lib/support/'"
|
||||
task :config_lint do
|
||||
shell_scripts = [
|
||||
'lib/support/init.d/gitlab',
|
||||
'lib/support/init.d/gitlab.default.example',
|
||||
'lib/support/deploy/deploy.sh'
|
||||
]
|
||||
|
||||
ConfigLint.run(shell_scripts) do |file|
|
||||
Kernel.system('bash', '-n', file)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,27 @@
|
|||
require 'rake_helper'
|
||||
Rake.application.rake_require 'tasks/config_lint'
|
||||
|
||||
describe ConfigLint do
|
||||
let(:files){ ['lib/support/fake.sh'] }
|
||||
|
||||
it 'errors out if any bash scripts have errors' do
|
||||
expect { ConfigLint.run(files){ system('exit 1') } }.to raise_error(SystemExit)
|
||||
end
|
||||
|
||||
it 'passes if all scripts are fine' do
|
||||
expect { ConfigLint.run(files){ system('exit 0') } }.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe 'config_lint rake task' do
|
||||
before(:each) do
|
||||
# Prevent `system` from actually being called
|
||||
allow(Kernel).to receive(:system).and_return(true)
|
||||
end
|
||||
|
||||
it 'runs lint on shell scripts' do
|
||||
expect(Kernel).to receive(:system).with('bash', '-n', 'lib/support/init.d/gitlab')
|
||||
|
||||
run_rake_task('config_lint')
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue