Skip to content

Instantly share code, notes, and snippets.

@andy-leonard
Last active August 29, 2015 13:56
Show Gist options
  • Save andy-leonard/8900299 to your computer and use it in GitHub Desktop.
Save andy-leonard/8900299 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'English'
puts 'Checking for whitespace errors...'
git_ws_check = `git diff-index --check --cached HEAD --`
unless $CHILD_STATUS.success?
puts git_ws_check
exit 1
end
COOKBOOK_PATH = `git rev-parse --show-toplevel`.chomp
COOKBOOK_PATH_PARTS = File.split COOKBOOK_PATH
PARENT_PATH = COOKBOOK_PATH_PARTS[0]
COOKBOOK_NAME = COOKBOOK_PATH_PARTS[1]
puts 'Running knife cookbook test...'
knife_output =
`bundle exec knife cookbook test #{COOKBOOK_NAME} -o #{PARENT_PATH}`
unless $CHILD_STATUS.success?
puts knife_output
exit 1
end
# Get the file names of (A)dded, (C)opied, (M)odified Ruby files
STAGED_FILES = `git diff-index --name-only --diff-filter=ACM HEAD -- '*.rb'`
puts 'Running tailor...'
STAGED_FILES.lines do |file|
file.chomp! # remove carriage returns
puts file
tailor_output =
`bundle exec tailor --max-line-length 999 #{file} \
--indentation-spaces false`
unless $CHILD_STATUS.success?
puts tailor_output
exit 1
end
end
puts 'Running RuboCop...'
STAGED_FILES.lines do |file|
file.chomp! # remove carriage returns
puts file
rubocop_output = `bundle exec rubocop -D #{file}`
unless $CHILD_STATUS.success?
puts rubocop_output
exit 1
end
end
puts 'Running foodcritic...'
fc_output =
`bundle exec foodcritic --epic-fail any #{COOKBOOK_PATH}`
unless $CHILD_STATUS.success?
puts fc_output
exit 1
end
chefspec_path = File.join([COOKBOOK_PATH, 'spec'])
if File.directory?(chefspec_path)
puts 'Running chefspec...'
cs_output = `bundle exec rspec #{chefspec_path}`
unless $CHILD_STATUS.success?
puts cs_output
exit 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment