Fastfile 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 15,OS=17.5")
  8. test(destination: "platform=tvOS Simulator,name=Apple TV,OS=17.5")
  9. build(destination: "platform=watchOS Simulator,name=Apple Watch Series 9 (41mm),OS=10.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: ["build/Kingfisher-#{target_version}.zip"]
  68. )
  69. pod_push
  70. end
  71. lane :xcframework do |options|
  72. version = options[:version]
  73. swift_version = options[:swift_version] || "5.0"
  74. xcode_version = options[:xcode_version] || "16.2"
  75. xcodes(version: xcode_version, select_for_current_build_only: true)
  76. FileUtils.rm_rf '../build'
  77. # Define platform to SDKs mapping
  78. PLATFORM_SDKS = {
  79. all: [
  80. "macosx",
  81. "iphoneos", "iphonesimulator",
  82. "appletvos", "appletvsimulator",
  83. "watchos", "watchsimulator",
  84. "xros", "xrsimulator"
  85. ],
  86. ios: ["iphoneos", "iphonesimulator"]
  87. }
  88. def create_archives(sdks, swift_version)
  89. frameworks = {}
  90. sdks.each do |sdk|
  91. archive_path = "build/Kingfisher-#{sdk}.xcarchive"
  92. xcodebuild(
  93. archive: true,
  94. archive_path: archive_path,
  95. scheme: "Kingfisher",
  96. sdk: sdk,
  97. build_settings: {
  98. "BUILD_LIBRARY_FOR_DISTRIBUTION" => "YES",
  99. "SKIP_INSTALL" => "NO",
  100. "SWIFT_VERSION" => swift_version
  101. }
  102. )
  103. framework_path = "#{archive_path}/Products/Library/Frameworks/Kingfisher.framework"
  104. dsym_path = "#{Dir.pwd}/../#{archive_path}/dSYMs/Kingfisher.framework.dSYM"
  105. frameworks[framework_path] = { dsyms: dsym_path }
  106. end
  107. frameworks
  108. end
  109. def create_and_package_xcframework(frameworks, output_name, version)
  110. output_base_name = if output_name.empty?
  111. "Kingfisher-#{version}"
  112. else
  113. "Kingfisher-#{output_name}-#{version}"
  114. end
  115. create_xcframework(
  116. frameworks_with_dsyms: frameworks,
  117. output: "build/#{output_base_name}/Kingfisher.xcframework"
  118. )
  119. Actions.sh("codesign --timestamp -v --sign 'Apple Distribution: Wei Wang (A4YJ9MRZ66)' ../build/#{output_base_name}/Kingfisher.xcframework")
  120. zip(
  121. path: "build/#{output_base_name}",
  122. output_path: "build/#{output_base_name}.zip",
  123. symlinks: true
  124. )
  125. end
  126. # Create full platform xcframework
  127. all_frameworks = create_archives(PLATFORM_SDKS[:all], swift_version)
  128. create_and_package_xcframework(all_frameworks, "", version)
  129. # Create iOS only xcframework
  130. ios_frameworks = create_archives(PLATFORM_SDKS[:ios], swift_version)
  131. create_and_package_xcframework(ios_frameworks, "iOS", version)
  132. end
  133. before_all do |lane|
  134. xcode_version = ENV["XCODE_VERSION"] || "16.2"
  135. xcodes(version: xcode_version, select_for_current_build_only: true)
  136. end
  137. after_all do |lane|
  138. end
  139. error do |lane, exception|
  140. end
  141. end