forked from gooddata/gooddata-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
263 lines (217 loc) · 7.13 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# encoding: UTF-8
require 'rubygems'
require 'bundler/setup'
require 'bundler/cli'
require 'bundler/gem_tasks'
require 'gooddata'
require 'rake/testtask'
require 'rspec/core/rake_task'
require 'yaml'
require 'yard'
require 'rubocop/rake_task'
desc 'Run RuboCop'
RuboCop::RakeTask.new(:cop) do |task|
task.patterns = ['{lib,spec}/**/*.rb']
task.options = ['--force-exclusion']
end
desc 'Run continuous integration test'
task :ci do
Rake::Task['test:unit'].invoke
unless ENV['TRAVIS'] == 'true' && ENV['TRAVIS_SECURE_ENV_VARS'] == 'false'
Rake::Task['test:integration'].invoke
end
Rake::Task['test:cop'].invoke
end
namespace :gem do
desc "Release gem version #{GoodData::VERSION} to rubygems"
task :release do
gem = "gooddata-#{GoodData::VERSION}.gem"
puts "Building #{gem} ..."
res = `gem build ./gooddata.gemspec`
file = res.match('File: (.*)')[1]
next unless file
puts "Pushing #{file} ..."
system("gem push #{file}")
end
end
namespace :hook do
hook_path = File.join(File.dirname(__FILE__), '.git', 'hooks', 'pre-commit').to_s
desc 'Installs git pre-commit hook running rubocop'
task :install do
if File.exist?(hook_path)
puts 'Git pre-commit hook is already installed'
else
File.open(hook_path, 'w') do |file|
file.write("#! /usr/bin/env bash\n")
file.write("\n")
file.write("rake cop\n")
end
system "chmod 755 #{hook_path}"
puts 'Git commit hook was installed'
end
end
desc 'Uninstalls git pre-commit hook'
task :uninstall do
res = File.exist?(hook_path)
if res
puts 'Uninstalling git pre-commit hook'
system "rm #{hook_path}"
puts 'Git pre-commit hook was uninstalled'
else
puts 'Git pre-commit hook is not installed'
end
end
desc 'Checks if is git pre-commit hook installed'
task :check do
res = File.exist?(hook_path)
if res
puts 'Git pre-commit IS installed'
else
puts 'Git pre-commit IS NOT installed'
end
end
end
namespace :license do
desc 'Show license report'
task :info do
Bundler::CLI.start(['exec', 'license_finder', '--decisions-file', 'dependency_decisions.yml'])
end
desc 'Generate licenses report - DEPENDENCIES.md'
task :report do
`bundle exec license_finder report --decisions-file dependency_decisions.yml --format=markdown > DEPENDENCIES.md`
end
desc 'Check if DEPENDENCIES.md is up to date'
task :check do
Rake::Task['license:report'].invoke
res = `git diff --stat DEPENDENCIES.md`
fail 'License check error' unless res.include?('1 file changed, 1 insertion(+), 1 deletion(-)')
puts 'All licenses seem to be OK'
end
desc 'Add license header to each file'
task :add do
spec = Gem::Specification.load('gooddata.gemspec')
license = File.readlines(File.expand_path('../LICENSE.rb', __FILE__))
license << "\n"
license_lines = license.length
spec.files.each do |path|
next if path == 'LICENSE.rb'
next unless path.end_with?('.rb')
puts "Processing #{path}"
content = File.read(path)
content_lines = content.lines
update = content_lines.length < license_lines
if update == false
content_with_license = (license + content_lines[license_lines..-1]).join
update = content != content_with_license
end
next unless update
puts "Updating #{path}"
if content_lines.length > 0 && content_lines[0].downcase.strip == '# encoding: utf-8'
content_lines.slice!(0)
content_lines.slice!(0) if content_lines[0] == "\n"
end
new_content = (license + content_lines).join
File.open(path, 'w') { |file| file.write(new_content) }
end
end
end
# Updates the changelog with commit messages
def update_changelog(new_version)
changelog = headless_changelog
fail 'the version is already mentioned in the changelog' if changelog =~ /## #{new_version}/
puts "Creating changelog for version #{new_version}"
File.open('CHANGELOG.md', 'w+') do |file|
file.puts changelog_header + "\n"
file.puts "## #{new_version}"
changes(changelog).each { |change| file.puts ' - ' + change }
file.puts changelog
end
end
def changes(changelog)
current_commit = `git rev-parse HEAD`.chomp
last_release = changelog.split("\n").reject(&:empty?).first.delete('## ').chomp
last_release_commit = `git rev-parse #{last_release}`.chomp
`git log --format=%s --no-merges #{last_release_commit}..#{current_commit}`.split("\n").reject(&:empty?)
end
def headless_changelog
changelog = File.read('CHANGELOG.md')
changelog.slice! changelog_header
changelog
end
def changelog_header
'# GoodData Ruby SDK Changelog'
end
namespace :version do
desc 'Updates the changelog, commits and tags the bump'
task :bump do
require_relative 'lib/gooddata/version'
new_version = GoodData::VERSION
update_changelog(new_version)
`git add CHANGELOG.md SDK_VERSION`
`git commit -m "Bump version to #{new_version}"`
`git tag #{new_version}`
end
desc 'Shows changes since last release'
task :changelog do
puts changes(headless_changelog)
end
end
RSpec::Core::RakeTask.new(:test)
namespace :test do
desc 'Run unit tests'
RSpec::Core::RakeTask.new(:unit) do |t|
t.pattern = 'spec/unit/**/*.rb'
end
desc 'Run integration tests'
RSpec::Core::RakeTask.new(:sdk) do |t|
t.pattern = 'spec/integration/**/*.rb'
t.rspec_opts = '--color --format documentation --require spec_helper \
--format RspecJunitFormatter --out integration.results.xml'
end
desc 'Run LCM tests'
RSpec::Core::RakeTask.new(:lcm) do |t|
t.pattern = 'spec/lcm/integration/**/*.rb'
end
desc 'Run project-related tests. Separated from test:sdk so that ' \
'it is possible to save time by running the tasks in parallel.'
RSpec::Core::RakeTask.new(:project) do |t|
t.pattern = 'spec/project/**/*.rb'
t.rspec_opts = '--color --format documentation --require spec_helper \
--format RspecJunitFormatter --out project.results.xml'
end
desc 'Run coding style tests'
RSpec::Core::RakeTask.new(:cop) do
Rake::Task['cop'].invoke
end
task :all => [:unit, :integration, :cop, :lcm, :project]
task :ci => [:unit, :integration, :lcm, :project]
task :integration => [:sdk, :project]
end
desc 'Run all tests'
task :test => 'test:all'
task :usage do
puts 'No rake task specified, use rake -T to list them'
end
YARD::Rake::YardocTask.new
task :default => [:usage]
namespace :gitflow do
task :init do
file_path = File.join(File.dirname(__FILE__), 'bin/gitflow-init.sh')
system(file_path) || fail('Initializing git-flow failed!')
end
end
desc 'Rotates the password of the test domain admin'
namespace :password do
task :rotate, [:value, :encryption_key] do |_, args|
key = 'password'
value = args[:value]
encryption_key = args[:encryption_key]
encrypted_value = GoodData::Helpers.encrypt(value, encryption_key).strip
secrets_path = File.join(File.dirname(__FILE__), 'spec/environment/secrets.yaml')
secrets = YAML.load_file(secrets_path)
secrets.each_value do |env|
env[key].replace(encrypted_value) if env.key?(key)
end
File.write(secrets_path, secrets.to_yaml)
end
end