Class: Fastlane::Actions::ExtractAppInfoAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::ExtractAppInfoAction
- Defined in:
- lib/fastlane/plugin/polidea/actions/extract_app_info.rb
Class Method Summary collapse
- .author ⇒ Object
- .available_options ⇒ Object
- .category ⇒ Object
- .description ⇒ Object
- .extract_app_name(platform, config) ⇒ Object
- .extract_binary_size(platform, config) ⇒ Object
- .extract_icon(platform, config) ⇒ Object
- .extract_icon_from_apk(apk_file, icon_output_path) ⇒ Object
- .extract_icon_from_ipa(ipa_file, icon_output_path) ⇒ Object
- .extract_version(platform, config) ⇒ Object
- .ipa_icon_files(info) ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .largest_android_icon(apk) ⇒ Object
- .largest_ios_icon(icons) ⇒ Object
- .output ⇒ Object
- .publish_shared_values(config) ⇒ Object
- .run(config) ⇒ Object
- .validate(platform, config) ⇒ Object
Class Method Details
.author ⇒ Object
203 204 205 |
# File 'lib/fastlane/plugin/polidea/actions/extract_app_info.rb', line 203 def self. "Piotrek Dubiel" end |
.available_options ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/fastlane/plugin/polidea/actions/extract_app_info.rb', line 172 def self. [ FastlaneCore::ConfigItem.new(key: :ipa, env_name: "", description: ".ipa file to extract icon", optional: true, default_value: Actions.lane_context[SharedValues::IPA_OUTPUT_PATH]), FastlaneCore::ConfigItem.new(key: :apk, env_name: "", description: ".apk file to extract icon", optional: true, default_value: Actions.lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH]), FastlaneCore::ConfigItem.new(key: :icon_output_path, env_name: "", description: "icon output path", optional: true, default_value: "./app_icon.png") ] end |
.category ⇒ Object
211 212 213 |
# File 'lib/fastlane/plugin/polidea/actions/extract_app_info.rb', line 211 def self.category :project end |
.description ⇒ Object
168 169 170 |
# File 'lib/fastlane/plugin/polidea/actions/extract_app_info.rb', line 168 def self.description "Extract information from .ipa/.apk" end |
.extract_app_name(platform, config) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/fastlane/plugin/polidea/actions/extract_app_info.rb', line 64 def self.extract_app_name(platform, config) case platform when :ios info = FastlaneCore::IpaFileAnalyser.fetch_info_plist_file(config[:ipa]) return info['CFBundleDisplayName'] || info['CFBundleName'], info['CFBundleIdentifier'] when :android apk = Android::Apk.new(config[:apk]) return apk.manifest.label, apk.manifest.package_name end end |
.extract_binary_size(platform, config) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/fastlane/plugin/polidea/actions/extract_app_info.rb', line 84 def self.extract_binary_size(platform, config) case platform when :ios File.open(config[:ipa]).size when :android File.open(config[:apk]).size end end |
.extract_icon(platform, config) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/fastlane/plugin/polidea/actions/extract_app_info.rb', line 75 def self.extract_icon(platform, config) case platform when :ios extract_icon_from_ipa(config[:ipa], config[:icon_output_path]) when :android extract_icon_from_apk(config[:apk], config[:icon_output_path]) end end |
.extract_icon_from_apk(apk_file, icon_output_path) ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/fastlane/plugin/polidea/actions/extract_app_info.rb', line 104 def self.extract_icon_from_apk(apk_file, icon_output_path) apk = Android::Apk.new(apk_file) icon = largest_android_icon(apk) return unless icon icon_file = File.open(icon_output_path, 'wb') icon_file.write icon[:data] icon_file end |
.extract_icon_from_ipa(ipa_file, icon_output_path) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/fastlane/plugin/polidea/actions/extract_app_info.rb', line 132 def self.extract_icon_from_ipa(ipa_file, icon_output_path) info = FastlaneCore::IpaFileAnalyser.fetch_info_plist_file(ipa_file) icon_files = ipa_icon_files(info) return if icon_files.empty? icon_file_name = icon_files.sort.last Zip::File.open(ipa_file) do |zipfile| icon_file = self.largest_ios_icon(zipfile.glob("**/Payload/**/#{icon_file_name}*.png")) return nil unless icon_file tmp_path = "/tmp/app_icon.png" File.write(tmp_path, zipfile.read(icon_file)) Actions.sh("xcrun -sdk iphoneos pngcrush -revert-iphone-optimizations #{tmp_path} #{icon_output_path}") File.delete(tmp_path) end end |
.extract_version(platform, config) ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/fastlane/plugin/polidea/actions/extract_app_info.rb', line 93 def self.extract_version(platform, config) case platform when :ios info = FastlaneCore::IpaFileAnalyser.fetch_info_plist_file(config[:ipa]) return info['CFBundleShortVersionString'], info['CFBundleVersion'].to_i when :android apk = Android::Apk.new(config[:apk]) return apk.manifest.version_name, apk.manifest.version_code end end |
.ipa_icon_files(info) ⇒ Object
147 148 149 150 151 152 153 154 155 |
# File 'lib/fastlane/plugin/polidea/actions/extract_app_info.rb', line 147 def self.ipa_icon_files(info) # try iPhone icons = info.dig('CFBundleIcons', 'CFBundlePrimaryIcon', 'CFBundleIconFiles') return icons unless icons.nil? # try iPad icons = info.dig('CFBundleIcons~ipad', 'CFBundlePrimaryIcon', 'CFBundleIconFiles') return icons unless icons.nil? [] end |
.is_supported?(platform) ⇒ Boolean
207 208 209 |
# File 'lib/fastlane/plugin/polidea/actions/extract_app_info.rb', line 207 def self.is_supported?(platform) [:ios, :android].include? platform end |
.largest_android_icon(apk) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/fastlane/plugin/polidea/actions/extract_app_info.rb', line 113 def self.largest_android_icon(apk) icons = apk.icon selected_icon = icons.max_by do |name, _| case name when /x*hdpi/ name.count "x" when /mdpi/ -1 when %r{\/drawable\/} -2 else -3 end end { name: selected_icon[0], data: selected_icon[1] } if selected_icon rescue nil end |
.largest_ios_icon(icons) ⇒ Object
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/fastlane/plugin/polidea/actions/extract_app_info.rb', line 157 def self.largest_ios_icon(icons) icons.max_by do |file, _| case file.name when /@(\d+)x/ $1.to_i else 1 end end end |
.output ⇒ Object
192 193 194 195 196 197 198 199 200 201 |
# File 'lib/fastlane/plugin/polidea/actions/extract_app_info.rb', line 192 def self.output [ ['APP_NAME', 'App name extracted from .ipa/.apk'], ['APP_IDENTIFIER', 'Bundle id or package name extracted from .ipa/.apk'], ['ICON_OUTPUT_PATH', 'Path to app icon extracted from .ipa/.apk'], ['BINARY_SIZE', 'Size of .ipa/.apk in bytes'], ['APP_VERSION', 'App version extracted from .ipa/.apk'], ['BUILD_NUMBER', 'Build number extracted from .ipa/.apk'] ] end |
.publish_shared_values(config) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fastlane/plugin/polidea/actions/extract_app_info.rb', line 48 def self.publish_shared_values(config) config.each do |key, value| if value Actions.lane_context[key] = value ENV[key.to_s] = value.to_s else Actions.lane_context[key] = nil UI.important("Value for #{key} not found.") end end FastlaneCore::PrintTable.print_values(config: config, hide_keys: [], title: "Summary for extract_app_info") end |
.run(config) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fastlane/plugin/polidea/actions/extract_app_info.rb', line 17 def self.run(config) platform = Actions.lane_context[Actions::SharedValues::PLATFORM_NAME].to_sym icon_output_path = config[:icon_output_path] validate(platform, config) app_name, app_identifier = extract_app_name(platform, config) app_icon = extract_icon(platform, config) if icon_output_path binary_size = extract_binary_size(platform, config) app_version, build_number = extract_version(platform, config) publish_shared_values( SharedValues::APP_NAME => app_name, SharedValues::APP_IDENTIFIER => app_identifier, SharedValues::ICON_OUTPUT_PATH => app_icon.nil? ? nil : icon_output_path, SharedValues::BINARY_SIZE => binary_size, SharedValues::APP_VERSION => app_version, SharedValues::BUILD_NUMBER => build_number ) end |
.validate(platform, config) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/fastlane/plugin/polidea/actions/extract_app_info.rb', line 39 def self.validate(platform, config) case platform when :ios UI.user_error!("No IPA file path given, pass using `ipa: 'ipa path'`") unless config[:ipa].to_s.length > 0 when :android UI.user_error!("No APK file path given, pass using `apk: 'apk path'`") unless config[:apk].to_s.length > 0 end end |