Fastfile 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. fastlane_version "1.37.0"
  2. default_platform :ios
  3. platform :ios do
  4. def normalize_destination(destination)
  5. return destination if destination.to_s.empty?
  6. return destination if destination.include?("arch=")
  7. return destination unless destination.include?("Simulator")
  8. host_arch = Actions.sh("uname -m", log: false).strip
  9. return destination unless host_arch == "arm64"
  10. "#{destination},arch=arm64"
  11. end
  12. desc "Runs all the tests"
  13. lane :tests do
  14. test(destination: "platform=macOS")
  15. test(destination: "platform=iOS Simulator,name=iPhone 16,OS=18.5")
  16. test(destination: "platform=tvOS Simulator,name=Apple TV,OS=18.5")
  17. build(destination: "platform=watchOS Simulator,name=Apple Watch Series 10 (42mm),OS=11.5")
  18. end
  19. lane :test_ci do
  20. if ENV["DESTINATION"].include? "watchOS" then
  21. build(destination: ENV["DESTINATION"])
  22. else
  23. test(destination: ENV["DESTINATION"])
  24. end
  25. end
  26. lane :build_ci do
  27. build(destination: ENV["DESTINATION"])
  28. end
  29. lane :test do |options|
  30. destination = normalize_destination(options[:destination])
  31. scan(
  32. scheme: "Kingfisher",
  33. clean: true,
  34. xcargs: "SWIFT_VERSION=5.0",
  35. destination: destination
  36. )
  37. end
  38. lane :build do |options|
  39. destination = normalize_destination(options[:destination])
  40. xcodebuild(
  41. workspace: "Kingfisher.xcworkspace",
  42. configuration: "Debug",
  43. scheme: "Kingfisher",
  44. destination: destination,
  45. build: true,
  46. build_settings: {
  47. "SWIFT_VERSION" => "5.0"
  48. }
  49. )
  50. end
  51. desc "Lint"
  52. lane :lint do
  53. pod_lib_lint
  54. spm
  55. end
  56. desc "Release new version"
  57. lane :release do |options|
  58. target_version = options[:version]
  59. raise "The version is missed. Use `fastlane release version:{version_number}`.`" if target_version.nil?
  60. ensure_git_branch
  61. ensure_git_status_clean
  62. skip_tests = options[:skip_tests]
  63. tests unless skip_tests
  64. lint
  65. sync_build_number_to_git
  66. increment_version_number(version_number: target_version)
  67. version_bump_podspec(path: "Kingfisher.podspec", version_number: target_version)
  68. log = extract_current_change_log(version: target_version)
  69. release_log = update_change_log(log: log)
  70. git_commit_all(message: "Bump version to #{target_version}")
  71. Actions.sh("git tag -s #{target_version} -m ''")
  72. push_to_git_remote
  73. xcframework(version: target_version)
  74. set_github_release(
  75. repository_name: "onevcat/Kingfisher",
  76. api_token: ENV['GITHUB_TOKEN'],
  77. name: release_log[:title],
  78. tag_name: target_version,
  79. description: release_log[:text],
  80. upload_assets: [
  81. "build/Kingfisher-#{target_version}.xcframework.zip",
  82. "build/Kingfisher-iOS-#{target_version}.xcframework.zip"
  83. ]
  84. )
  85. pod_push
  86. end
  87. lane :xcframework do |options|
  88. version = options[:version]
  89. swift_version = options[:swift_version] || "5.0"
  90. xcode_version = options[:xcode_version] || "26.2.0"
  91. xcodes(version: xcode_version, select_for_current_build_only: true)
  92. FileUtils.rm_rf '../build'
  93. # Define platform to SDKs mapping
  94. PLATFORM_SDKS = {
  95. all: [
  96. "macosx",
  97. "iphoneos", "iphonesimulator",
  98. "appletvos", "appletvsimulator",
  99. "watchos", "watchsimulator",
  100. "xros", "xrsimulator"
  101. ],
  102. ios: ["iphoneos", "iphonesimulator"]
  103. }
  104. def create_archives(sdks, swift_version)
  105. frameworks = {}
  106. sdks.each do |sdk|
  107. archive_path = "build/Kingfisher-#{sdk}.xcarchive"
  108. xcodebuild(
  109. archive: true,
  110. archive_path: archive_path,
  111. scheme: "Kingfisher",
  112. sdk: sdk,
  113. build_settings: {
  114. "BUILD_LIBRARY_FOR_DISTRIBUTION" => "YES",
  115. "SKIP_INSTALL" => "NO",
  116. "SWIFT_VERSION" => swift_version
  117. }
  118. )
  119. framework_path = "#{archive_path}/Products/Library/Frameworks/Kingfisher.framework"
  120. dsym_path = "#{Dir.pwd}/../#{archive_path}/dSYMs/Kingfisher.framework.dSYM"
  121. frameworks[framework_path] = { dsyms: dsym_path }
  122. end
  123. frameworks
  124. end
  125. def create_and_package_xcframework(frameworks, output_name, version)
  126. output_base_name = if output_name.empty?
  127. "Kingfisher-#{version}"
  128. else
  129. "Kingfisher-#{output_name}-#{version}"
  130. end
  131. output_xcframework_path = "build/#{output_base_name}/Kingfisher.xcframework"
  132. create_xcframework(
  133. frameworks_with_dsyms: frameworks,
  134. output: output_xcframework_path
  135. )
  136. Actions.sh("codesign --timestamp -v --sign 'Apple Distribution: Wei Wang (A4YJ9MRZ66)' ../build/#{output_base_name}/Kingfisher.xcframework")
  137. zip(
  138. path: output_xcframework_path,
  139. output_path: "build/#{output_base_name}.xcframework.zip",
  140. symlinks: true
  141. )
  142. end
  143. # Create full platform xcframework
  144. all_frameworks = create_archives(PLATFORM_SDKS[:all], swift_version)
  145. create_and_package_xcframework(all_frameworks, "", version)
  146. # Create iOS only xcframework
  147. ios_frameworks = create_archives(PLATFORM_SDKS[:ios], swift_version)
  148. create_and_package_xcframework(ios_frameworks, "iOS", version)
  149. end
  150. before_all do |lane|
  151. xcode_version = ENV["XCODE_VERSION"] || "26.2.0"
  152. xcodes(version: xcode_version, select_for_current_build_only: true)
  153. end
  154. after_all do |lane|
  155. end
  156. error do |lane, exception|
  157. end
  158. end