forked from ChartsOrg/Charts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
146 lines (124 loc) · 3.26 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
def type
:project # set `:project` for xcodeproj and `:workspace` for xcworkspace
end
def project_name
'Charts.xcodeproj'
end
def configuration
'Debug'
end
def test_platforms
[
:iOS,
:tvOS
]
end
def build_platforms
[
:macOS
]
end
def build_schemes
%w(
Charts
ChartsRealm
)
end
def test_schemes
[
'ChartsTests'
]
end
def devices
{
iOS: {
sdk: 'iphonesimulator',
device: "id='22FA2149-1241-469C-BF6D-462D3837DB72'",
uuid: '22FA2149-1241-469C-BF6D-462D3837DB72'
},
macOS: {
sdk: 'macosx',
device: "arch='x86_64'",
uuid: nil
},
tvOS: {
sdk: 'appletvsimulator',
device: "id='5761D8AB-2838-4681-A528-D0949FF240C5'",
uuid: '5761D8AB-2838-4681-A528-D0949FF240C5'
}
}
end
def open_simulator_and_sleep(uuid)
return if uuid.nil? # Don't need a sleep on macOS because it runs first.
sh "xcrun instruments -w '#{uuid}' || sleep 15"
end
def xcodebuild(type, name, scheme, configuration, sdk, destination, tasks, xcprety_args)
# set either workspace or project flag for xcodebuild
case type
when :project
project_type = '-project'
when :workspace
project_type = '-workspace'
else
abort 'Invalid project type, use `:project` for xcodeproj and `:workspace` for xcworkspace.'
end
sh "set -o pipefail && xcodebuild #{project_type} '#{name}' -scheme '#{scheme}' -configuration '#{configuration}' -sdk #{sdk} -destination #{destination} #{tasks} | bundle exec xcpretty -c #{xcprety_args}"
end
def run_xcodebuild(schemes_to_execute, tasks, destination, is_test, xcprety_args)
sdk = destination[:sdk]
device = destination[:device]
uuid = destination[:uuid]
open_simulator_and_sleep uuid if is_test
schemes_to_execute.each do |scheme|
xcodebuild type, project_name, scheme, configuration, sdk, device, tasks, xcprety_args
end
sh 'killall Simulator' if is_test
end
def execute(tasks, platform, xcprety_args: '')
is_test = tasks.include?('test')
# platform specific settings
destination = devices[platform]
schemes = is_test ? test_schemes : build_schemes
# check if xcodebuild needs to be run on multiple devices
if destination.is_a?(Array)
destination.each do |destination|
run_xcodebuild schemes, tasks, destination, is_test, xcprety_args
end
else
run_xcodebuild schemes, tasks, destination, is_test, xcprety_args
end
end
def arg_to_key(string_key)
case string_key.downcase
when 'ios'
:iOS
when 'tvos'
:tvOS
when 'macos'
:macOS
when 'watchos'
:watchOS
else
abort 'Invalid platform, use `iOS`, `tvOS`, `macOS` or `watchOS`'
end
end
desc 'Run CI tasks. Build and test or build depending on the platform.'
task :ci, [:platform] do |_task, args|
platform = arg_to_key(args[:platform]) if args.has_key?(:platform)
if test_platforms.include?(platform)
execute 'clean build test', platform
elsif build_platforms.include?(platform)
execute 'clean build', platform
else
test_platforms.each do |platform|
execute 'clean build test', platform
end
build_platforms.each do |platform|
execute 'clean build', platform
end
end
end
desc 'updated the podspec on cocoapods'
task :update_pod do
sh "bundle exec pod trunk push Charts.podspec --allow-warnings"
end