Class: Fastlane::Actions::AndroidGetVersionCodeAction

Inherits:
AndroidBaseAction show all
Defined in:
lib/fastlane/plugin/android_version_manager/actions/android_get_version_code_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



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fastlane/plugin/android_version_manager/actions/android_get_version_code_action.rb', line 38

def self.available_options
  [
    app_project_dir_action,
    FastlaneCore::ConfigItem.new(key: :key,
                                 env_name: "FL_ANDROID_GET_VERSION_CODE_KEY",
                                 description: "The property key",
                                 optional: true,
                                 type: String,
                                 default_value: "versionCode"),
  ]
end

.categoryObject



56
57
58
59
# File 'lib/fastlane/plugin/android_version_manager/actions/android_get_version_code_action.rb', line 56

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

.descriptionObject



30
31
32
# File 'lib/fastlane/plugin/android_version_manager/actions/android_get_version_code_action.rb', line 30

def self.description
  "Returns the version code of the android project"
end

.detailsObject



34
35
36
# File 'lib/fastlane/plugin/android_version_manager/actions/android_get_version_code_action.rb', line 34

def self.details
  "Based on the provided params, returns the value of the version code of the build.gradle file as a number"
end

.outputObject



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

def self.output
  [
    ["ANDROID_VERSION_CODE", "The version code specified on the build.gradle file of the project"],
  ]
end

.return_typeObject



75
76
77
78
# File 'lib/fastlane/plugin/android_version_manager/actions/android_get_version_code_action.rb', line 75

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 = get_version_number(xcodeproj: "Project.xcodeproj")',
  'version = get_version_number(
    xcodeproj: "Project.xcodeproj",
    target: "App"
  )'
]

end



71
72
73
# File 'lib/fastlane/plugin/android_version_manager/actions/android_get_version_code_action.rb', line 71

def self.return_value
  "The Android app version code"
end

.run(params) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fastlane/plugin/android_version_manager/actions/android_get_version_code_action.rb', line 12

def self.run(params)
  # fastlane will take care of reading in the parameter and fetching the environment variable:
  UI.message("Parameter app_project_dir: #{params[:app_project_dir]}")
  UI.message("Parameter key: #{params[:key]}")

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

  Actions.lane_context[Fastlane::Actions::SharedValues::ANDROID_VERSION_CODE] = version_code

  return version_code
end