Explorar el Código

Refactoring the xcframework action

onevcat hace 1 año
padre
commit
bb0fec2324
Se han modificado 1 ficheros con 57 adiciones y 60 borrados
  1. 57 60
      fastlane/Fastfile

+ 57 - 60
fastlane/Fastfile

@@ -88,79 +88,76 @@ platform :ios do
   end
 
   lane :xcframework do |options|
-    target_version = "Kingfisher-#{options[:version]}"
-    
+    version = options[:version]
     swift_version = options[:swift_version] || "5.0"
     xcode_version = options[:xcode_version] || "16.2"
 
     xcodes(version: xcode_version, select_for_current_build_only: true)
-
     FileUtils.rm_rf '../build'
-    
-    frameworks = {}
-    
-    ["macosx",
-     "iphoneos", 
-     "iphonesimulator", 
-     "appletvos", 
-     "appletvsimulator", 
-     "watchos", 
-     "watchsimulator",
-     "xros",
-     "xrsimulator"
-    ].each do |sdk|
-      archive_path = "build/Kingfisher-#{sdk}.xcarchive"
-      xcodebuild(
-        archive: true,
-        archive_path: archive_path,
-        scheme: "Kingfisher",
-        sdk: sdk,
-        build_settings: {
-          "BUILD_LIBRARY_FOR_DISTRIBUTION" => "YES",
-          "SKIP_INSTALL" => "NO",
-          "SWIFT_VERSION" => swift_version
-        }
-      )
 
-      dSYM_path = "#{Dir.pwd}/../#{archive_path}/dSYMs/Kingfisher.framework.dSYM"
-      frameworks["#{archive_path}/Products/Library/Frameworks/Kingfisher.framework"] = { dsyms: dSYM_path }
+    # Define platform to SDKs mapping
+    PLATFORM_SDKS = {
+      all: [
+        "macosx",
+        "iphoneos", "iphonesimulator",
+        "appletvos", "appletvsimulator",
+        "watchos", "watchsimulator",
+        "xros", "xrsimulator"
+      ],
+      ios: ["iphoneos", "iphonesimulator"]
+    }
+
+    def create_archives(sdks, swift_version)
+      frameworks = {}
+      sdks.each do |sdk|
+        archive_path = "build/Kingfisher-#{sdk}.xcarchive"
+        xcodebuild(
+          archive: true,
+          archive_path: archive_path,
+          scheme: "Kingfisher",
+          sdk: sdk,
+          build_settings: {
+            "BUILD_LIBRARY_FOR_DISTRIBUTION" => "YES",
+            "SKIP_INSTALL" => "NO",
+            "SWIFT_VERSION" => swift_version
+          }
+        )
+
+        framework_path = "#{archive_path}/Products/Library/Frameworks/Kingfisher.framework"
+        dsym_path = "#{Dir.pwd}/../#{archive_path}/dSYMs/Kingfisher.framework.dSYM"
+        frameworks[framework_path] = { dsyms: dsym_path }
+      end
+      frameworks
     end
 
-    create_xcframework(
-      frameworks_with_dsyms: frameworks, 
-      output: "build/#{target_version}/Kingfisher.xcframework"
-    )
+    def create_and_package_xcframework(frameworks, output_name, version)
+      output_base_name = if output_name.empty?
+        "Kingfisher-#{version}"
+      else
+        "Kingfisher-#{output_name}-#{version}"
+      end
+      
+      create_xcframework(
+        frameworks_with_dsyms: frameworks,
+        output: "build/#{output_base_name}/Kingfisher.xcframework"
+      )
 
-    Actions.sh("codesign --timestamp -v --sign 'Apple Distribution: Wei Wang (A4YJ9MRZ66)' ../build/#{target_version}/Kingfisher.xcframework")
+      Actions.sh("codesign --timestamp -v --sign 'Apple Distribution: Wei Wang (A4YJ9MRZ66)' ../build/#{output_base_name}/Kingfisher.xcframework")
 
-    zip(
-      path: "build/#{target_version}",
-      output_path: "build/#{target_version}.zip",
-      symlinks: true
-    )
-
-    # Create iOS only xcframework
-    ios_frameworks = {}
-    ["iphoneos", "iphonesimulator"].each do |sdk|
-      archive_path = "build/Kingfisher-#{sdk}.xcarchive"
-      ios_frameworks["#{archive_path}/Products/Library/Frameworks/Kingfisher.framework"] = { 
-        dsyms: "#{Dir.pwd}/../#{archive_path}/dSYMs/Kingfisher.framework.dSYM" 
-      }
+      zip(
+        path: "build/#{output_base_name}",
+        output_path: "build/#{output_base_name}.zip",
+        symlinks: true
+      )
     end
 
-    ios_target_version = "Kingfisher-iOS-#{options[:version]}"
-    create_xcframework(
-      frameworks_with_dsyms: ios_frameworks,
-      output: "build/#{ios_target_version}/Kingfisher.xcframework"
-    )
+    # Create full platform xcframework
+    all_frameworks = create_archives(PLATFORM_SDKS[:all], swift_version)
+    create_and_package_xcframework(all_frameworks, "", version)
 
-    Actions.sh("codesign --timestamp -v --sign 'Apple Distribution: Wei Wang (A4YJ9MRZ66)' ../build/#{ios_target_version}/Kingfisher.xcframework")
-
-    zip(
-      path: "build/#{ios_target_version}",
-      output_path: "build/#{ios_target_version}.zip",
-      symlinks: true
-    )
+    # Create iOS only xcframework
+    ios_frameworks = create_archives(PLATFORM_SDKS[:ios], swift_version)
+    create_and_package_xcframework(ios_frameworks, "iOS", version)
   end
 
   before_all do |lane|