This repository has been archived by the owner on Apr 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathRakefile
82 lines (66 loc) · 2.53 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
require "json"
def e(cmd)
puts cmd
system({"GO111MODULE" => "on"}, cmd) || raise("Error running `#{cmd}`")
end
def target(expand="")
root = File.dirname(__FILE__)
File.expand_path(expand, File.join(root, 'target'))
end
desc 'Vendor dependencies for all projects.'
task :deps do
e "go mod vendor"
end
desc 'Build all projects'
task :build do
e "go build -i -ldflags -s -v ./..."
end
desc 'Test all projects (short only)'
task :test => [:build] do
e "go test -ldflags -s -short -timeout 30s ./..."
end
desc 'Test all projects'
task :test_all => [:build] do
# due to https://github.com/square/p2/issues/832, some tests are excluded from -race
# So, we run once with the race detector and one without. See .travis.yml for setting ENV['RACE']
e "go test -ldflags -s -timeout 300s #{ENV['RACE']} ./..."
end
desc 'Update all dependencies'
task :update do
e "go get -u -t -v ./..."
e "go mod vendor"
end
desc 'Install all built binaries'
task :install do
e "go install -a -ldflags \"-X github.com/square/p2/pkg/version.VERSION=$(git describe --tags)\" ./..."
end
task :errcheck do
e "exit $(errcheck -ignoretests -ignore \"fmt:.*\" github.com/square/p2/pkg/... | grep -v defer | wc -l || 1)"
end
desc 'Package the installed P2 binaries into a Hoist artifact that runs as the preparer. The output tar is symlinked to builds/p2.tar.gz'
task :package => :install do
root = File.dirname(__FILE__)
os = `uname`.downcase.chomp
arch = `uname -p`.downcase.chomp
builds_dir = File.join(root, "builds", os)
version_tag = `git describe --tags`.chomp
build_base = "p2-#{version_tag}-#{os}-#{arch}"
abort("Could not get version_tag") unless version_tag && version_tag != ""
e "mkdir -p #{builds_dir}/#{build_base}/bin"
Dir.glob(File.join(File.dirname(`which p2-preparer`.chomp), 'p2*')).each do |f|
e "cp #{f} #{builds_dir}/#{build_base}/bin"
end
e "mv #{builds_dir}/#{build_base}/bin/p2-preparer #{builds_dir}/#{build_base}/bin/launch"
e "tar -czf #{builds_dir}/#{build_base}.tar.gz -C #{builds_dir}/#{build_base} ."
e "rm -f #{builds_dir}/p2.tar.gz"
e "ln -s #{builds_dir}/#{build_base}.tar.gz #{builds_dir}/p2.tar.gz"
end
desc 'Run the vagrant integration tests. Will attempt to build first to save you some time.'
task :integration => :build do
root = File.dirname(__FILE__)
# suite.rb has a number of options, this one just runs the default one.
script = File.expand_path("integration/suite.rb", root)
exec "ruby #{script}"
end
desc 'By default, gather dependencies, build and test'
task :default => [:deps, :test, :install]