Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to build demo projects unit tests on iOS #3121

Merged
merged 2 commits into from
Dec 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 49 additions & 15 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ def type
end

def project_name
'Charts.xcodeproj'
'ChartsDemo/ChartsDemo.xcodeproj'
end

def macos_project_name
'ChartsDemo-OSX/ChartsDemo-OSX.xcodeproj'
end

def configuration
Expand All @@ -29,6 +33,19 @@ def build_schemes
]
end

def build_demo_schemes
%i[
ChartsDemo
ChartsDemo-Swift
]
end

def build_macos_demo_schemes
[
'ChartsDemo-OSX'
]
end

def test_schemes
[
'ChartsTests'
Expand Down Expand Up @@ -74,33 +91,43 @@ def xcodebuild(type, name, scheme, configuration, sdk, destination, tasks, xcpre
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)
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_name, scheme, configuration, sdk, device, tasks, xcprety_args
xcodebuild type, project, scheme, configuration, sdk, device, tasks, xcprety_args
end
end

def execute(tasks, platform, xcprety_args: '')
is_test = tasks.include?('test')

def execute(tasks, platform, is_build_demo = false, xcprety_args: '')
# 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
run_xcodebuild tasks, destination, is_build_demo, xcprety_args
end
else
run_xcodebuild schemes, tasks, destination, is_test, xcprety_args
run_xcodebuild tasks, destination, is_build_demo, xcprety_args
end
end

Expand All @@ -122,11 +149,18 @@ 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)

if test_platforms.include?(platform)
execute 'clean test', platform
elsif build_platforms.include?(platform)
execute 'clean build', 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
Expand Down