Fastfile 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. xcversion(version: "~> 11.0")
  86. FileUtils.rm_rf '../build'
  87. frameworks = []
  88. ["macosx",
  89. "iphoneos",
  90. "iphonesimulator",
  91. "appletvos",
  92. "appletvsimulator",
  93. "watchos",
  94. "watchsimulator"
  95. ].each do |sdk|
  96. archive_path = "build/Kingfisher-#{sdk}.xcarchive"
  97. xcodebuild(
  98. archive: true,
  99. archive_path: archive_path,
  100. scheme: "Kingfisher",
  101. sdk: sdk,
  102. build_settings: {
  103. "BUILD_LIBRARY_FOR_DISTRIBUTION" => "YES",
  104. "SKIP_INSTALL" => "NO"
  105. }
  106. )
  107. frameworks.push("#{archive_path}/Products/Library/Frameworks/Kingfisher.framework")
  108. dSYM_path = "../#{archive_path}/dSYMs/Kingfisher.framework.dSYM"
  109. FileUtils.mkdir_p("#{supporting_root}/#{sdk}/dSYMs/")
  110. FileUtils.cp_r(dSYM_path, "#{supporting_root}/#{sdk}/dSYMs/Kingfisher.framework.dSYM")
  111. bitcode_symbol_map_path = "../#{archive_path}/BCSymbolMaps/"
  112. if Dir.exist?(bitcode_symbol_map_path)
  113. FileUtils.mkdir_p("#{supporting_root}/#{sdk}/BCSymbolMaps/")
  114. FileUtils.cp_r(bitcode_symbol_map_path, "#{supporting_root}/#{sdk}")
  115. end
  116. end
  117. # `xcodebuild` action in fastlane does not support `-create-xcframework` arg yet.
  118. # Change it back to use fastlane action later when it is prepared.
  119. framework_args = frameworks.map { |framework_path| "-framework '#{framework_path}'"}
  120. args = "-create-xcframework #{framework_args.join(" ")} -output 'build/#{target_version}/Kingfisher.xcframework'"
  121. Dir.chdir("..") do
  122. Action.sh "xcodebuild #{args}"
  123. end
  124. zip(
  125. path: "build/#{target_version}",
  126. output_path: "build/#{target_version}.zip"
  127. )
  128. end
  129. after_all do |lane|
  130. end
  131. error do |lane, exception|
  132. end
  133. end