Class: Fastlane::Helper::GitBuildVersioningHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/git_build_versioning/helper/git_build_versioning_helper.rb

Class Method Summary collapse

Class Method Details

.build_tags(tag_prefix) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/fastlane/plugin/git_build_versioning/helper/git_build_versioning_helper.rb', line 100

def self.build_tags(tag_prefix)
  if self.is_git?

    builds = Actions.sh("git ls-remote --tags --refs --quiet", log: false)
    tags = builds.split(/\r?\n/)
                 .map { |s| GitBuildTag.new(s, tag_prefix) }
                 .reject { |t| t.build_number.nil? }
                 .sort_by(&:build_number)

    tags
  else
    UI.user_error!("No git repository detected")
  end
end

.current_build_number(tag_prefix) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/fastlane/plugin/git_build_versioning/helper/git_build_versioning_helper.rb', line 82

def self.current_build_number(tag_prefix)
  head = self.head
  tags = self.build_tags(tag_prefix)

  tags.select { |t| t.hash == head }
      .map(&:build_number)
      .last
end

.headObject



91
92
93
94
95
96
97
98
# File 'lib/fastlane/plugin/git_build_versioning/helper/git_build_versioning_helper.rb', line 91

def self.head
  if self.is_git?
    head = Actions.sh("git rev-parse HEAD", log: false)
    (head || "").strip
  else
    UI.user_error!("No git repository detected")
  end
end

.is_git?Boolean

Returns:

  • (Boolean)


41
42
43
44
45
46
# File 'lib/fastlane/plugin/git_build_versioning/helper/git_build_versioning_helper.rb', line 41

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

.last_build_number(tag_prefix) ⇒ Object



76
77
78
79
80
# File 'lib/fastlane/plugin/git_build_versioning/helper/git_build_versioning_helper.rb', line 76

def self.last_build_number(tag_prefix)
  self.build_tags(tag_prefix)
      .map(&:build_number)
      .last
end

.reserve_build_number(tag_prefix) ⇒ Object

class methods that you define here become available in your action as Helper::GitBuildVersioningHelper.your_method



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/fastlane/plugin/git_build_versioning/helper/git_build_versioning_helper.rb', line 51

def self.reserve_build_number(tag_prefix)
  head = self.head
  tags = self.build_tags(tag_prefix)

  current = tags
            .select { |t| t.hash == head }
            .map(&:build_number)
            .last

  if current.nil?
    latest = tags
             .map(&:build_number)
             .last
    current = (latest || 0) + 1

    tag_name = "#{tag_prefix}#{current}"
    Actions.sh("git tag #{tag_name} && git push --quiet origin #{tag_name}", log: false)
    UI.success("Tagging #{tag_name}")
  else
    UI.success("Current commit already tagged as build #{tag_name}")
  end

  current
end