Fastfile 4.9 KB

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