Class: Fastlane::Actions::GetVersionNameAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



65
66
67
# File 'lib/fastlane/plugin/get_version_name/actions/get_version_name_action.rb', line 65

def self.authors
  ["Jems"]
end

.available_optionsObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/fastlane/plugin/get_version_name/actions/get_version_name_action.rb', line 69

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :app_folder_name,
                            env_name: "GETVERSIONNAME_APP_VERSION_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: "GETVERSIONNAME_GRADLE_FILE_PATH",
                         description: "The relative path to the gradle file containing the version name parameter (default:app/build.gradle)",
                            optional: true,
                                type: String,
                       default_value: nil),
     FastlaneCore::ConfigItem.new(key: :ext_constant_name,
                             env_name: "GETVERSIONNAME_EXT_CONSTANT_NAME",
                          description: "If the version name is set in an ext constant, specify the constant name (optional)",
                             optional: true,
                                 type: String,
                        default_value: "versionName")
  ]
end

.descriptionObject



61
62
63
# File 'lib/fastlane/plugin/get_version_name/actions/get_version_name_action.rb', line 61

def self.description
  "Get the version name of an Android project. This action will return the version name of your project according to the one set in your build.gradle file"
end

.getVersionName(path, constant_name) ⇒ Object



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

def self.getVersionName(path, constant_name)
    version_name = "0"
    if !File.file?(path)
        UI.message(" -> No file exist at path: (#{path})!")
        return version_name
    end
    begin
        file = File.new(path, "r")
        while (line = file.gets)
            if line.include? constant_name
               versionComponents = line.strip.split(' ')
               version_name = 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_name
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/fastlane/plugin/get_version_name/actions/get_version_name_action.rb', line 98

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

.outputObject



92
93
94
95
96
# File 'lib/fastlane/plugin/get_version_name/actions/get_version_name_action.rb', line 92

def self.output
  [
    ['VERSION_NAME', 'The version name']
  ]
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_name/actions/get_version_name_action.rb', line 4

def self.run(params)
  version_name = "0"
  constant_name ||= params[:ext_constant_name]
  gradle_file_path ||= params[:gradle_file_path]
  if gradle_file_path != nil
      UI.message("The increment_version_code plugin will use gradle file at (#{gradle_file_path})!")
      version_name = getVersionName(gradle_file_path, constant_name)
  else
      app_folder_name ||= params[:app_folder_name]
      UI.message("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.message(" -> Found a build.gradle file at path: (#{path})!")
          version_name = getVersionName(path, constant_name)
      end
  end

  if version_name == "0"
      UI.user_error!("Impossible to find the version name with the specified properties 😭")
  else
      # Store the version name in the shared hash
      Actions.lane_context["VERSION_NAME"]=version_name
      UI.success("👍 Version name found: #{version_name}")
  end

  return version_name

end