lib/appversion.rb in overview-0.0.4.14 vs lib/appversion.rb in overview-0.0.4.17
- old
+ new
@@ -3,22 +3,22 @@
class Release
def self.is_pre_release?(tag)
default = TRUE #default to true if running locally
begin
if tag.empty?
- p 'No tag, so unable to check Github release status.'
+ p 'No tag, so unable to check Github release status'
default
else
require 'octokit'
repo = CI.repo || Git.repo
- p "Repo slug is #{repo}."
+ $stdout.puts "Repo slug is #{repo}"
if repo.empty? || ENV['GITHUB_TOKEN'].nil? #for local builds
- p 'GITHUB_TOKEN missing, running locally.'
+ $stdout.puts 'GITHUB_TOKEN missing, running locally'
default
else
client = Octokit::Client.new(:access_token => ENV['GITHUB_TOKEN'])
- p 'Connecting to Github.'
+ $stdout.puts 'Connecting to Github'
client.user.login
client.default_media_type = "application/vnd.github.moondragon+json"
release = client.release_for_tag(repo, tag)
if !release
default
@@ -27,11 +27,11 @@
end
end
end
rescue LoadError
- p 'Octokit gem missing, running locally.'
+ $stdout.puts 'Octokit gem missing, running locally'
default
end
end
end
@@ -42,49 +42,56 @@
end
#TODO: refactor so that every permutation can be tested. E.g. github release where is_pre_release=false, what is the commit count?
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
+ if !Git.installed? then
+ $stderr.puts 'Git required, not installed'
+ exit 1
+ end
- target = !version_suffix.empty? ? ":#{version_suffix.upcase}" : ''
- if semantic
- short_version
- else
- short_version + target + suffix
- 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
- $stderr.puts 'Git required, not installed.'
- exit 1
+ 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
def build_no
CI.build_no
end
def suffix
branch = CI.branch || Git.branch
- p "Branch = #{branch}."
+ $stdout.puts "Branch = #{branch}"
case branch
when /develop/
suffix = '-develop'
when /master/
suffix = '-master'
@@ -97,10 +104,10 @@
else
suffix = '-debug'
end
#special case for github releases
if CI.tagged_build?
- p 'Tagged build, suppressing branch suffix.'
+ $stdout.puts 'Tagged build, suppressing branch suffix'
suffix = ''
end
return suffix
end
end
\ No newline at end of file