Class: AppVersion::Version

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

Instance Method Summary collapse

Instance Method Details

#build_noObject



86
87
88
# File 'lib/appversion.rb', line 86

def build_no
  CI.build_no
end

#suffixObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/appversion.rb', line 90

def suffix
  branch = CI.branch || Git.branch
  $stdout.puts "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?
    $stdout.puts  '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
78
79
80
81
82
83
84
# File 'lib/appversion.rb', line 45

def version(semantic = false)
  version_suffix = CI.version_suffix
  if !Git.installed? then
    $stderr.puts 'Git required, not installed'
    exit 1
  end

  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
  is_pre_release = Release.is_pre_release?(latest_tag)
  $stdout.puts  "Latest tag = #{latest_tag}"
  $stdout.puts  "Commit count since tag = #{commit_count}"
  $stdout.puts  "Was tag from a Github pre-release? #{is_pre_release}"
  $stdout.puts  "Is this a Github release? #{CI.tagged_build?}"

  #Don't increment version for Github releases, if no commits have been made since last tag, or if last Github release was a pre_release
  if CI.tagged_build? || commit_count == 0 || is_pre_release
    short_version = clean_tag
  else
    short_version = clean_tag.increment_version
  end

  if semantic
    short_version
  else
    target = !version_suffix.empty? ? ":#{version_suffix.upcase}" : ''
    short_version + target + suffix
  end
end