Module: AnotherBrick::Tag

Extended by:
Tag
Included in:
Tag
Defined in:
lib/another_brick/tag.rb

Instance Method Summary collapse

Instance Method Details

#create(prefix) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/another_brick/tag.rb', line 5

def create(prefix)
  version_tag = get_last_tag('v')

  major, minor = strip_version('v', version_tag)

  last_tag = get_last_tag("#{prefix}_#{major}.#{minor}")

  build = last_tag ? strip_version("#{prefix}_", last_tag).last + 1 : 0

  "#{prefix}_#{major}.#{minor}.#{build}".tap do |next_tag|
    `git tag #{next_tag}`
    `git push --tags`
  end
end

#get_last_tag(pattern) ⇒ Object



20
21
22
# File 'lib/another_brick/tag.rb', line 20

def get_last_tag(pattern)
  `git tag | grep ^#{pattern} | sort -V`.lines.map(&:chomp).last
end

#strip_version(prefix, version) ⇒ Object



24
25
26
# File 'lib/another_brick/tag.rb', line 24

def strip_version(prefix, version)
  version.delete(prefix).split('.').map(&:to_i)
end