OSDN Git Service

fix service control.
[metasearch/grid-chef-repo.git] / cookbooks / 00cookbook / Rakefile
1 require 'rspec/core/rake_task'
2 require 'rubocop/rake_task'
3 require 'foodcritic'
4 require 'stove/rake_task'
5
6 tpl_cookbook = '00cookbook'
7 cookbook_name = File.basename(Dir.pwd)
8
9 desc 'Initialize project'
10 task :init do
11   next if cookbook_name == tpl_cookbook
12
13   [
14     '.foodcritic',
15     '.rubocop.yml',
16     'Berksfile',
17     'concourse.yml',
18     'fly-vars.yml',
19     'fly-vars.local.yml',
20     'Gemfile',
21     'Gemfile.lock',
22     'version',
23   ].each {|conf|
24     sh "cp ../#{tpl_cookbook}/#{conf} ./" unless File.exist?(conf)
25   }
26
27   ruby [
28     %(-pne '$_.gsub!(/^cookbook-name: .*$/, "cookbook-name: #{cookbook_name}")'),
29     '-i fly-vars.local.yml',
30   ].join(' ')
31 end
32
33 desc 'Update project'
34 task :update do
35   next if cookbook_name == tpl_cookbook
36
37   [
38     'Rakefile',
39     'concourse.yml',
40     'fly-vars.yml',
41     'Gemfile',
42     'Gemfile.lock',
43   ].each {|conf|
44     sh "cp ../#{tpl_cookbook}/#{conf} ./"
45   }
46 end
47
48 desc 'fly set-pipeline'
49 task :'set-pipeline' do
50   sh [
51     "fly -t $CC_TARGET sp -p #{cookbook_name}-cookbook -c concourse.yml",
52     '-l fly-vars.yml -l fly-vars.local.yml -l ~/sec/credentials-prod.yml',
53   ].join(' ')
54 end
55 desc 'rake set-pipeline alias'
56 task sp: 'set-pipeline'
57
58 namespace :style do
59   desc 'Run Ruby style checks'
60   RuboCop::RakeTask.new(:ruby) do |t|
61     t.options = [
62       '--auto-gen-config',  # creates .rubocop_todo.yml
63     ]
64   end
65
66   desc 'Run Chef style checks'
67   FoodCritic::Rake::LintTask.new(:chef) do |t|
68     t.options = {
69       fail_tags: ['any'],
70     }
71   end
72 end
73
74 desc 'Run all style checks'
75 task style: ['style:chef', 'style:ruby']
76
77 desc 'Run ChefSpec examples'
78 RSpec::Core::RakeTask.new(:spec)
79
80 desc 'Publish cookbook'
81 Stove::RakeTask.new(:publish) do |t|
82   t.stove_opts = [
83     # `--username` and `--key` are set in ~/.stove typically.
84     #'--username', 'somebody',
85     #'--key', '~/chef/chef.io.example.com/somebody.pem',
86     #'--endpoint', 'https://supermarket.io.example.com/api/v1',  # default: supermarket.chef.io
87     #'--no-ssl-verify',
88     '--no-git',
89     '--log-level', 'info',
90   ]
91 end
92
93 task default: ['style', 'spec']