Method: AppVersion::Version#version

Defined in:
lib/appversion.rb

#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