Class: Fastlane::Actions::AndroidIncrementVersionNameAction

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

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



124
125
126
# File 'lib/fastlane/plugin/android_version_manager/actions/android_increment_version_name_action.rb', line 124

def self.authors
  ["Jonathan Cardoso", "@_jonathancardos", "JCMais"]
end

.available_optionsObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/fastlane/plugin/android_version_manager/actions/android_increment_version_name_action.rb', line 59

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :app_project_dir,
                                 env_name: "FL_ANDROID_INCREMENT_VERSION_NAME_APP_PROJECT_DIR",
                                 description: "The path to the application source folder in the Android project (default: android/app)",
                                 optional: true,
                                 type: String,
                                 default_value: "android/app",
                                 verify_block: proc do |value|
                                   # Not using File.exist?("#{value}/build.gradle") because it does not handle globs
                                   UI.user_error!("Couldn't find build.gradle file at path '#{value}'") unless Dir["#{value}/build.gradle"].any?
                                 end),
    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



100
101
102
103
# File 'lib/fastlane/plugin/android_version_manager/actions/android_increment_version_name_action.rb', line 100

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

.descriptionObject



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

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

.detailsObject



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

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

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/fastlane/plugin/android_version_manager/actions/android_increment_version_name_action.rb', line 128

def self.is_supported?(platform)
  platform == :android
end

.outputObject



94
95
96
97
98
# File 'lib/fastlane/plugin/android_version_manager/actions/android_increment_version_name_action.rb', line 94

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

.return_typeObject



119
120
121
122
# File 'lib/fastlane/plugin/android_version_manager/actions/android_increment_version_name_action.rb', line 119

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



115
116
117
# File 'lib/fastlane/plugin/android_version_manager/actions/android_increment_version_name_action.rb', line 115

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

.run(params) ⇒ Object



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

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 = "#{params[:app_project_dir]}/build.gradle"
  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