Rakefile 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. def type
  2. :project # set `:project` for xcodeproj and `:workspace` for xcworkspace
  3. end
  4. def project_name
  5. 'ChartsDemo-iOS/ChartsDemo-iOS.xcodeproj'
  6. end
  7. def macos_project_name
  8. 'ChartsDemo-macOS/ChartsDemo-macOS.xcodeproj'
  9. end
  10. def configuration
  11. 'Debug'
  12. end
  13. def test_platforms
  14. %i[
  15. iOS
  16. tvOS
  17. ]
  18. end
  19. def build_platforms
  20. [
  21. :macOS
  22. ]
  23. end
  24. def build_schemes
  25. %w[
  26. Charts
  27. ]
  28. end
  29. def build_demo_schemes
  30. %i[
  31. ChartsDemo-iOS
  32. ChartsDemo-iOS-Swift
  33. ]
  34. end
  35. def build_macos_demo_schemes
  36. [
  37. 'ChartsDemo-macOS'
  38. ]
  39. end
  40. def test_schemes
  41. [
  42. 'ChartsTests'
  43. ]
  44. end
  45. def devices
  46. {
  47. iOS: {
  48. sdk: 'iphonesimulator',
  49. device: "name='iPhone 7'",
  50. name: 'iPhone 7'
  51. },
  52. macOS: {
  53. sdk: 'macosx',
  54. device: "arch='x86_64'",
  55. uuid: nil
  56. },
  57. tvOS: {
  58. sdk: 'appletvsimulator',
  59. device: "name='Apple TV'",
  60. name: 'Apple TV'
  61. }
  62. }
  63. end
  64. def open_simulator_and_sleep(uuid)
  65. return if uuid.nil? # Don't need a sleep on macOS because it runs first.
  66. sh "xcrun instruments -w '#{uuid}' || sleep 15"
  67. end
  68. def xcodebuild(type, name, scheme, configuration, sdk, destination, tasks, xcprety_args)
  69. # set either workspace or project flag for xcodebuild
  70. case type
  71. when :project
  72. project_type = '-project'
  73. when :workspace
  74. project_type = '-workspace'
  75. else
  76. abort 'Invalid project type, use `:project` for xcodeproj and `:workspace` for xcworkspace.'
  77. end
  78. sh "set -o pipefail && xcodebuild #{project_type} '#{name}' -scheme '#{scheme}' -configuration '#{configuration}' -sdk #{sdk} -destination #{destination} #{tasks} | bundle exec xcpretty -c #{xcprety_args}"
  79. end
  80. def run_xcodebuild(tasks, destination, is_build_demo, xcprety_args)
  81. sdk = destination[:sdk]
  82. device = destination[:device]
  83. uuid = destination[:uuid]
  84. is_test = tasks.include?('test')
  85. is_macos = sdk == 'macosx'
  86. project = is_macos ? macos_project_name : project_name
  87. schemes_to_execute = []
  88. if is_test
  89. schemes_to_execute = test_schemes
  90. elsif is_build_demo
  91. schemes_to_execute = is_macos ? build_macos_demo_schemes : build_demo_schemes
  92. else
  93. schemes_to_execute = build_schemes
  94. end
  95. open_simulator_and_sleep uuid if is_test
  96. schemes_to_execute.each do |scheme|
  97. xcodebuild type, project, scheme, configuration, sdk, device, tasks, xcprety_args
  98. end
  99. end
  100. def execute(tasks, platform, is_build_demo = false, xcprety_args: '')
  101. # platform specific settings
  102. destination = devices[platform]
  103. # check if xcodebuild needs to be run on multiple devices
  104. if destination.is_a?(Array)
  105. destination.each do |destination|
  106. run_xcodebuild tasks, destination, is_build_demo, xcprety_args
  107. end
  108. else
  109. run_xcodebuild tasks, destination, is_build_demo, xcprety_args
  110. end
  111. end
  112. def arg_to_key(string_key)
  113. case string_key.downcase
  114. when 'ios'
  115. :iOS
  116. when 'tvos'
  117. :tvOS
  118. when 'macos'
  119. :macOS
  120. when 'watchos'
  121. :watchOS
  122. else
  123. abort 'Invalid platform, use `iOS`, `tvOS`, `macOS` or `watchOS`'
  124. end
  125. end
  126. desc 'Run CI tasks. Build and test or build depending on the platform.'
  127. task :ci, [:platform] do |_task, args|
  128. platform = arg_to_key(args[:platform]) if args.key?(:platform)
  129. is_build_demo = test_platforms.include?(platform) || build_platforms.include?(platform)
  130. if test_platforms.include?(platform) # iOS and tvOS
  131. if platform == :iOS
  132. execute 'clean', platform, is_build_demo
  133. execute 'build', platform, is_build_demo
  134. execute 'test', platform # not use demo specifically
  135. else
  136. execute 'clean test', platform
  137. end
  138. elsif build_platforms.include?(platform) # macOS
  139. execute 'clean build', platform, is_build_demo
  140. else
  141. test_platforms.each do |platform|
  142. execute 'clean test', platform
  143. end
  144. build_platforms.each do |platform|
  145. execute 'clean build', platform
  146. end
  147. end
  148. end
  149. desc 'updated the podspec on cocoapods'
  150. task :update_pod do
  151. sh 'bundle exec pod trunk push Charts.podspec --allow-warnings'
  152. end
  153. desc 'generate changelog'
  154. task :generate_changelog do
  155. sh 'github_changelog_generator'
  156. end