Class: Fastlane::Actions::IncrementVersionNameAction

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

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



116
117
118
# File 'lib/fastlane/plugin/android_versioning_kts/actions/increment_version_name.rb', line 116

def self.authors
  ['Manabu OHTAKE']
end

.available_optionsObject



53
54
55
56
57
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/fastlane/plugin/android_versioning_kts/actions/increment_version_name.rb', line 53

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :app_project_dir,
      env_name: 'ANDROID_VERSIONING_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'
    ),
    FastlaneCore::ConfigItem.new(
      key: :flavor,
      env_name: 'ANDROID_VERSIONING_FLAVOR',
      description: 'The product flavor name (optional)',
      optional: true,
      type: String
    ),
    FastlaneCore::ConfigItem.new(
      key: :bump_type,
      env_name: 'ANDROID_VERSIONING_BUMP_TYPE',
      description: 'Change to a specific type (optional)',
      optional: true,
      type: String,
      default_value: 'patch',
      verify_block:
        proc do |value|
          unless %w[
            patch minor major
          ].include? value
            UI.user_error!(
              "Available values are 'patch', 'minor' and 'major'"
            )
          end
        end
    ),
    FastlaneCore::ConfigItem.new(
      key: :version_name,
      env_name: 'ANDROID_VERSIONING_VERSION_NAME',
      description: 'Change to a specific version (optional)',
      optional: true,
      type: String
    )
  ]
end

.descriptionObject



99
100
101
# File 'lib/fastlane/plugin/android_versioning_kts/actions/increment_version_name.rb', line 99

def self.description
  'Increment the version name of your project'
end

.detailsObject



103
104
105
106
107
108
# File 'lib/fastlane/plugin/android_versioning_kts/actions/increment_version_name.rb', line 103

def self.details
  [
    'This action will increment the version name directly
      in build.gradle.kts'
  ].join("\n")
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/fastlane/plugin/android_versioning_kts/actions/increment_version_name.rb', line 120

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

.outputObject



110
111
112
113
114
# File 'lib/fastlane/plugin/android_versioning_kts/actions/increment_version_name.rb', line 110

def self.output
  [
    ['VERSION_NAME', 'The 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
45
46
47
48
# File 'lib/fastlane/plugin/android_versioning_kts/actions/increment_version_name.rb', line 13

def self.run(params)
  if params[:version_name].nil? || params[:version_name].empty?
    current_version = GetVersionNameAction.run(params)
    unless current_version =~ /\d+.\d+.\d+/
      UI.user_error!(
        "Your current version (#{current_version})
         does not respect the format A.B.C"
      )
    end
    version = current_version.split('.').map(&:to_i)
    case params[:bump_type]
    when 'patch'
      version[2] = version[2] + 1
      new_version = version.join('.')
    when 'minor'
      version[1] = version[1] + 1
      version[2] = version[2] = 0
      new_version = version.join('.')
    when 'major'
      version[0] = version[0] + 1
      version[1] = 0
      version[2] = 0
      new_version = version.join('.')
    end
  else
    new_version = params[:version_name]
  end
  SetValueInBuildAction.run(
    app_project_dir: params[:app_project_dir],
    flavor: params[:flavor],
    key: 'versionName',
    value: new_version
  )
  Actions.lane_context[SharedValues::VERSION_NAME] = new_version
  new_version
end