Fastfile 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. fastlane_version "1.37.0"
  2. default_platform :ios
  3. platform :ios do
  4. desc "Runs all the tests"
  5. lane :tests do
  6. test(destination: "platform=macOS", swift_version: "5.0")
  7. test(destination: "platform=macOS", swift_version: "4.2")
  8. test(destination: "platform=macOS", swift_version: "4.0")
  9. test(destination: "platform=iOS Simulator,name=iPhone 8", swift_version: "5.0")
  10. test(destination: "platform=iOS Simulator,name=iPhone 8", swift_version: "4.2")
  11. test(destination: "platform=iOS Simulator,name=iPhone 8", swift_version: "4.0")
  12. test(destination: "platform=tvOS Simulator,name=Apple TV", swift_version: "5.0")
  13. test(destination: "platform=tvOS Simulator,name=Apple TV", swift_version: "4.2")
  14. test(destination: "platform=tvOS Simulator,name=Apple TV", swift_version: "4.0")
  15. build(destination: "platform=watchOS Simulator,name=Apple Watch Series 5 - 40mm", swift_version: "4.0")
  16. build(destination: "platform=watchOS Simulator,name=Apple Watch Series 5 - 40mm", swift_version: "4.2")
  17. build(destination: "platform=watchOS Simulator,name=Apple Watch Series 5 - 40mm", swift_version: "5.0")
  18. end
  19. lane :test_ci do
  20. if ENV["DESTINATION"].include? "watchOS" then
  21. build(destination: ENV["DESTINATION"], swift_version: ENV["SWIFT_VERSION"])
  22. else
  23. test(destination: ENV["DESTINATION"], swift_version: ENV["SWIFT_VERSION"])
  24. end
  25. end
  26. lane :test do |options|
  27. scan(
  28. scheme: "Kingfisher",
  29. clean: true,
  30. xcargs: "SWIFT_VERSION=#{options[:swift_version]}",
  31. destination: options[:destination]
  32. )
  33. end
  34. lane :build do |options|
  35. gym(
  36. workspace: "Kingfisher.xcworkspace",
  37. configuration: "Debug",
  38. scheme: "Kingfisher",
  39. xcargs: "SWIFT_VERSION=#{options[:swift_version]}",
  40. destination: options[:destination]
  41. )
  42. end
  43. desc "Lint"
  44. lane :lint do
  45. # carthage(command: "build", no_skip_current: true, platform: "iOS")
  46. pod_lib_lint
  47. end
  48. desc "Release new version"
  49. lane :release do |options|
  50. target_version = options[:version]
  51. raise "The version is missed. Use `fastlane release version:{version_number}`.`" if target_version.nil?
  52. ensure_git_branch
  53. ensure_git_status_clean
  54. skip_tests = options[:skip_tests]
  55. tests unless skip_tests
  56. lint
  57. sync_build_number_to_git
  58. increment_version_number(version_number: target_version)
  59. version_bump_podspec(path: "Kingfisher.podspec", version_number: target_version)
  60. log = extract_current_change_log(version: target_version)
  61. release_log = update_change_log(log: log)
  62. # doc(version: target_version)
  63. git_commit_all(message: "Bump version to #{target_version}")
  64. Actions.sh("git tag -s #{target_version} -m ''")
  65. push_to_git_remote
  66. xcframework(version: target_version)
  67. set_github_release(
  68. repository_name: "onevcat/Kingfisher",
  69. api_token: ENV['GITHUB_TOKEN'],
  70. name: release_log[:title],
  71. tag_name: target_version,
  72. description: release_log[:text],
  73. upload_assets: ["build/Kingfisher-#{target_version}.zip"]
  74. )
  75. pod_push
  76. end
  77. lane :podpush do
  78. pod_push
  79. end
  80. lane :doc do |options|
  81. target_version = options[:version]
  82. Actions.sh("cd .. && jazzy \
  83. --clean \
  84. -x USE_SWIFT_RESPONSE_FILE=NO \
  85. --author \"Wei Wang\" \
  86. --author_url https://onevcat.com \
  87. --github_url https://github.com/onevcat/Kingfisher \
  88. --github-file-prefix https://github.com/onevcat/Kingfisher/tree/#{target_version} \
  89. --module-version #{target_version} \
  90. --module Kingfisher \
  91. --root-url http://onevcat.github.io/Kingfisher/ \
  92. --output docs/ \
  93. --theme fullwidth")
  94. end
  95. lane :xcframework do |options|
  96. target_version = "Kingfisher-#{options[:version]}"
  97. supporting_root = "../build/#{target_version}/Supporting Files"
  98. xcversion(version: "~> 12.0")
  99. FileUtils.rm_rf '../build'
  100. frameworks = []
  101. ["macosx",
  102. "iphoneos",
  103. "iphonesimulator",
  104. "appletvos",
  105. "appletvsimulator",
  106. "watchos",
  107. "watchsimulator"
  108. ].each do |sdk|
  109. archive_path = "build/Kingfisher-#{sdk}.xcarchive"
  110. xcodebuild(
  111. archive: true,
  112. archive_path: archive_path,
  113. scheme: "Kingfisher",
  114. sdk: sdk,
  115. build_settings: {
  116. "BUILD_LIBRARY_FOR_DISTRIBUTION" => "YES",
  117. "SKIP_INSTALL" => "NO"
  118. }
  119. )
  120. frameworks.push("#{archive_path}/Products/Library/Frameworks/Kingfisher.framework")
  121. dSYM_path = "../#{archive_path}/dSYMs/Kingfisher.framework.dSYM"
  122. FileUtils.mkdir_p("#{supporting_root}/#{sdk}/dSYMs/")
  123. FileUtils.cp_r(dSYM_path, "#{supporting_root}/#{sdk}/dSYMs/Kingfisher.framework.dSYM")
  124. bitcode_symbol_map_path = "../#{archive_path}/BCSymbolMaps/"
  125. if Dir.exist?(bitcode_symbol_map_path)
  126. FileUtils.mkdir_p("#{supporting_root}/#{sdk}/BCSymbolMaps/")
  127. FileUtils.cp_r(bitcode_symbol_map_path, "#{supporting_root}/#{sdk}")
  128. end
  129. end
  130. # `xcodebuild` action in fastlane does not support `-create-xcframework` arg yet.
  131. # Change it back to use fastlane action later when it is prepared.
  132. framework_args = frameworks.map { |framework_path| "-framework '#{framework_path}'"}
  133. args = "-create-xcframework #{framework_args.join(" ")} -output 'build/#{target_version}/Kingfisher.xcframework'"
  134. Dir.chdir("..") do
  135. Action.sh "xcodebuild #{args}"
  136. end
  137. zip(
  138. path: "build/#{target_version}",
  139. output_path: "build/#{target_version}.zip"
  140. )
  141. end
  142. after_all do |lane|
  143. end
  144. error do |lane, exception|
  145. end
  146. end