Class: Fastlane::Actions::GetVersionNumberFromXcodeprojAction

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

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



102
103
104
# File 'lib/fastlane/plugin/versioning/actions/get_version_number_from_xcodeproj.rb', line 102

def self.authors
  ["jdouglas-nz"]
end

.available_optionsObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/fastlane/plugin/versioning/actions/get_version_number_from_xcodeproj.rb', line 76

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :xcodeproj,
                                 env_name: "FL_VERSION_NUMBER_PROJECT",
                                 description: "Optional, you must specify the path to your main Xcode project if it is not in the project root directory or if you have multiple *.xcodeproj's in the root directory",
                                 optional: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("Please pass the path to the project, not the workspace") if value.end_with? ".xcworkspace"
                                   UI.user_error!("Could not find Xcode project at path '#{File.expand_path(value)}'") if !File.exist?(value) and !Helper.is_test?
                                 end),
    FastlaneCore::ConfigItem.new(key: :target,
                                 env_name: "FL_VERSION_NUMBER_TARGET",
                                 optional: true,
                                 conflicting_options: [:scheme],
                                 description: "Specify a specific target if you have multiple per project, optional"),
    FastlaneCore::ConfigItem.new(key: :scheme,
                                 env_name: "FL_VERSION_NUMBER_SCHEME",
                                 optional: true,
                                 conflicting_options: [:target],
                                 description: "Specify a specific scheme if you have multiple per project, optional"),
    FastlaneCore::ConfigItem.new(key: :build_configuration_name,
                                 optional: true,
                                 description: "Specify a specific build configuration if you have different build settings for each configuration")
  ]
end

.descriptionObject



68
69
70
# File 'lib/fastlane/plugin/versioning/actions/get_version_number_from_xcodeproj.rb', line 68

def self.description
  "Get the version number of your project"
end

.detailsObject



72
73
74
# File 'lib/fastlane/plugin/versioning/actions/get_version_number_from_xcodeproj.rb', line 72

def self.details
  'Gets the $(MARKETING_VERSION) build setting using the specified parameters, or the first if not enough parameters are passed.'
end

.get_version_number_using_scheme(params) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/fastlane/plugin/versioning/actions/get_version_number_from_xcodeproj.rb', line 54

def self.get_version_number_using_scheme(params)
  config = { project: params[:xcodeproj], scheme: params[:scheme], configuration: params[:build_configuration_name] }
  project = FastlaneCore::Project.new(config)
  project.select_scheme

  build_number = project.build_settings(key: 'MARKETING_VERSION')
  UI.user_error! "Cannot resolve $(MARKETING_VERSION) in for the scheme #{config.scheme} with the name #{params.configuration}" if build_number.nil? || build_number.empty?
  build_number
end

.get_version_number_using_target(params) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fastlane/plugin/versioning/actions/get_version_number_from_xcodeproj.rb', line 26

def self.get_version_number_using_target(params)
  project = Xcodeproj::Project.open(params[:xcodeproj])
  if params[:target]
    target = project.targets.detect { |t| t.name == params[:target] }
  else
    # firstly we are trying to find modern application target
    target = project.targets.detect do |t|
      t.kind_of?(Xcodeproj::Project::Object::PBXNativeTarget) &&
        t.product_type == 'com.apple.product-type.application'
    end
    target = project.targets[0] if target.nil?
  end

  version_number = target.resolved_build_setting('MARKETING_VERSION', true)
  UI.user_error! 'Cannot resolve version number build setting.' if version_number.nil? || version_number.empty?

  if !(build_configuration_name = params[:build_configuration_name]).nil?
    version_number = version_number[build_configuration_name]
    UI.user_error! "Cannot resolve $(MARKETING_VERSION) build setting for #{build_configuration_name}." if version_number.nil?
  else
    version_number = version_number.values.compact.uniq
    UI.user_error! 'Cannot accurately resolve $(MARKETING_VERSION) build setting, try specifying :build_configuration_name.' if version_number.count > 1
    version_number = version_number.first
  end

  version_number
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/fastlane/plugin/versioning/actions/get_version_number_from_xcodeproj.rb', line 106

def self.is_supported?(platform)
  %i[ios mac].include? platform
end

.run(params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fastlane/plugin/versioning/actions/get_version_number_from_xcodeproj.rb', line 7

def self.run(params)
  unless params[:xcodeproj]
    if Helper.test?
      params[:xcodeproj] = "/tmp/fastlane/tests/fastlane/xcodeproj/versioning_fixture_project.xcodeproj"
    else
      params[:xcodeproj] = Dir["*.xcodeproj"][0] unless params[:xcodeproj]
    end
  end

  if params[:target]
    version_number = get_version_number_using_target(params)
  else
    version_number = get_version_number_using_scheme(params)
  end

  Actions.lane_context[SharedValues::VERSION_NUMBER] = version_number
  version_number
end