-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
154 lines (131 loc) · 3.49 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
$concurrent_destinations = 1
$framework = "Relay"
def build_matrix
return [
{
:scheme => "#{$framework}-iOS",
:run_tests => true,
:destinations => [
"OS=latest,name=iPhone 11 Pro Max"
]
},
{
:scheme => "#{$framework}-macOS",
:run_tests => true,
:destinations => [
"platform=OS X,arch=x86_64"
]
},
{
:scheme => "#{$framework}-tvOS",
:run_tests => true,
:destinations => [
"OS=latest,name=Apple TV 4K"
]
},
{
:scheme => "#{$framework}-watchOS",
:run_tests => false,
:destinations => [
"OS=latest,name=Apple Watch Series 5 - 40mm"
]
}
]
end
desc "Clean all builds"
task :clean do
clean_all_schemes
end
desc "Update project dependencies"
task :update do
update_dependencies
end
desc "Build all targets"
task :build do
build_all_schemes
end
desc "Run all tests"
task :test do
test_all_schemes
end
desc "Run all tests on SPM"
task :test_spm do
test_spm
end
desc "Run all iOS tests"
task :test_ios do
test_platform build_matrix.find { |config| config[:scheme] == "#{$framework}-iOS" }
end
desc "Run all macOS tests"
task :test_macos do
test_platform build_matrix.find { |config| config[:scheme] == "#{$framework}-macOS" }
end
desc "Run all tvOS tests"
task :test_tvos do
test_platform build_matrix.find { |config| config[:scheme] == "#{$framework}-tvOS" }
end
desc "Run all watchOS tests"
task :test_watchos do
test_platform build_matrix.find { |config| config[:scheme] == "#{$framework}-watchOS" }
end
desc "Install CI dependencies"
task :ci_install do
system("bundle install")
system("bundle exec danger")
end
#
# Utility functions for rake tasks. Can be overriden.
#
def clean_all_schemes
execute "swift package reset" if swift_package_manager
build_matrix.each do |config|
scheme = config[:scheme]
execute "xcodebuild -scheme #{scheme} -quiet clean"
end
end
def build_all_schemes
execute "swift build" if swift_package_manager
build_matrix.each do |config|
scheme = config[:scheme]
destinations = config[:destinations].map { |destination| "-destination '#{destination}'" }.join(" ")
execute "xcodebuild -scheme #{scheme} -configuration Release #{destinations} -quiet build analyze"
end
end
def test_all_schemes
test_spm if swift_package_manager
build_matrix.each do |config|
test_platform config
end
end
def test_spm
execute "swift test --parallel"
end
def test_platform(config)
scheme = config[:scheme]
destinations = config[:destinations].map { |destination| "-destination '#{destination}'" }.join(" ")
if config[:run_tests] then
execute "xcodebuild -scheme #{scheme} #{destinations} -quiet build-for-testing analyze"
execute "xcodebuild -scheme #{scheme} #{destinations} -quiet -disable-concurrent-destination-testing test-without-building"
else
execute "xcodebuild -scheme #{scheme} -configuration Release #{destinations} -quiet build analyze"
end
end
def swift_package_manager
return File.file?("Package.swift")
end
def bootstrap
execute "carthage bootstrap --cache-builds"
end
def update_dependencies
execute "carthage update --cache-builds"
execute "swift package update" if swift_package_manager
end
def execute(command)
puts "\n\e[35m=== EXECUTE: #{command} ===\e[39m\n\n"
system(command) || fail_build
puts "\n\e[32m=== EXECUTE: Command exited with code 0. ===\e[39m\n\n"
end
def fail_build
puts "\n\e[101m=== EXECUTE: Command failed. ===\e[39m\e[49m\n\n"
exit -1
end