Class: Fastlane::Actions::IncrementBuildNumberAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/increment_build_number.rb

Constant Summary

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, authors, deprecated_notes, details, lane_context, method_missing, other_action, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorObject



96
97
98
# File 'fastlane/lib/fastlane/actions/increment_build_number.rb', line 96

def self.author
  "KrauseFx"
end

.available_optionsObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'fastlane/lib/fastlane/actions/increment_build_number.rb', line 64

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :build_number,
                                 env_name: "FL_BUILD_NUMBER_BUILD_NUMBER",
                                 description: "Change to a specific version",
                                 optional: true,
                                 is_string: false),
    FastlaneCore::ConfigItem.new(key: :xcodeproj,
                                 env_name: "FL_BUILD_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") if !File.exist?(value) && !Helper.test?
                                 end)
  ]
end

.categoryObject



114
115
116
# File 'fastlane/lib/fastlane/actions/increment_build_number.rb', line 114

def self.category
  :project
end

.descriptionObject



60
61
62
# File 'fastlane/lib/fastlane/actions/increment_build_number.rb', line 60

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

.example_codeObject



100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'fastlane/lib/fastlane/actions/increment_build_number.rb', line 100

def self.example_code
  [
    'increment_build_number # automatically increment by one',
    'increment_build_number(
      build_number: "75" # set a specific number
    )',
    'increment_build_number(
      build_number: 75, # specify specific build number (optional, omitting it increments by one)
      xcodeproj: "./path/to/MyApp.xcodeproj" # (optional, you must specify the path to your main Xcode project if it is not in the project root directory)
    )',
    'build_number = increment_build_number'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



10
11
12
# File 'fastlane/lib/fastlane/actions/increment_build_number.rb', line 10

def self.is_supported?(platform)
  [:ios, :mac].include?(platform)
end

.outputObject



82
83
84
85
86
# File 'fastlane/lib/fastlane/actions/increment_build_number.rb', line 82

def self.output
  [
    ['BUILD_NUMBER', 'The new build number']
  ]
end

.return_typeObject



92
93
94
# File 'fastlane/lib/fastlane/actions/increment_build_number.rb', line 92

def self.return_type
  :string
end

.return_valueObject



88
89
90
# File 'fastlane/lib/fastlane/actions/increment_build_number.rb', line 88

def self.return_value
  "The new build number"
end

.run(params) ⇒ Object



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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'fastlane/lib/fastlane/actions/increment_build_number.rb', line 14

def self.run(params)
  folder = params[:xcodeproj] ? File.join(params[:xcodeproj], '..') : '.'

  command_prefix = [
    'cd',
    File.expand_path(folder).shellescape,
    '&&'
  ].join(' ')

  command_suffix = [
    '&&',
    'cd',
    '-'
  ].join(' ')

  # More information about how to set up your project and how it works:
  # https://developer.apple.com/library/ios/qa/qa1827/_index.html
  # Attention: This is NOT the version number - but the build number

  # We do not want to run agvtool under tests to avoid output about not having a project available
  unless Helper.test?
    agv_enabled = system([command_prefix, 'agvtool what-version', command_suffix].join(' '))
    raise "Apple Generic Versioning is not enabled." unless agv_enabled
  end

  command = [
    command_prefix,
    'agvtool',
    params[:build_number] ? "new-version -all #{params[:build_number].to_s.strip}" : 'next-version -all',
    command_suffix
  ].join(' ')

  if Helper.test?
    return Actions.lane_context[SharedValues::BUILD_NUMBER] = command
  else
    Actions.sh(command)

    # Store the new number in the shared hash
    build_number = `#{command_prefix} agvtool what-version`.split("\n").last.strip

    return Actions.lane_context[SharedValues::BUILD_NUMBER] = build_number
  end
rescue
  UI.user_error!("Apple Generic Versioning is not enabled in this project.\nBefore being able to increment and read the version number from your Xcode project, you first need to setup your project properly. Please follow the guide at https://developer.apple.com/library/content/qa/qa1827/_index.html")
end