Class: Fastlane::Actions::GetBuildNumberAction

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

Constant Summary

Constants inherited from Fastlane::Action

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

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, author, deprecated_notes, lane_context, method_missing, other_action, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorsObject



79
80
81
# File 'fastlane/lib/fastlane/actions/get_build_number.rb', line 79

def self.authors
  ["Liquidsoul"]
end

.available_optionsObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'fastlane/lib/fastlane/actions/get_build_number.rb', line 55

def self.available_options
  [
    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),
    FastlaneCore::ConfigItem.new(key: :hide_error_when_versioning_disabled,
                       env_name: "FL_BUILD_NUMBER_HIDE_ERROR_WHEN_VERSIONING_DISABLED",
                       description: "Used during `fastlane init` to hide the error message",
                       default_value: false,
                       type: Boolean)
  ]
end

.categoryObject



97
98
99
# File 'fastlane/lib/fastlane/actions/get_build_number.rb', line 97

def self.category
  :project
end

.descriptionObject



44
45
46
# File 'fastlane/lib/fastlane/actions/get_build_number.rb', line 44

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

.detailsObject



48
49
50
51
52
53
# File 'fastlane/lib/fastlane/actions/get_build_number.rb', line 48

def self.details
  [
    "This action will return the current build number set on your project.",
    "You first have to set up your Xcode project, if you haven't done it already: [https://developer.apple.com/library/ios/qa/qa1827/_index.html](https://developer.apple.com/library/ios/qa/qa1827/_index.html)."
  ].join("\n")
end

.example_codeObject



87
88
89
90
91
# File 'fastlane/lib/fastlane/actions/get_build_number.rb', line 87

def self.example_code
  [
    'build_number = get_build_number(xcodeproj: "Project.xcodeproj")'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



83
84
85
# File 'fastlane/lib/fastlane/actions/get_build_number.rb', line 83

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

.outputObject



73
74
75
76
77
# File 'fastlane/lib/fastlane/actions/get_build_number.rb', line 73

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

.return_typeObject



93
94
95
# File 'fastlane/lib/fastlane/actions/get_build_number.rb', line 93

def self.return_type
  :string
end

.run(params) ⇒ Object



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
# File 'fastlane/lib/fastlane/actions/get_build_number.rb', line 6

def self.run(params)
  # More information about how to set up your project and how it works:
  # https://developer.apple.com/library/ios/qa/qa1827/_index.html

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

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

  command = [
    command_prefix,
    'agvtool',
    'what-version',
    '-terse'
  ].join(' ')

  if Helper.test?
    Actions.lane_context[SharedValues::BUILD_NUMBER] = command
  else
    build_number = Actions.sh(command).split("\n").last.strip

    # Store the number in the shared hash
    Actions.lane_context[SharedValues::BUILD_NUMBER] = build_number
  end
  return build_number
rescue => ex
  return false if params[:hide_error_when_versioning_disabled]
  UI.error('Before 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')
  raise ex
end