This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display the git tag, branch/commit or version when possible
Signed-off-by: Yann Lopez <[email protected]>
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |