Class: Fastlane::Actions::ExtractVersionAction

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

Class Method Summary collapse

Class Method Details

.authorObject



89
90
91
# File 'lib/fastlane/plugin/polidea/actions/extract_version.rb', line 89

def self.author
  "Piotrek Dubiel"
end

.available_optionsObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/fastlane/plugin/polidea/actions/extract_version.rb', line 67

def self.available_options
  [
    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])
  ]
end

.categoryObject



97
98
99
# File 'lib/fastlane/plugin/polidea/actions/extract_version.rb', line 97

def self.category
  :deprecated
end

.descriptionObject



63
64
65
# File 'lib/fastlane/plugin/polidea/actions/extract_version.rb', line 63

def self.description
  "Extracts application version and build number from .ipa/.apk, use `extract_app_info` instead"
end

.extract_version(platform, config) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/fastlane/plugin/polidea/actions/extract_version.rb', line 30

def self.extract_version(platform, config)
  case platform
  when :ios
    extract_version_from_ipa(config[:ipa]) if validate_ios(config)
  when :android
    extract_version_from_apk(config[:apk]) if validate_android(config)
  end
end

.extract_version_from_apk(apk_file) ⇒ Object



58
59
60
61
# File 'lib/fastlane/plugin/polidea/actions/extract_version.rb', line 58

def self.extract_version_from_apk(apk_file)
  apk = Android::Apk.new(apk_file)
  return apk.manifest.version_name, apk.manifest.version_code
end

.extract_version_from_ipa(ipa_file) ⇒ Object



46
47
48
49
# File 'lib/fastlane/plugin/polidea/actions/extract_version.rb', line 46

def self.extract_version_from_ipa(ipa_file)
  info = FastlaneCore::IpaFileAnalyser.fetch_info_plist_file(ipa_file)
  return info['CFBundleShortVersionString'], info['CFBundleVersion']
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/fastlane/plugin/polidea/actions/extract_version.rb', line 93

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

.outputObject



82
83
84
85
86
87
# File 'lib/fastlane/plugin/polidea/actions/extract_version.rb', line 82

def self.output
  [
    ['APP_VERSION', 'App version extracted from .ipa/.apk'],
    ['BUILD_NUMBER', 'Build number extracted from .ipa/.apk']
  ]
end

.run(config) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fastlane/plugin/polidea/actions/extract_version.rb', line 13

def self.run(config)
  platform = Actions.lane_context[Actions::SharedValues::PLATFORM_NAME].to_sym

  # Gets version from ipa/apk
  app_version, build_number = extract_version(platform, config)

  Actions.lane_context[SharedValues::APP_VERSION] = app_version
  ENV[SharedValues::APP_VERSION.to_s] = app_version

  Actions.lane_context[SharedValues::BUILD_NUMBER] = build_number
  ENV[SharedValues::BUILD_NUMBER.to_s] = build_number.to_s

  UI.success("Successfully extracted app version: '#{Actions.lane_context[SharedValues::APP_VERSION]}', build number: #{Actions.lane_context[SharedValues::BUILD_NUMBER]}")

  return app_version, build_number
end

.validate_android(config) ⇒ Object

android specific



53
54
55
56
# File 'lib/fastlane/plugin/polidea/actions/extract_version.rb', line 53

def self.validate_android(config)
  UI.user_error!("No APK file path given, pass using `apk: 'apk path'`") unless config[:apk].to_s.length > 0
  true
end

.validate_ios(config) ⇒ Object

ios specific



41
42
43
44
# File 'lib/fastlane/plugin/polidea/actions/extract_version.rb', line 41

def self.validate_ios(config)
  UI.user_error!("No IPA file path given, pass using `ipa: 'ipa path'`") unless config[:ipa].to_s.length > 0
  true
end