forked from kjw1/magic-cookbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
119 lines (88 loc) · 2.14 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
require 'rubygems'
require 'bundler'
require 'rake'
def master?
`git rev-parse --abbrev-ref HEAD`.strip == 'master'
end
def test_kitchen?
File.exist? '.kitchen.yml'
end
def realm?
`git ls-files` =~ /\bBerksfile\.lock\b/
end
def current_version
File.read('VERSION').strip
end
def youre_behind?
`git fetch >/dev/null 2>&1`
behind = `git log ..origin/master --oneline`.split("\n").length > 0
raise unless $?.exitstatus.zero?
return behind
end
def youre_behind!
if youre_behind?
raise "ERROR: You're out of sync with the remote! Try 'git pull --rebase'"
end
end
def bump component
youre_behind!
`tony bump #{component}`
if realm?
`berks`
`git add Berksfile.lock`
end
version = current_version
`git add VERSION`
`git commit -m "Version bump to #{version}"`
`git tag -a v#{version} -m v#{version}`
raise 'Could not add tag' unless $?.exitstatus.zero?
puts 'Version is now "%s"' % version
end
def bump_and_release component
bump component
youre_behind!
`git push`
raise 'Push failed' unless $?.exitstatus.zero?
`git push --tag`
raise 'Tag push failed' unless $?.exitstatus.zero?
end
raise 'ERROR: You should only run tasks on the "master" branch' unless master?
desc 'Perform syntax check and linting'
task :lint do
system "knife cookbook test magic -o .."
raise 'Failed "knife cookbook test"' unless $?.exitstatus.zero?
system 'foodcritic .' # Merely a suggestion
end
if test_kitchen?
desc 'Execute default Test Kitchen test suite'
task test: :lint do
system 'kitchen test'
end
end
desc 'Print the current version'
task :version do
puts current_version
end
namespace :release do
desc 'Release new major version'
task :major do
bump_and_release :major
end
desc 'Release new minor version'
task :minor do
bump_and_release :minor
end
task :patch do
bump_and_release :patch
end
end
desc 'Release a new patch version'
task release: %w[ release:patch ]
if realm?
desc 'Apply Berksfile lock to an environment'
task :constrain, [ :env ] do |_, args|
youre_behind!
`git tag -a #{args[:env]} -m #{args[:env]} --force`
`git push --tag --force`
end
end