-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
158 lines (121 loc) · 3.44 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
require 'bundler/setup'
# require 'bundler/gem_tasks'
require 'rake/clean'
require 'rake/testtask'
require 'rubocop/rake_task'
# rubocop:disable Style/HashSyntax, Metrics/LineLength
GO_DIRS = `git ls-files -z`
.split("\0")
.grep(/\.go$/)
.map { |f| File.dirname(File.join('.', f)) }
.uniq
GO_TOOLS = %w(cover vet)
.map { |cmd| "code.google.com/p/go.tools/cmd/#{cmd}" }
def cov?
ENV['COVERAGE']
end
def verbose?
ENV['VERBOSE']
end
task :clean do
sh 'git clean -fdx target/'
end
if ENV['CI']
ENV['COVERAGE'] = '1'
Rake::Task[:clean].invoke
end
desc 'Get prerequisite libraries and such'
task :prereqs do
get_cmd = ['go get -t -v']
get_cmd << '-u' if ENV['UPDATE']
get_cmd.concat(GO_DIRS)
get_cmd.concat(GO_TOOLS)
sh get_cmd.join(' ')
gobin = `go env GOPATH`
.strip
.split(':')
.map { |dir| File.join(dir, 'bin') }
.select { |dir| File.directory?(dir) }
ENV['PATH'] = "#{gobin.join(':')}:#{ENV['PATH']}"
end
### Code Generation
###################
GENERATED = FileList.new
def generate_file(*args, &block)
GENERATED << file(*args, &block)
end
generate_file 'regexp.go' => 'script/compose_regexp.go' do
sh 'go run script/compose_regexp.go > regexp.go'
end
generate_file 'lib/cardea/regexp.rb' => ['regexp.go', 'script/regexp2ruby.pl'] do
sh 'script/regexp2ruby.pl < regexp.go > lib/cardea/regexp.rb'
end
desc 'Generate secondary files'
task :generate => :prereqs
task :generate => GENERATED do
sh "git diff --name-status --exit-code #{GENERATED}"
end
### Build Targets
#################
TARGETS = FileList.new
def build_file(*args, &block)
TARGETS << file(*args, &block)
end
build_file 'target/nginx-auth-cardea' => FileList['*.go', 'nginx-auth-cardea/*.go'] do |t|
sh "go build -o #{t} ./nginx-auth-cardea"
end
desc 'Build targets'
task :build => [:prereqs, :generate]
task :build => TARGETS
namespace :go do
desc 'Run GoConvey tests'
task :convey => :prereqs do
test_cmd = ['go test']
test_cmd << '-v' if verbose?
test_cmd << '-coverprofile=target/report/gocov.txt' if cov?
sh test_cmd.join(' ')
sh 'go tool cover -func=target/report/gocov.txt' if cov?
end
desc 'Vet the Go files'
task :vet => :prereqs do
vet_cmd = ['go tool vet']
vet_cmd << '-v' if verbose?
vet_cmd.concat(GO_DIRS)
sh vet_cmd.join(' ')
end
desc 'Run Go tests'
task :test => [:convey, :vet]
desc 'Generate Go reports'
task :report => [:test] do
sh 'go tool cover -html=target/report/gocov.txt -o target/report/gocov.html' if cov?
end
end
desc 'Run whole workflow for Go'
task :go => ['go:test', 'go:report']
namespace :ruby do
RuboCop::RakeTask.new
Rake::TestTask.new :spec do |t|
t.pattern = 'test/spec/**_spec.rb'
t.options = '--command-name=spec'
t.libs = %w(lib test/lib)
t.verbose = verbose?
end
Rake::TestTask.new :integration do |t|
t.pattern = 'test/integration/**_spec.rb'
t.options = '--command-name=integration'
t.libs = %w(lib test/lib)
t.verbose = verbose?
end
desc 'Run Ruby tests'
task :test => [:rubocop, :spec, :integration]
desc 'Generate Ruby reports'
task :report => [:test]
end
desc 'Run full Ruby workflow'
task :ruby => ['ruby:test', 'ruby:report']
desc 'Run all tests'
task :test => ['go:test', 'ruby:test']
desc 'Generate all reports'
task :report => ['go:report', 'ruby:report']
task :default => [:build, :test, :report]
task 'ruby:integration' => :build