Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Display the git tag, branch/commit or version when possible
Browse files Browse the repository at this point in the history
Signed-off-by: Yann Lopez <[email protected]>
  • Loading branch information
lonewulf authored and mssola committed May 6, 2016
1 parent a5ea875 commit c1fb8c3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/views/layouts/application.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ html
'Created with
i.fa.fa-heart
'by the SUSE team
- if current_user.admin? && Version.value
p
'Version: #{Version.value}
28 changes: 28 additions & 0 deletions config/initializers/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'mkmf'

# Version module
# Makes the app version available to the application itself
# Needs the git executable for all git operations
module Version
git = find_executable('git')
BRANCH = git ? `git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3 2>/dev/null`.chomp : nil
COMMIT = git ? `git log --pretty=format:'%h' -n 1 2>/dev/null`.chomp : nil
TAG = git ? `git tag --points-at $(git rev-parse HEAD) 2>/dev/null`.chomp : nil

# Version.value returns the app version
# Priority: git tag > git branch/commit > VERSION file
def self.value
if TAG.present?
"#{TAG}"
elsif COMMIT.present?
if BRANCH.present?
"#{BRANCH}@#{COMMIT}"
else
"#{COMMIT}"
end
else
version = Rails.root.join("VERSION")
File.read(version).chomp if File.exists?(version)
end
end
end

0 comments on commit c1fb8c3

Please sign in to comment.