This repository has been archived by the owner on May 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathRakefile
96 lines (83 loc) · 2.38 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
def mvn(*args)
ensure_cmd("mvn")
args.unshift("-o") if ENV["OFFLINE"] == "1"
system("mvn", *args)
return $?.exitstatus == 0
end
def mvn_or_die(*args)
if !mvn(*args)
yield if block_given?
exit(-1)
end
end
def cmd?(name)
%x{which #{name}}
return $?.exitstatus == 0
end
def ensure_cmd(name)
if not cmd?(name)
$stderr.puts "Unable to find command '#{name}'! Make sure it is installed and in your PATH (#{ENV['PATH']})"
exit(-1)
end
end
desc "Runs bouncer."
task :run do
mvn_or_die("exec:java")
end
task :default => [:test]
desc "Runs the tests."
task :test do
mvn_or_die("clean", "test") do
for test_file in Dir["target/surefire-reports/*.txt"]
test_results = File.read(test_file)
if test_results =~ /FAILURE/m
puts test_results
end
end
end
end
namespace :test do
desc "Generates an HTML coverage report and opens it in your default browser. NO_OPEN=1 to just generate the report."
task :coverage do
mvn_or_die("clean", "cobertura:cobertura")
system("open", "target/site/cobertura/index.html") unless ENV["NO_OPEN"] == "1"
end
desc "Generates an HTML test report and opens it in your default browser. NO_OPEN=1 to just generate the report."
task :report do
mvn_or_die("clean", "surefire-report:report")
system("open", "target/site/surefire-report.html") unless ENV["NO_OPEN"] == "1"
end
end
desc "Build a deliverable JAR file."
task :jar do
require "time"
head = `git log -n1 --pretty="format:%H"`
@version = "#{Time.now.utc.strftime("%Y%m%d%H%M%S")}-#{head[0..7]}"
mvn_or_die("-Dmaven.test.skip=true", "clean", "assembly:assembly")
generated_jar_file = Dir["target/*-with-dependencies.jar"].first
@jar_file = "target/" + File.basename(generated_jar_file).gsub(/[\d]+.[\d]+(-SNAPSHOT)?-jar-with-dependencies/, @version)
mv(generated_jar_file, @jar_file)
end
def deployer
require "tasks/deploy"
if ENV["STAGING"] == "1"
Deploy.send(:hosts, %w{ bouncer1.stage })
else
Deploy.send(:hosts, %w{ bouncer1.prod bouncer2.prod })
end
return Deploy.new
end
desc "Push the latest version to the servers."
task :deploy => [:jar] do
deployer.run(@jar_file)
end
namespace :deploy do
desc "Prints all installed versions."
task :installed do
deployer.print_installed_versions
end
desc "Cleans all but the 5 most recent installed versions."
task :clean do
deployer.clean_installed
end
end