-
Notifications
You must be signed in to change notification settings - Fork 4
/
Rakefile
109 lines (97 loc) · 2.91 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
require 'bundler/gem_tasks'
require 'rake/testtask'
require 'yard'
require 'open3'
require 'net/http'
require 'json'
def run_command(command)
exit_status = 0
Open3.popen2e(command) do |stdin, stdout_stderr, wait_thr|
output = []
stdout_stderr.each do |line|
output << line
end
exit_status = wait_thr.value.to_i
if exit_status != 0
output.each { |line| puts line }
throw Exception.new("An error occurred running command: #{command}")
end
end
end
def parse_release_tag(tag)
regex = /^[vV]?(\d+)\.(\d+)\.(\d+).*$/
parsed = regex.match(tag)
{
major: parsed[1].to_i,
minor: parsed[2].to_i,
patch: parsed[3].to_i
}
end
def version_greater_than(tag1, tag2)
if tag1[:major].eql?(tag2[:major])
if tag1[:minor].eql?(tag2[:minor])
tag1[:patch] > tag2[:patch]
else
tag1[:minor] > tag2[:minor]
end
else
tag1[:major] > tag2[:major]
end
end
namespace :test do
Rake::TestTask.new(:integration) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/integration/{**/,}*_test.rb']
end
Rake::TestTask.new(:unit) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList.new('test/**/*_test.rb') do |fl|
fl.exclude(/integration/)
end
end
desc 'Run all tests'
task :all => [:unit, :integration]
end
namespace :docs do
task :prepare do
Dir.mkdir('doc')
Dir.chdir('doc') do
run_command 'git init'
run_command 'git remote add origin https://github.com/bugsnag/maze-runner.git'
run_command 'git fetch'
run_command 'git checkout gh-pages'
run_command 'git pull'
run_command "echo https://#{ENV["DOCS_PUSH_TOKEN"]}:x-oauth-basic@github.com >> ~/.git-credentials"
run_command "git config credential.helper 'store'"
run_command "git config --global user.email 'notifiers@bugsnag.com'"
run_command "git config --global user.name 'Bugsnag notifiers'"
end
end
YARD::Rake::YardocTask.new do |t|
t.files = ['lib/features/**/*.rb']
t.options = ['--tag', 'step_input:Step parameters', '--markup', 'markdown', '--markup-provider', 'redcarpet']
end
task :publish do
Dir.chdir('doc') do
run_command 'git add .'
run_command "git commit -m 'Docs update'"
run_command 'git push'
end
end
task :build_and_publish do
latest_release_raw = Net::HTTP.get(URI('https://api.github.com/repos/bugsnag/maze-runner/releases/latest'))
latest_release = JSON.parse(latest_release_raw)
latest_version = latest_release['tag_name']
latest_tag = parse_release_tag(latest_version)
release_tag = parse_release_tag(ENV['BUILDKITE_TAG'])
if release_tag.eql?(latest_tag) || version_greater_than(release_tag, latest_tag)
Rake::Task['docs:yard'].invoke
Rake::Task['docs:publish'].invoke
else
puts 'Skipping docs publish as the tag is not the latest release'
end
end
end
task :default => ['test:unit']