Fastfile 5.0 KB

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