fastlane-plugin-store_sizer 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ac17078c20fbdb0299b160391ef7701138872932
4
+ data.tar.gz: 43390fda5a935830cd1aa8285438ab2af7a702d7
5
+ SHA512:
6
+ metadata.gz: 4ca50f777806a64f2a180497a67c13150b2176787ffea51c340766faa1e88200fdcd0aa48bf57a80663e32fedf8f80e60104bd7145a60cb7ea3dd6c91a797619
7
+ data.tar.gz: c1bda9fefb87598c8ce702c6acdd5506753c6d76492d7b3811a0463653ad7085b4e8879bd1e19685fb5e167a847f4b0d44075c43e89bd59e3010e9edf83d1c79
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Marcelo Oliveira <capyvara@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # store_sizer plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-store_sizer)
4
+
5
+ ## Getting Started
6
+
7
+ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-store_sizer`, add it to your project by running:
8
+
9
+ ```bash
10
+ fastlane add_plugin store_sizer
11
+ ```
12
+
13
+ ## About store_sizer
14
+
15
+ Estimates download and install sizes for your app, optionally checks and raise an error if the size exceeds given thresholds.
16
+
17
+ Some apps, specially games, struggle to keep their download sizes below the **100Mb** limit, due to carrier network download limits on iOS, however the way people usually get around it is to send the build to iTunesConnect and later check the sizes reported by Apple.
18
+
19
+ It works by **simulating the Apple encryption** of the app executable (random bytes are written to the TEXT segments of the executable file), plus some artificially added files, followed by an ad-hoc export of the archive with the exportOptionsPlist thinning set to _thin-for-all-variants_
20
+
21
+ Also check for Apple's [executable size constaints](https://developer.apple.com/library/content/documentation/LanguagesUtilities/Conceptual/iTunesConnect_Guide/Chapters/SubmittingTheApp.html)
22
+
23
+ Requires the Xcode _.xcarchive_, currently only **iOS** is supported.
24
+
25
+ ### Actions
26
+ #### `store_size_xcarchive`
27
+ Simulates encryption and returns a hash containing the reported size for all variants plus some info about the executable.
28
+
29
+ Parameters:
30
+ - `archive_path`: path to your .xcarchive
31
+
32
+ #### `store_size_xcarchive_check`
33
+ Checks executable size constraints and max download size, raise an error if exceeded.
34
+
35
+ Parameters:
36
+ - `report`: hash reported by the `store_size_xcarchive` action
37
+ - `ignore_universal`: should the universal variant be ignored? true per default (only devices <= iOS 8 uses the universal variant)
38
+ - `max_wifi_size`: overrides default 100Mb size check, pass 0 to disable wi-fi download size check
39
+
40
+ ## Example
41
+
42
+ Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin.
43
+
44
+ Unfortunately an example _.xcarchive_ can't be supplied since it will require distributing a signed executable, you will need to use your own.
45
+
46
+ Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test archive_path:YourArchive.xcarchive`.
47
+
48
+ ## Run tests for this plugin
49
+
50
+ To run both the tests, and code style validation, run
51
+
52
+ ```
53
+ rake
54
+ ```
55
+
56
+ To automatically fix many of the styling issues, use
57
+ ```
58
+ rubocop -a
59
+ ```
60
+
61
+ ## Issues and Feedback
62
+
63
+ For any other issues and feedback about this plugin, please submit it to this repository.
64
+
65
+ ## Troubleshooting
66
+
67
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
68
+
69
+ ## Using _fastlane_ Plugins
70
+
71
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
72
+
73
+ ## About _fastlane_
74
+
75
+ _fastlane_ is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
@@ -0,0 +1,16 @@
1
+ require 'fastlane/plugin/store_sizer/version'
2
+
3
+ module Fastlane
4
+ module StoreSizer
5
+ # Return all .rb files inside the "actions" and "helper" directory
6
+ def self.all_classes
7
+ Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
8
+ end
9
+ end
10
+ end
11
+
12
+ # By default we want to import all available actions and helpers
13
+ # A plugin can contain any number of actions and plugins
14
+ Fastlane::StoreSizer.all_classes.each do |current|
15
+ require current
16
+ end
@@ -0,0 +1,102 @@
1
+ module Fastlane
2
+ module Actions
3
+ module SharedValues
4
+ SIZE_REPORT = :SIZE_REPORT
5
+ end
6
+
7
+ class StoreSizeXcarchiveAction < Action
8
+ EXTRA_FILE_SIZE = 2_000_000
9
+
10
+ def self.run(params)
11
+ require 'plist'
12
+
13
+ unless Fastlane::Helper.test?
14
+ UI.user_error!("xcodebuild not installed") if `which xcodebuild`.length == 0
15
+ end
16
+
17
+ archive_path = params[:archive_path] || Actions.lane_context[SharedValues::XCODEBUILD_ARCHIVE]
18
+ app_path = Dir.glob(File.join(archive_path, "Products", "Applications", "*.app")).first
19
+ UI.user_error!("No applications found in archive") if app_path.nil?
20
+
21
+ binary_name = File.basename(app_path, ".app")
22
+ binary_path = File.join(app_path, binary_name)
23
+ extra_file_path = File.join(app_path, "extradata_simulated")
24
+ result = {}
25
+
26
+ Dir.mktmpdir do |tmp_path|
27
+ binary_backup_path = File.join(tmp_path, binary_name)
28
+ export_path = File.join(tmp_path, "Export")
29
+ begin
30
+ FileUtils.mv(binary_path, binary_backup_path)
31
+ FileUtils.cp(binary_backup_path, binary_path)
32
+
33
+ macho_info = Helper::MachoInfo.new(binary_path)
34
+
35
+ Helper::StoreSizerHelper.write_random_segments(binary_path, macho_info.encryption_segments)
36
+ Helper::StoreSizerHelper.write_random_file(extra_file_path, EXTRA_FILE_SIZE)
37
+
38
+ export_options = {}
39
+ export_options[:method] = 'ad-hoc'
40
+ export_options[:thinning] = '<thin-for-all-variants>'
41
+ export_options_plist_path = File.join(tmp_path, "ExportOptions.plist")
42
+ File.write(export_options_plist_path, Plist::Emit.dump(export_options, false))
43
+
44
+ UI.message("Exporting all variants of #{archive_path} for estimation...")
45
+ Helper::StoreSizerHelper.xcode_export_package(archive_path, export_options_plist_path, export_path)
46
+
47
+ UI.verbose(File.read(File.join(export_path, "App Thinning Size Report.txt")))
48
+
49
+ result = Plist.parse_xml(File.join(export_path, "app-thinning.plist"))
50
+ result.merge!(macho_info.sizes_info)
51
+ ensure
52
+ FileUtils.rm_f(binary_path)
53
+ FileUtils.mv(binary_backup_path, binary_path)
54
+ FileUtils.rm_f(extra_file_path)
55
+ end
56
+ end
57
+
58
+ Actions.lane_context[SharedValues::SIZE_REPORT] = result
59
+ result
60
+ end
61
+
62
+ def self.description
63
+ "Estimates download and install sizes for your app"
64
+ end
65
+
66
+ def self.authors
67
+ ["Marcelo Oliveira"]
68
+ end
69
+
70
+ def self.output
71
+ [
72
+ ['SIZE_REPORT', 'The generated size report hash']
73
+ ]
74
+ end
75
+
76
+ def self.return_value
77
+ "Hash containing App Thinning report"
78
+ end
79
+
80
+ def self.details
81
+ "Compute estimated size of the .ipa after encryption and App Thinning for all variants"
82
+ end
83
+
84
+ def self.available_options
85
+ [
86
+ FastlaneCore::ConfigItem.new(key: :archive_path,
87
+ description: 'Path to your xcarchive file. Optional if you use the `xcodebuild` action',
88
+ default_value: Actions.lane_context[SharedValues::XCODEBUILD_ARCHIVE],
89
+ optional: true,
90
+ env_name: 'STORE_SIZE_ARCHIVE_PATH',
91
+ verify_block: proc do |value|
92
+ UI.user_error!("Couldn't find xcarchive file at path '#{value}'") if !Helper.test? && !File.exist?(value)
93
+ end)
94
+ ]
95
+ end
96
+
97
+ def self.is_supported?(platform)
98
+ [:ios].include?(platform)
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,90 @@
1
+ module Fastlane
2
+ module Actions
3
+ class StoreSizeXcarchiveCheckAction < Action
4
+ # Apple sizes reference http://goo.gl/6A3nQK
5
+ MAX_TEXT_6_LESS = 80_000_000
6
+ MAX_SEGMENT_7_TO_8 = 60_000_000
7
+ MAX_TEXT_9_PLUS = 500_000_000
8
+ DEFAULT_MAX_WIFI_SIZE = 100_000_000
9
+
10
+ def self.run(params)
11
+ report = params[:report]
12
+
13
+ errors = 0
14
+ error = proc do |message|
15
+ errors += 1
16
+ UI.error(message)
17
+ end
18
+
19
+ unless report["min_os_version"].nil?
20
+ major_version = report["min_os_version"][0]
21
+ text_size = report["text_segments_size"]
22
+ max_slice_size = report["text_max_slice_size"]
23
+ error.call("__TEXT segments size #{text_size} greater than #{MAX_TEXT_6_LESS}") if major_version <= 6 && text_size > MAX_TEXT_6_LESS
24
+ 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
25
+ error.call("__TEXT segments size #{text_size} greater than #{MAX_TEXT_9_PLUS}") if major_version >= 9 && text_size > MAX_TEXT_9_PLUS
26
+ end
27
+
28
+ max_wifi_size = params[:max_wifi_size] || DEFAULT_MAX_WIFI_SIZE
29
+
30
+ if max_wifi_size > 0 && !report["variants"].nil?
31
+ report["variants"].each do |name, variant|
32
+ next if variant["variantIds"].nil? && params[:ignore_universal]
33
+
34
+ size = variant["sizeCompressedApp"]
35
+ error.call("Variant #{name} size #{size} greater than #{max_wifi_size}") if size > max_wifi_size
36
+ end
37
+ end
38
+
39
+ UI.test_failure!("Size check failed, #{errors} sizes exceeded the limits") if errors > 0
40
+
41
+ UI.success("App size check suceeded")
42
+ end
43
+
44
+ def self.description
45
+ "Checks if the size report fits the requirements"
46
+ end
47
+
48
+ def self.authors
49
+ ["Marcelo Oliveira"]
50
+ end
51
+
52
+ def self.output
53
+ end
54
+
55
+ def self.return_value
56
+ end
57
+
58
+ def self.details
59
+ "Checks estimated size for all non-universal variants and maximum executable sizes"
60
+ end
61
+
62
+ def self.available_options
63
+ [
64
+ FastlaneCore::ConfigItem.new(key: :report,
65
+ description: 'Generated report. Optional if you use the `store_size_xcarchive` action',
66
+ default_value: Actions.lane_context[SharedValues::SIZE_REPORT],
67
+ type: Hash,
68
+ optional: true,
69
+ verify_block: proc do |value|
70
+ UI.user_error!("Invalid report!'") if !Helper.test? && value["variants"].nil?
71
+ end),
72
+ FastlaneCore::ConfigItem.new(key: :ignore_universal,
73
+ description: 'True to ignore universal variant',
74
+ default_value: true,
75
+ is_string: false,
76
+ optional: true),
77
+ FastlaneCore::ConfigItem.new(key: :max_wifi_size,
78
+ description: 'Max Wi-Fi download size, pass 0 to ignore',
79
+ default_value: DEFAULT_MAX_WIFI_SIZE,
80
+ type: Integer,
81
+ optional: true)
82
+ ]
83
+ end
84
+
85
+ def self.is_supported?(platform)
86
+ [:ios].include?(platform)
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,52 @@
1
+ require 'macho'
2
+
3
+ module Fastlane
4
+ module Helper
5
+ class MachoInfo
6
+ attr_accessor :min_os_versions
7
+ attr_accessor :encryption_segments
8
+ attr_accessor :text_segment_sizes
9
+
10
+ def initialize(binary_path)
11
+ self.min_os_versions = []
12
+ self.encryption_segments = []
13
+ self.text_segment_sizes = []
14
+
15
+ file = MachO.open(binary_path)
16
+ if file.kind_of?(MachO::FatFile)
17
+ file.fat_archs.each_index do |arch_index|
18
+ macho_add(file.machos[arch_index], file.fat_archs[arch_index].offset)
19
+ end
20
+ elsif file.kind_of?(MachO::MachOFile)
21
+ macho_add(file, 0)
22
+ end
23
+ end
24
+
25
+ def self.split_version(version)
26
+ binary = format("%032b", version)
27
+ return [
28
+ binary[0..15], binary[16..23], binary[24..31]
29
+ ].map { |s| s.to_i(2) }
30
+ end
31
+
32
+ def sizes_info
33
+ result = {}
34
+ result["min_os_version"] = self.min_os_versions.first
35
+ result["text_segments_size"] = self.text_segment_sizes.flatten.reduce(0, :+)
36
+ result["text_max_slice_size"] = self.text_segment_sizes.flatten.max
37
+ result
38
+ end
39
+
40
+ def macho_add(macho, file_offset)
41
+ encryption_info = (macho.magic32? ? macho[:LC_ENCRYPTION_INFO] : macho[:LC_ENCRYPTION_INFO_64]).first
42
+ self.encryption_segments.push([file_offset + encryption_info.cryptoff, encryption_info.cryptsize]) unless encryption_info.nil?
43
+
44
+ min_version_info = macho[:LC_VERSION_MIN_IPHONEOS].first
45
+ self.min_os_versions.push(MachoInfo.split_version(min_version_info.version)) unless min_version_info.nil?
46
+
47
+ text_segments = macho.segments.select { |seg| seg.segname == "__TEXT" }
48
+ self.text_segment_sizes.push(text_segments.map(&:filesize)) unless text_segments.nil?
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,27 @@
1
+ module Fastlane
2
+ module Helper
3
+ class StoreSizerHelper
4
+ def self.write_random_segments(file_path, segments)
5
+ File.open(file_path, "rb+") do |file|
6
+ segments.each do |segment|
7
+ file.pos = segment[0]
8
+ file.puts(SecureRandom.random_bytes(segment[1]))
9
+ end
10
+ end
11
+ end
12
+
13
+ def self.write_random_file(path, size)
14
+ IO.binwrite(path, SecureRandom.random_bytes(size))
15
+ end
16
+
17
+ def self.xcode_export_package(archive_path, export_options_plist_path, export_path)
18
+ command = "xcodebuild"
19
+ command << " -exportArchive"
20
+ command << " -exportOptionsPlist #{export_options_plist_path}"
21
+ command << " -archivePath #{archive_path}"
22
+ command << " -exportPath #{export_path}"
23
+ FastlaneCore::CommandExecutor.execute(command: command, print_command: false, print_all: false)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module StoreSizer
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-store_sizer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marcelo Oliveira
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: fastlane
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 2.40.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 2.40.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: ruby-macho
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: plist
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description:
126
+ email: capyvara@gmail.com
127
+ executables: []
128
+ extensions: []
129
+ extra_rdoc_files: []
130
+ files:
131
+ - LICENSE
132
+ - README.md
133
+ - lib/fastlane/plugin/store_sizer.rb
134
+ - lib/fastlane/plugin/store_sizer/actions/store_size_xcarchive_action.rb
135
+ - lib/fastlane/plugin/store_sizer/actions/store_size_xcarchive_check_action.rb
136
+ - lib/fastlane/plugin/store_sizer/helper/macho_info.rb
137
+ - lib/fastlane/plugin/store_sizer/helper/store_sizer_helper.rb
138
+ - lib/fastlane/plugin/store_sizer/version.rb
139
+ homepage: https://github.com/capyvara/fastlane-plugin-store_sizer
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.6.11
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Estimates download and install sizes for your app
163
+ test_files: []
164
+ has_rdoc: