Fastfile 4.9 KB

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