require 'rspec/core/rake_task' require 'rubocop/rake_task' require 'foodcritic' require 'stove/rake_task' tpl_cookbook = '00cookbook' cookbook_name = File.basename(Dir.pwd) desc 'Initialize project' task :init do next if cookbook_name == tpl_cookbook [ '.foodcritic', '.rubocop.yml', 'Berksfile', 'chefignore', 'concourse.yml', 'fly-vars.yml', 'fly-vars.local.yml', 'Gemfile', 'Gemfile.lock', 'version', ].each {|conf| sh "cp ../#{tpl_cookbook}/#{conf} ./" unless File.exist?(conf) } ruby [ %(-pne '$_.gsub!(/^cookbook-name: .*$/, "cookbook-name: #{cookbook_name}")'), '-i fly-vars.local.yml', ].join(' ') end desc 'Update project' task :update do next if cookbook_name == tpl_cookbook [ 'Rakefile', 'chefignore', 'concourse.yml', 'fly-vars.yml', 'Gemfile', 'Gemfile.lock', ].each {|conf| sh "cp ../#{tpl_cookbook}/#{conf} ./" } end desc 'fly set-pipeline' task :'set-pipeline' do sh [ "fly -t $CC_TARGET sp -p #{cookbook_name}-cookbook -c concourse.yml", '-l fly-vars.yml -l fly-vars.local.yml -l ~/sec/credentials-prod.yml', ].join(' ') end desc 'rake set-pipeline alias' task sp: 'set-pipeline' namespace :style do desc 'Run Ruby style checks' RuboCop::RakeTask.new(:ruby) do |t| t.options = [ '--auto-gen-config', # creates .rubocop_todo.yml ] end desc 'Run Chef style checks' FoodCritic::Rake::LintTask.new(:chef) do |t| t.options = { fail_tags: ['any'], } end end desc 'Run all style checks' task style: ['style:chef', 'style:ruby'] desc 'Run ChefSpec examples' RSpec::Core::RakeTask.new(:spec) desc 'Publish cookbook' Stove::RakeTask.new(:publish) do |t| t.stove_opts = [ # `--username` and `--key` are set in ~/.stove typically. #'--username', 'somebody', #'--key', '~/chef/chef.io.example.com/somebody.pem', #'--endpoint', 'https://supermarket.io.example.com/api/v1', # default: supermarket.chef.io #'--no-ssl-verify', '--no-git', '--log-level', 'info', ] end task default: ['style', 'spec']