Class: Fastlane::Actions::GetBuildNumberRepositoryAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/get_build_number_repository.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_type, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorsObject



101
102
103
# File 'fastlane/lib/fastlane/actions/get_build_number_repository.rb', line 101

def self.authors
  ["bartoszj", "pbrooks", "armadsen"]
end

.available_optionsObject



80
81
82
83
84
85
86
87
88
89
# File 'fastlane/lib/fastlane/actions/get_build_number_repository.rb', line 80

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :use_hg_revision_number,
                                 env_name: "USE_HG_REVISION_NUMBER",
                                 description: "Use hg revision number instead of hash (ignored for non-hg repos)",
                                 optional: true,
                                 type: Boolean,
                                 default_value: false)
  ]
end

.categoryObject



115
116
117
# File 'fastlane/lib/fastlane/actions/get_build_number_repository.rb', line 115

def self.category
  :source_control
end

.command(use_hg_revision_number) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'fastlane/lib/fastlane/actions/get_build_number_repository.rb', line 36

def self.command(use_hg_revision_number)
  if is_svn?
    UI.message("Detected repo: svn")
    return 'svn info | grep Revision | egrep -o "[0-9]+"'
  elsif is_git_svn?
    UI.message("Detected repo: git-svn")
    return 'git svn info | grep Revision | egrep -o "[0-9]+"'
  elsif is_git?
    UI.message("Detected repo: git")
    return 'git rev-parse --short HEAD'
  elsif is_hg?
    UI.message("Detected repo: hg")
    if use_hg_revision_number
      return 'hg parent --template {rev}'
    else
      return 'hg parent --template "{node|short}"'
    end
  else
    UI.user_error!("No repository detected")
  end
end

.descriptionObject



68
69
70
# File 'fastlane/lib/fastlane/actions/get_build_number_repository.rb', line 68

def self.description
  "Get the build number from the current repository"
end

.detailsObject



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

def self.details
  [
    "This action will get the **build number** according to what the SCM HEAD reports.",
    "Currently supported SCMs are svn (uses root revision), git-svn (uses svn revision), git (uses short hash) and mercurial (uses short hash or revision number).",
    "There is an option, `:use_hg_revision_number`, which allows to use mercurial revision number instead of hash."
  ].join("\n")
end

.example_codeObject



109
110
111
112
113
# File 'fastlane/lib/fastlane/actions/get_build_number_repository.rb', line 109

def self.example_code
  [
    'get_build_number_repository'
  ]
end

.is_git?Boolean

Returns:



15
16
17
18
19
20
# File 'fastlane/lib/fastlane/actions/get_build_number_repository.rb', line 15

def self.is_git?
  Actions.sh('git rev-parse HEAD')
  return true
rescue
  return false
end

.is_git_svn?Boolean

Returns:



22
23
24
25
26
27
# File 'fastlane/lib/fastlane/actions/get_build_number_repository.rb', line 22

def self.is_git_svn?
  Actions.sh('git svn info')
  return true
rescue
  return false
end

.is_hg?Boolean

Returns:



29
30
31
32
33
34
# File 'fastlane/lib/fastlane/actions/get_build_number_repository.rb', line 29

def self.is_hg?
  Actions.sh('hg status')
  return true
rescue
  return false
end

.is_supported?(platform) ⇒ Boolean

Returns:



105
106
107
# File 'fastlane/lib/fastlane/actions/get_build_number_repository.rb', line 105

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

.is_svn?Boolean

Returns:



8
9
10
11
12
13
# File 'fastlane/lib/fastlane/actions/get_build_number_repository.rb', line 8

def self.is_svn?
  Actions.sh('svn info')
  return true
rescue
  return false
end

.outputObject



91
92
93
94
95
# File 'fastlane/lib/fastlane/actions/get_build_number_repository.rb', line 91

def self.output
  [
    ['BUILD_NUMBER_REPOSITORY', 'The build number from the current repository']
  ]
end

.return_valueObject



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

def self.return_value
  "The build number from the current repository"
end

.run(params) ⇒ Object



58
59
60
61
62
# File 'fastlane/lib/fastlane/actions/get_build_number_repository.rb', line 58

def self.run(params)
  build_number = Action.sh(command(params[:use_hg_revision_number])).strip
  Actions.lane_context[SharedValues::BUILD_NUMBER_REPOSITORY] = build_number
  return build_number
end