Class: Fastlane::Actions::GetVersionCodeAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



42
43
44
# File 'lib/fastlane/plugin/get_version_code/actions/get_version_code_action.rb', line 42

def self.authors
  ["Jérémy TOUDIC"]
end

.available_optionsObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/fastlane/plugin/get_version_code/actions/get_version_code_action.rb', line 46

def self.available_options
  [
    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")
  ]
end

.descriptionObject



38
39
40
# File 'lib/fastlane/plugin/get_version_code/actions/get_version_code_action.rb', line 38

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

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/fastlane/plugin/get_version_code/actions/get_version_code_action.rb', line 63

def self.is_supported?(platform)
  [:android].include?(platform)
end

.outputObject



57
58
59
60
61
# File 'lib/fastlane/plugin/get_version_code/actions/get_version_code_action.rb', line 57

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
34
35
36
# File 'lib/fastlane/plugin/get_version_code/actions/get_version_code_action.rb', line 4

def self.run(params)
  app_folder_name ||= params[:app_folder_name]
  UI.message("The get_version_code plugin is looking inside your project folder (#{app_folder_name})!")

  version_code = "0"

  Dir.glob("**/#{app_folder_name}/build.gradle") do |path|
      begin
          file = File.new(path, "r")
          while (line = file.gets)
              if line.include? "versionCode"
                 versionComponents = line.strip.split(' ')
                 version_code = versionComponents[1].tr("\"","")
                 break
              end
          end
          file.close
      rescue => err
          UI.error("An exception occured while reading gradle file: #{err}")
          err
      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