-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
135 lines (115 loc) · 3.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
# frozen_string_literal: true
# require 'bump/tasks'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
require 'yard'
require 'tty-spinner'
require 'rdoc/task'
module TempFixForRakeLastComment
def last_comment
last_description
end
end
Rake::Application.send :include, TempFixForRakeLastComment
Rake::RDocTask.new do |rd|
rd.main = 'README.rdoc'
rd.rdoc_files.include('README.rdoc', 'lib/**/*.rb', 'bin/**/*')
rd.title = 'Howzit'
end
task default: %i[test yard]
desc 'Run test suite'
task test: %i[rubocop spec]
RSpec::Core::RakeTask.new
RuboCop::RakeTask.new do |t|
t.formatters = ['progress']
end
YARD::Rake::YardocTask.new
desc 'Development version check'
task :ver do
gver = `git ver`
cver = IO.read(File.join(File.dirname(__FILE__), 'CHANGELOG.md')).match(/^#+ (\d+\.\d+\.\d+(\w+)?)/)[1]
res = `grep VERSION lib/howzit/version.rb`
version = res.match(/VERSION *= *['"](\d+\.\d+\.\d+(\w+)?)/)[1]
puts "git tag: #{gver}"
puts "version.rb: #{version}"
puts "changelog: #{cver}"
end
desc 'Changelog version check'
task :cver do
puts IO.read(File.join(File.dirname(__FILE__), 'CHANGELOG.md')).match(/^#+ (\d+\.\d+\.\d+(\w+)?)/)[1]
end
desc 'Run tests in Docker'
task :dockertest, :version, :login do |_, args|
args.with_defaults(version: 'all', login: false)
case args[:version]
when /^a/
%w[2 3 32].each do |v|
Rake::Task['dockertest'].reenable
Rake::Task['dockertest'].invoke(v, false)
end
Process.exit 0
when /^32/
img = 'howzittest32'
file = 'docker/Dockerfile-3.2'
when /^3/
img = 'howzittest3'
file = 'docker/Dockerfile-3.0'
# when /6$/
# img = 'howzittest26'
# file = 'docker/Dockerfile-2.6'
when /(^2|7$)/
img = 'howzittest27'
file = 'docker/Dockerfile-2.7'
else
img = 'howzittest'
file = 'docker/Dockerfile'
end
d_spinner = TTY::Spinner.new("[:spinner] Setting up Docker", hide_cursor: true, format: :dots)
d_spinner.auto_spin
`docker build . --file #{file} -t #{img} &> /dev/null`
d_spinner.success
d_spinner.stop
exec "docker run -v #{File.dirname(__FILE__)}:/howzit -it #{img} /bin/bash -l" if args[:login]
spinner = TTY::Spinner.new("[:spinner] Running tests #{img}", hide_cursor: true, format: :dots)
spinner.auto_spin
res = `docker run --rm -v #{File.dirname(__FILE__)}:/howzit -it #{img}`
commit = `bash -c "docker commit $(docker ps -a|grep #{img}|awk '{print $1}'|head -n 1) #{img}"`.strip
if $?.exitstatus == 0
spinner.success
else
spinner.error
puts res
end
spinner.stop
puts commit&.empty? ? "Error commiting Docker tag #{img}" : "Committed Docker tag #{img}"
end
desc 'Alias for build'
task package: :build
desc 'Bump incremental version number'
task :bump, :type do |_, args|
args.with_defaults(type: 'inc')
version_file = 'lib/howzit/version.rb'
content = IO.read(version_file)
content.sub!(/VERSION = '(?<major>\d+)\.(?<minor>\d+)\.(?<inc>\d+)(?<pre>\S+)?'/) do
m = Regexp.last_match
major = m['major'].to_i
minor = m['minor'].to_i
inc = m['inc'].to_i
pre = m['pre']
case args[:type]
when /^maj/
major += 1
minor = 0
inc = 0
when /^min/
minor += 1
inc = 0
else
inc += 1
end
$stdout.puts "At version #{major}.#{minor}.#{inc}#{pre}"
"VERSION = '#{major}.#{minor}.#{inc}#{pre}'"
end
File.open(version_file, 'w+') { |f| f.puts content }
end