forked from ChartsOrg/Charts
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Rakefile
182 lines (156 loc) · 3.99 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
def type
:project # set `:project` for xcodeproj and `:workspace` for xcworkspace
end
def project_name
'ChartsDemo-iOS/ChartsDemo-iOS.xcodeproj'
end
def macos_project_name
'ChartsDemo-macOS/ChartsDemo-macOS.xcodeproj'
end
def configuration
'Debug'
end
def test_platforms
%i[
iOS
tvOS
]
end
def build_platforms
[
:macOS
]
end
def build_schemes
%w[
Charts
]
end
def build_demo_schemes
%i[
ChartsDemo-iOS
ChartsDemo-iOS-Swift
]
end
def build_macos_demo_schemes
[
'ChartsDemo-macOS'
]
end
def test_schemes
[
'ChartsTests'
]
end
def devices
{
iOS: {
sdk: 'iphonesimulator',
device: "name='iPhone 7'",
name: 'iPhone 7'
},
macOS: {
sdk: 'macosx',
device: "arch='x86_64'",
uuid: nil
},
tvOS: {
sdk: 'appletvsimulator',
device: "name='Apple TV'",
name: 'Apple TV'
}
}
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(tasks, destination, is_build_demo, xcprety_args)
sdk = destination[:sdk]
device = destination[:device]
uuid = destination[:uuid]
is_test = tasks.include?('test')
is_macos = sdk == 'macosx'
project = is_macos ? macos_project_name : project_name
schemes_to_execute = []
if is_test
schemes_to_execute = test_schemes
elsif is_build_demo
schemes_to_execute = is_macos ? build_macos_demo_schemes : build_demo_schemes
else
schemes_to_execute = build_schemes
end
open_simulator_and_sleep uuid if is_test
schemes_to_execute.each do |scheme|
xcodebuild type, project, scheme, configuration, sdk, device, tasks, xcprety_args
end
end
def execute(tasks, platform, is_build_demo = false, xcprety_args: '')
# platform specific settings
destination = devices[platform]
# check if xcodebuild needs to be run on multiple devices
if destination.is_a?(Array)
destination.each do |destination|
run_xcodebuild tasks, destination, is_build_demo, xcprety_args
end
else
run_xcodebuild tasks, destination, is_build_demo, 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.key?(:platform)
is_build_demo = test_platforms.include?(platform) || build_platforms.include?(platform)
if test_platforms.include?(platform) # iOS and tvOS
if platform == :iOS
execute 'clean', platform, is_build_demo
execute 'build', platform, is_build_demo
execute 'test', platform # not use demo specifically
else
execute 'clean test', platform
end
elsif build_platforms.include?(platform) # macOS
execute 'clean build', platform, is_build_demo
else
test_platforms.each do |platform|
execute 'clean 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
desc 'generate changelog'
task :generate_changelog do
sh 'github_changelog_generator'
end