Class: Fastlane::Actions::StoreSizeXcarchiveAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/store_sizer/actions/store_size_xcarchive_action.rb

Constant Summary collapse

EXTRA_FILE_SIZE =
2_000_000

Class Method Summary collapse

Class Method Details

.authorsObject



66
67
68
# File 'lib/fastlane/plugin/store_sizer/actions/store_size_xcarchive_action.rb', line 66

def self.authors
  ["Marcelo Oliveira"]
end

.available_optionsObject



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/fastlane/plugin/store_sizer/actions/store_size_xcarchive_action.rb', line 84

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :archive_path,
                                 description: 'Path to your xcarchive file. Optional if you use the `xcodebuild` action',
                                 default_value: Actions.lane_context[SharedValues::XCODEBUILD_ARCHIVE],
                                 optional: true,
                                 env_name: 'STORE_SIZE_ARCHIVE_PATH',
                                 verify_block: proc do |value|
                                   UI.user_error!("Couldn't find xcarchive file at path '#{value}'") if !Helper.test? && !File.exist?(value)
                                 end)
  ]
end

.descriptionObject



62
63
64
# File 'lib/fastlane/plugin/store_sizer/actions/store_size_xcarchive_action.rb', line 62

def self.description
  "Estimates download and install sizes for your app"
end

.detailsObject



80
81
82
# File 'lib/fastlane/plugin/store_sizer/actions/store_size_xcarchive_action.rb', line 80

def self.details
  "Compute estimated size of the .ipa after encryption and App Thinning for all variants"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/fastlane/plugin/store_sizer/actions/store_size_xcarchive_action.rb', line 97

def self.is_supported?(platform)
  [:ios].include?(platform)
end

.outputObject



70
71
72
73
74
# File 'lib/fastlane/plugin/store_sizer/actions/store_size_xcarchive_action.rb', line 70

def self.output
  [
    ['SIZE_REPORT', 'The generated size report hash']
  ]
end

.return_valueObject



76
77
78
# File 'lib/fastlane/plugin/store_sizer/actions/store_size_xcarchive_action.rb', line 76

def self.return_value
  "Hash containing App Thinning report"
end

.run(params) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fastlane/plugin/store_sizer/actions/store_size_xcarchive_action.rb', line 10

def self.run(params)
  require 'plist'

  unless Fastlane::Helper.test?
    UI.user_error!("xcodebuild not installed") if `which xcodebuild`.length == 0
  end

  archive_path = params[:archive_path] || Actions.lane_context[SharedValues::XCODEBUILD_ARCHIVE]
  app_path = Dir.glob(File.join(archive_path, "Products", "Applications", "*.app")).first
  UI.user_error!("No applications found in archive") if app_path.nil?

  binary_name = File.basename(app_path, ".app")
  binary_path = File.join(app_path, binary_name)
  extra_file_path = File.join(app_path, "extradata_simulated")
  result = {}

  Dir.mktmpdir do |tmp_path|
    binary_backup_path = File.join(tmp_path, binary_name)
    export_path = File.join(tmp_path, "Export")
    begin
      FileUtils.mv(binary_path, binary_backup_path)
      FileUtils.cp(binary_backup_path, binary_path)

      macho_info = Helper::MachoInfo.new(binary_path)

      Helper::StoreSizerHelper.write_random_segments(binary_path, macho_info.encryption_segments)
      Helper::StoreSizerHelper.write_random_file(extra_file_path, EXTRA_FILE_SIZE)

      export_options = {}
      export_options[:method] = 'ad-hoc'
      export_options[:thinning] = '<thin-for-all-variants>'
      export_options_plist_path = File.join(tmp_path, "ExportOptions.plist")
      File.write(export_options_plist_path, Plist::Emit.dump(export_options, false))

      UI.message("Exporting all variants of #{archive_path} for estimation...")
      Helper::StoreSizerHelper.xcode_export_package(archive_path, export_options_plist_path, export_path)

      UI.verbose(File.read(File.join(export_path, "App Thinning Size Report.txt")))

      result = Plist.parse_xml(File.join(export_path, "app-thinning.plist"))
      result.merge!(macho_info.sizes_info)
    ensure
      FileUtils.rm_f(binary_path)
      FileUtils.mv(binary_backup_path, binary_path)
      FileUtils.rm_f(extra_file_path)
    end
  end

  Actions.lane_context[SharedValues::SIZE_REPORT] = result
  result
end