forked from adamgoucher/chemistrykit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
183 lines (142 loc) · 5.39 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# Encoding: utf-8
require 'bundler/gem_tasks'
require 'cucumber'
require 'cucumber/rake/task'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
require 'flog_task'
require 'flay_task'
require 'reek/rake/task'
task default: :build
desc 'Runs standard build activities.'
task build: [:clean, :prepare, :quality, :unit, :integration]
desc 'Runs full build activities.'
task build_full: [:clean, :prepare, :quality, :unit, :integration, :system]
desc 'Runs quality checks.'
task quality: [:rubocop, :reek, :flog_total, :flog_average, :flay]
desc 'Removes the build directory.'
task :clean do
FileUtils.rm_rf('build')
end
desc 'Adds the build tmp directory for test kit creation.'
task :prepare do
FileUtils.mkdir_p('build/tmp')
FileUtils.mkdir_p('build/spec')
end
def get_rspec_flags(log_name, others = nil)
"--format documentation --out build/spec/#{log_name}.log --format html --out build/spec/#{log_name}.html --format progress #{others}"
end
RSpec::Core::RakeTask.new(:unit) do |t|
t.pattern = FileList['spec/unit/**/*_spec.rb']
t.rspec_opts = get_rspec_flags('unit')
end
RSpec::Core::RakeTask.new(:integration) do |t|
t.pattern = FileList['spec/integration/**/*_spec.rb']
t.rspec_opts = get_rspec_flags('integration')
end
Cucumber::Rake::Task.new(:system)
Rubocop::RakeTask.new
# TODO: lower the quality score and improve the code!
FlogTask.new :flog_total, 10000 do |t|
t.method = :total_score
t.verbose = true
end
# TODO: lower the quality score and improve the code!
FlogTask.new :flog_average, 200 do |t|
t.method = :average
t.verbose = true
end
# TODO: lower the quality score and improve the code!
FlayTask.new :flay, 10000 do |t|
t.verbose = true
end
# TODO: fix all the smells and turn on failing on error
Reek::Rake::Task.new do |t|
t.fail_on_error = false
t.verbose = false
t.reek_opts = '--quiet'
end
# TODO This could probably be more cleanly automated
desc 'Start a release (Requires Git Flow)'
task :release_start, [:version, :no_verify] do |t, args|
version = args['version']
# make sure we have the latest stuff
system 'git fetch --all'
# first make sure master is checked out and up to date
system 'git checkout master'
system 'git pull --no-edit origin master'
# then make sure develop is up to date
system 'git checkout develop'
system 'git pull --no-edit origin develop'
# next assure all the tests run
task(:build_full).invoke unless !!args['no_verify']
# start the release process
system "git flow release start #{version}"
# update the version number in the .gemspec file
gemspec = File.join(Dir.getwd, 'chemistrykit.gemspec')
updated = File.read(gemspec).gsub(
/s.version(\s+)=(\s?["|']).+(["|'])/,
"s.version\\1=\\2#{version}\\3"
)
File.open(gemspec, 'w') { |f| f.write(updated) }
# commit the version bump
system 'git add chemistrykit.gemspec'
system "git commit -m 'Bumped version to #{version} to prepare for release.'"
puts "You've started release #{version}, make any last minute updates now.\n"
end
# TODO This could probablly be more cleanly automated
desc 'Finish a release (Requires Git Flow and Gem Deploy Permissions'
task :release_finish, :update_message do |t, args|
message = args['update_message']
gemspec = File.join(Dir.getwd, 'chemistrykit.gemspec')
changelog = File.join(Dir.getwd, 'CHANGELOG.md')
version = File.read(gemspec).match(/s.version\s+=\s?["|'](.+)["|']/)[1]
readme = File.join(Dir.getwd, 'README.md')
date = Time.new.strftime('%Y-%m-%d')
### Changelog
# get the latest tag
system 'git checkout master'
last_tag = `git describe --abbrev=0`
system "git checkout release/#{version}"
# get the commit hash since the last that version was merged to develop
hash = `git log --grep="Merge branch 'release/#{last_tag.chomp}' into develop" --format="%H"`
# get all the commits since them less merges
log = `git log --format="- %s" --no-merges #{hash.chomp}..HEAD`
changelog_contents = File.read(changelog)
# create the new heading
updated_changelog = "##{version} (#{date})\n" + message + "\n\n" + log + "\n" + changelog_contents
# update the contents
File.open(changelog, 'w') { |f| f.write(updated_changelog) }
puts "Updated change log for version #{version}\n"
### Update the gemspec with the message
updated_gemspec = File.read(gemspec).gsub(
/s.description(\s+)=(\s?["|']).+(["|'])/,
"s.description\\1=\\2#{message}\\3"
)
File.open(gemspec, 'w') { |f| f.write(updated_gemspec) }
### Update the readme heading
updated = File.read(readme).gsub(
/^#ChemistryKit \d+\.\d+.\d+ \(.+\)/,
"#ChemistryKit #{version} (#{date})"
)
File.open(readme, 'w') { |f| f.write(updated) }
# Commit the updated change log and gemspec and readme
system "git commit -am 'Updated CHANGELOG.md gemspec and readme heading for #{version} release.'"
# build the gem
system 'gem build chemistrykit.gemspec'
# push the gem
system "gem push chemistrykit-#{version}.gem"
# remove the gem file
system "rm chemistrykit-#{version}.gem"
# finish the release
# TODO there is a bug with git flow, and you still need to deal with merge
# messages, might just do this with git directly
system "git flow release finish -m'#{version}' #{version}"
# push develop
system 'git push origin develop'
# push master
system 'git push origin master'
# push tags
system 'git push --tags'
puts "Rock and roll, you just released ChemistryKit #{version}!\n"
end