Class: Fastlane::Actions::GetBuildNumberAction

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

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, author, return_value, sh, step_text

Class Method Details

.authorsObject



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

def self.authors
  ["Liquidsoul"]
end

.available_optionsObject



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fastlane/actions/get_build_number.rb', line 54

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|
                         raise "Please pass the path to the project, not the workspace".red if value.end_with? ".xcworkspace"
                         raise "Could not find Xcode project".red if !File.exist?(value) and !Helper.is_test?
                       end)
  ]
end

.descriptionObject



42
43
44
# File 'lib/fastlane/actions/get_build_number.rb', line 42

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

.detailsObject



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

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"
  ].join(' ')
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/fastlane/actions/get_build_number.rb', line 77

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

.outputObject



67
68
69
70
71
# File 'lib/fastlane/actions/get_build_number.rb', line 67

def self.output
  [
    ['BUILD_NUMBER', 'The build number']
  ]
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
# File '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
rescue => ex
  Helper.log.error 'Make sure to follow the steps to setup your Xcode project: https://developer.apple.com/library/ios/qa/qa1827/_index.html'.yellow
  raise ex
end