Class: Fastlane::Actions::AndroidGetVersionCodeAction

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

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



88
89
90
# File 'lib/fastlane/plugin/android_version_manager/actions/android_get_version_code_action.rb', line 88

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

.available_optionsObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fastlane/plugin/android_version_manager/actions/android_get_version_code_action.rb', line 37

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :app_project_dir,
                                 env_name: "FL_ANDROID_GET_VERSION_CODE_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_GET_VERSION_CODE_KEY",
                                 description: "The property key",
                                 optional: true,
                                 type: String,
                                 default_value: "versionCode"),
  ]
end

.categoryObject



64
65
66
67
# File 'lib/fastlane/plugin/android_version_manager/actions/android_get_version_code_action.rb', line 64

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

.descriptionObject



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

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

.detailsObject



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

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

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/fastlane/plugin/android_version_manager/actions/android_get_version_code_action.rb', line 92

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

.outputObject



58
59
60
61
62
# File 'lib/fastlane/plugin/android_version_manager/actions/android_get_version_code_action.rb', line 58

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

.return_typeObject



83
84
85
86
# File 'lib/fastlane/plugin/android_version_manager/actions/android_get_version_code_action.rb', line 83

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



79
80
81
# File 'lib/fastlane/plugin/android_version_manager/actions/android_get_version_code_action.rb', line 79

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
# 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]}")

  # We can expect version_code to be an existing and valid version code
  version_code = Helper::AndroidVersionManagerHelper.get_version_code_from_gradle_file("#{params[:app_project_dir]}/build.gradle", params[:key])

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

  return version_code
end