Class: Fastlane::Actions::StoreSizeXcarchiveCheckAction

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

Constant Summary collapse

MAX_TEXT_6_LESS =

Apple sizes reference goo.gl/6A3nQK

80_000_000
MAX_SEGMENT_7_TO_8 =
60_000_000
MAX_TEXT_9_PLUS =
500_000_000
DEFAULT_MAX_WIFI_SIZE =
100_000_000

Class Method Summary collapse

Class Method Details

.authorsObject



48
49
50
# File 'lib/fastlane/plugin/store_sizer/actions/store_size_xcarchive_check_action.rb', line 48

def self.authors
  ["Marcelo Oliveira"]
end

.available_optionsObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fastlane/plugin/store_sizer/actions/store_size_xcarchive_check_action.rb', line 62

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :report,
                                 description: 'Generated report. Optional if you use the `store_size_xcarchive` action',
                                 default_value: Actions.lane_context[SharedValues::SIZE_REPORT],
                                 type: Hash,
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Invalid report!'") if !Helper.test? && value["variants"].nil?
                                 end),
    FastlaneCore::ConfigItem.new(key: :ignore_universal,
                                 description: 'True to ignore universal variant',
                                 default_value: true,
                                 is_string: false,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :max_wifi_size,
                                 description: 'Max Wi-Fi download size, pass 0 to ignore',
                                 default_value: DEFAULT_MAX_WIFI_SIZE,
                                 type: Integer,
                                 optional: true)
  ]
end

.descriptionObject



44
45
46
# File 'lib/fastlane/plugin/store_sizer/actions/store_size_xcarchive_check_action.rb', line 44

def self.description
  "Checks if the size report fits the requirements"
end

.detailsObject



58
59
60
# File 'lib/fastlane/plugin/store_sizer/actions/store_size_xcarchive_check_action.rb', line 58

def self.details
  "Checks estimated size for all non-universal variants and maximum executable sizes"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/fastlane/plugin/store_sizer/actions/store_size_xcarchive_check_action.rb', line 85

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

.outputObject



52
53
# File 'lib/fastlane/plugin/store_sizer/actions/store_size_xcarchive_check_action.rb', line 52

def self.output
end

.return_valueObject



55
56
# File 'lib/fastlane/plugin/store_sizer/actions/store_size_xcarchive_check_action.rb', line 55

def self.return_value
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
# File 'lib/fastlane/plugin/store_sizer/actions/store_size_xcarchive_check_action.rb', line 10

def self.run(params)
  report = params[:report]

  errors = 0
  error = proc do |message|
    errors += 1
    UI.error(message)
  end

  unless report["min_os_version"].nil?
    major_version = report["min_os_version"][0]
    text_size = report["text_segments_size"]
    max_slice_size = report["text_max_slice_size"]
    error.call("__TEXT segments size #{text_size} greater than #{MAX_TEXT_6_LESS}") if major_version <= 6 && text_size > MAX_TEXT_6_LESS
    error.call("__TEXT #{max_slice_size} greater than #{MAX_SEGMENT_7_TO_8}") if major_version.between?(7, 8) && max_slice_size > MAX_SEGMENT_7_TO_8
    error.call("__TEXT segments size #{text_size} greater than #{MAX_TEXT_9_PLUS}") if major_version >= 9 && text_size > MAX_TEXT_9_PLUS
  end

  max_wifi_size = params[:max_wifi_size] || DEFAULT_MAX_WIFI_SIZE

  if max_wifi_size > 0 && !report["variants"].nil?
    report["variants"].each do |name, variant|
      next if variant["variantIds"].nil? && params[:ignore_universal]

      size = variant["sizeCompressedApp"]
      error.call("Variant #{name} size #{size} greater than #{max_wifi_size}") if size > max_wifi_size
    end
  end

  UI.test_failure!("Size check failed, #{errors} sizes exceeded the limits") if errors > 0

  UI.success("App size check suceeded")
end