Class: AppVersion::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/appversion.rb

Instance Method Summary collapse

Instance Method Details

#build_noObject



79
80
81
# File 'lib/appversion.rb', line 79

def build_no
  CI.build_no
end

#suffixObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/appversion.rb', line 83

def suffix
  branch = CI.branch || Git.branch
  p "Branch = #{branch}."
  case branch
    when /develop/
      suffix = '-develop'
    when /master/
      suffix = '-master'
    when /feature*/
      suffix = "-#{branch.split('/').last.downcase}"
    when /release*/
      suffix = "-#{branch.split('/').last.downcase}"
    when /hotfix*/
      suffix = "-#{branch.split('/').last.downcase}"
    else
      suffix = '-debug'
  end
  #special case for github releases
  if CI.tagged_build?
    p 'Tagged build, suppressing branch suffix.'
    suffix = ''
  end
  return suffix
end

#to_sObject



40
41
42
# File 'lib/appversion.rb', line 40

def to_s
  "#{version} (#{build_no})"
end

#version(semantic = false) ⇒ Object

TODO: refactor so that every permutation can be tested. E.g. github release where is_pre_release=false, what is the commit count?



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/appversion.rb', line 45

def version(semantic = false)
  version_suffix = CI.version_suffix
  if Git.installed?
    latest_tag = Git.tag
    if latest_tag == 'HEAD'
      commit_count = Git.commit_count
      clean_tag = '0.0.1'
    elsif latest_tag.empty? #not a git directory
      commit_count = 0
      clean_tag = '0.0.1'
    else
      commit_count = Git.commit_count_since_tag(latest_tag)
      clean_tag = Git.clean_tag
    end
    #Only increment version after production release, so that we retain a single version during beta and RCs
    #TODO: check if this is a tagged build, and then always use the clean_tag. Not need to check pre_release or increment
    if commit_count == 0 || Release.is_pre_release?(latest_tag)
      short_version = clean_tag
    else
      short_version = clean_tag.increment_version
    end

    target = !version_suffix.empty? ? ":#{version_suffix.upcase}" : ''
    if semantic
      short_version
    else
      short_version + target + suffix
    end
  else
    $stderr.puts 'Git required, not installed.'
    exit 1
  end
end