Class: Fastlane::Actions::IncrementBuildNumberInPlistAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



101
102
103
# File 'lib/fastlane/plugin/versioning/actions/increment_build_number_in_plist.rb', line 101

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

.available_optionsObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/fastlane/plugin/versioning/actions/increment_build_number_in_plist.rb', line 57

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :build_number,
                                 env_name: "FL_BUILD_NUMBER_BUILD_NUMBER",
                                 description: "Change to a specific build number",
                                 optional: true),
    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",
                                 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 Info.plist build settings for each configuration"),
    FastlaneCore::ConfigItem.new(key: :plist_build_setting_support,
                                 description: "support automatic resolution of build setting from xcodeproj if not a literal value in the plist",
                                 is_string: false,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :skip_package_dependencies_resolution,
                                 description: "Skips resolution of Swift Package Manager dependencies",
                                 type: Boolean,
                                 default_value: false)
  ]
end

.descriptionObject



46
47
48
# File 'lib/fastlane/plugin/versioning/actions/increment_build_number_in_plist.rb', line 46

def self.description
  "Increment the build number of your project"
end

.detailsObject



50
51
52
53
54
55
# File 'lib/fastlane/plugin/versioning/actions/increment_build_number_in_plist.rb', line 50

def self.details
  [
    "This action will increment the build number directly in Info.plist",
    "unless plist_build_setting_support: true is passed in as parameters"
  ].join("\n")
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/fastlane/plugin/versioning/actions/increment_build_number_in_plist.rb', line 105

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

.outputObject



95
96
97
98
99
# File 'lib/fastlane/plugin/versioning/actions/increment_build_number_in_plist.rb', line 95

def self.output
  [
    ['BUILD_NUMBER', 'The new build number']
  ]
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
37
38
39
40
41
42
43
44
# File 'lib/fastlane/plugin/versioning/actions/increment_build_number_in_plist.rb', line 4

def self.run(params)
  if params[:build_number]
    next_build_number = params[:build_number]
  else
    current_build_number = GetBuildNumberFromPlistAction.run(params)
    build_array = current_build_number.split(".").map(&:to_i)
    build_array[-1] = build_array[-1] + 1
    next_build_number = build_array.join(".")
  end

  if Helper.test?
    plist = "/tmp/fastlane/tests/fastlane/plist/Info.plist"
  else
    plist = GetInfoPlistPathAction.run(params)
  end

  build_number = GetInfoPlistValueAction.run(path: plist, key: 'CFBundleVersion')
  if build_number =~ /\$\(([\w\-]+)\)/
    UI.important "detected that build number is a build setting."
    if params[:plist_build_setting_support]
      UI.important "will continue and update the xcodeproj $(CURRENT_PROJECT_VERSION) instead."
      IncrementBuildNumberInXcodeprojAction.run(params)
    else
      UI.important "will continue and update the info plist key. this will replace the existing value."
      SetInfoPlistValueAction.run(path: plist, key: 'CFBundleVersion', value: next_build_number)
    end
  else
    if params[:plist_build_setting_support]
      UI.important "will continue and update the xcodeproj $(CURRENT_PROJECT_VERSION) instead."
      IncrementBuildNumberInXcodeprojAction.run(params)
      UI.important "will also update info plist key to be a build setting"
      SetInfoPlistValueAction.run(path: plist, key: 'CFBundleVersion', value: "$(CURRENT_PROJECT_VERSION)")
    else
      UI.important "will continue and update the info plist key. this will replace the existing value."
      SetInfoPlistValueAction.run(path: plist, key: 'CFBundleVersion', value: next_build_number)
    end 
  end

  Actions.lane_context[SharedValues::BUILD_NUMBER] = next_build_number
  next_build_number
end