Class: Fastlane::Actions::AndroidIncrementVersionNameAction

Inherits:
AndroidBaseAction
  • Object
show all
Defined in:
lib/fastlane/plugin/android_version_manager/actions/android_increment_version_name_action.rb

Documentation collapse

Class Method Summary collapse

Methods inherited from AndroidBaseAction

app_project_dir_action, authors, find_build_gradle, is_supported?

Class Method Details

.available_optionsObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/fastlane/plugin/android_version_manager/actions/android_increment_version_name_action.rb', line 58

def self.available_options
  [
    app_project_dir_action,
    FastlaneCore::ConfigItem.new(key: :key,
                                 env_name: "FL_ANDROID_INCREMENT_VERSION_NAME_KEY",
                                 description: "The property key",
                                 optional: true,
                                 type: String,
                                 default_value: "versionName"),
    FastlaneCore::ConfigItem.new(key: :increment_type,
                                 env_name: "FL_ANDROID_INCREMENT_VERSION_NAME_INCREMENT_TYPE",
                                 description: "The type of increment to make, can be one of: patch, minor, major",
                                 optional: true,
                                 type: String,
                                 default_value: "patch",
                                 verify_block: proc do |value|
                                   UI.user_error!("Increment type of #{value} is not valid") unless ['patch', 'minor', 'major'].include?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :version_name,
                                 env_name: "FL_ANDROID_GET_VERSION_CODE_VERSION_NAME",
                                 description: "Change to a specific version name instead of just incrementing",
                                 optional: true,
                                 is_string: false),
  ]
end

.categoryObject



90
91
92
93
# File 'lib/fastlane/plugin/android_version_manager/actions/android_increment_version_name_action.rb', line 90

def self.category
  # https://github.com/fastlane/fastlane/blob/051e5012984d97257571a76627c1261946afb8f8/fastlane/lib/fastlane/action.rb#L6-L21
  :project
end

.descriptionObject



50
51
52
# File 'lib/fastlane/plugin/android_version_manager/actions/android_increment_version_name_action.rb', line 50

def self.description
  "Increments the version name of the android project"
end

.detailsObject



54
55
56
# File 'lib/fastlane/plugin/android_version_manager/actions/android_increment_version_name_action.rb', line 54

def self.details
  "Based on the provided params, increments the version name and returns their new value"
end

.outputObject



84
85
86
87
88
# File 'lib/fastlane/plugin/android_version_manager/actions/android_increment_version_name_action.rb', line 84

def self.output
  [
    ["ANDROID_VERSION_NAME", "The new version name"],
  ]
end

.return_typeObject



109
110
111
112
# File 'lib/fastlane/plugin/android_version_manager/actions/android_increment_version_name_action.rb', line 109

def self.return_type
  # https://github.com/fastlane/fastlane/blob/051e5012984d97257571a76627c1261946afb8f8/fastlane/lib/fastlane/action.rb#L23-L30
  :int
end

.return_valueObject

def self.example_code

[
  'version = android_increment_version_code(xcodeproj: "Project.xcodeproj")',
  'version = android_increment_version_code(
    xcodeproj: "Project.xcodeproj",
    target: "App"
  )'
]

end



105
106
107
# File 'lib/fastlane/plugin/android_version_manager/actions/android_increment_version_name_action.rb', line 105

def self.return_value
  "The Android app new version name"
end

.run(params) ⇒ Object



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
# File 'lib/fastlane/plugin/android_version_manager/actions/android_increment_version_name_action.rb', line 13

def self.run(params)
  UI.message("Param app_project_dir: #{params[:app_project_dir]}")
  UI.message("Param version_name: #{params[:version_name]}")
  UI.message("Param increment_type: #{params[:increment_type]}")
  UI.message("Param key: #{params[:key]}")

  file_path = find_build_gradle(params[:app_project_dir])
  increment_type = params[:increment_type].to_sym

  # We can expect version_code to be an existing and valid version code
  version_name = Helper::AndroidVersionManagerHelper.get_version_name_from_gradle_file(file_path, params[:key])

  param_version_name = params[:version_name]
  unless param_version_name.nil?
    begin
      param_version_name = Semantic::Version.new(param_version_name)
    rescue Exception # rubocop:disable RescueException
      raise $!, "Error parsing version name #{param_version_name}: #{$!}", $!.backtrace
    end
  end
  new_version_name = param_version_name || version_name.increment!(increment_type)

  if new_version_name <= version_name
    UI.important("New version name is not greater than the current one")
  end

  Helper::AndroidVersionManagerHelper.set_key_value_on_gradle_file(file_path, params[:key], new_version_name.to_s)

  Actions.lane_context[Fastlane::Actions::SharedValues::ANDROID_VERSION_NAME] = new_version_name

  return new_version_name
end