Class: Fastlane::Actions::GetVersionCodeAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::GetVersionCodeAction
- Defined in:
- lib/fastlane/plugin/get_version_code/actions/get_version_code_action.rb
Class Method Summary collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .description ⇒ Object
- .getVersionCode(path, constant_name) ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .output ⇒ Object
- .run(params) ⇒ Object
Class Method Details
.authors ⇒ Object
62 63 64 |
# File 'lib/fastlane/plugin/get_version_code/actions/get_version_code_action.rb', line 62 def self. ["Jems"] end |
.available_options ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/fastlane/plugin/get_version_code/actions/get_version_code_action.rb', line 66 def self. [ FastlaneCore::ConfigItem.new(key: :app_folder_name, env_name: "GETVERSIONCODE_APP_FOLDER_NAME", description: "The name of the application source folder in the Android project (default: app)", optional: true, type: String, default_value:"app"), FastlaneCore::ConfigItem.new(key: :gradle_file_path, env_name: "GETVERSIONCODE_GRADLE_FILE_PATH", description: "The relative path to the gradle file containing the version code parameter (default:app/build.gradle)", optional: true, type: String, default_value: nil), FastlaneCore::ConfigItem.new(key: :ext_constant_name, env_name: "GETVERSIONCODE_EXT_CONSTANT_NAME", description: "If the version code is set in an ext constant, specify the constant name (optional)", optional: true, type: String, default_value: "versionCode") ] end |
.description ⇒ Object
58 59 60 |
# File 'lib/fastlane/plugin/get_version_code/actions/get_version_code_action.rb', line 58 def self.description "Get the version code of an Android project. This action will return the version code of your project according to the one set in your build.gradle file" end |
.getVersionCode(path, constant_name) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fastlane/plugin/get_version_code/actions/get_version_code_action.rb', line 35 def self.getVersionCode(path, constant_name) version_code = "0" if !File.file?(path) UI.(" -> No file exist at path: (#{path})!") return version_code end begin file = File.new(path, "r") while (line = file.gets) if line.include? constant_name versionComponents = line.strip.split(' ') version_code = versionComponents[versionComponents.length - 1].tr("\"","") break end end file.close rescue => err UI.error("An exception occured while readinf gradle file: #{err}") err end return version_code end |
.is_supported?(platform) ⇒ Boolean
95 96 97 |
# File 'lib/fastlane/plugin/get_version_code/actions/get_version_code_action.rb', line 95 def self.is_supported?(platform) [:android].include?(platform) end |
.output ⇒ Object
89 90 91 92 93 |
# File 'lib/fastlane/plugin/get_version_code/actions/get_version_code_action.rb', line 89 def self.output [ ['VERSION_CODE', 'The version code of the project'] ] end |
.run(params) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/fastlane/plugin/get_version_code/actions/get_version_code_action.rb', line 4 def self.run(params) version_code = "0" constant_name ||= params[:ext_constant_name] gradle_file_path ||= params[:gradle_file_path] if gradle_file_path != nil UI.("The get_version_code plugin will use gradle file at (#{gradle_file_path})!") version_code = getVersionCode(gradle_file_path, constant_name) else app_folder_name ||= params[:app_folder_name] UI.("The get_version_code plugin is looking inside your project folder (#{app_folder_name})!") #temp_file = Tempfile.new('fastlaneIncrementVersionCode') #foundVersionCode = "false" Dir.glob("**/#{app_folder_name}/build.gradle") do |path| UI.(" -> Found a build.gradle file at path: (#{path})!") version_code = getVersionCode(path, constant_name) end end if version_code == "0" UI.user_error!("Impossible to find the version code in the current project folder #{app_folder_name} 😭") else # Store the version name in the shared hash Actions.lane_context["VERSION_CODE"]=version_code UI.success("👍 Version name found: #{version_code}") end return version_code end |