Last active
June 15, 2017 09:11
-
-
Save cybrox/e00bbeb348d1f34b12bd5537fb5f05a9 to your computer and use it in GitHub Desktop.
Distillery pseudo-plugin for appending git revision and branch (if not master) to a release version
This file contains hidden or 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
defmodule VersionBuilder do | |
@doc """ | |
Returns the current git info, consisting of the current revision and | |
the current branch, if it should differ from being "master" | |
""" | |
def git_info do | |
"#{git_revision()}#{git_branch()}" | |
end | |
defp git_revision do | |
{revision, 0} = System.cmd("git", ~w(rev-parse --short HEAD)) | |
"+#{String.trim(revision)}" | |
end | |
defp git_branch do | |
{branches, 0} = System.cmd("git", ~w(branch)) | |
branch = branches | |
|> String.split("\n") | |
|> Enum.find(fn(x) -> String.contains?(x, "*") end) | |
|> String.replace("*", "") | |
|> String.trim() | |
case branch do | |
"master" -> "" | |
other -> "+#{other}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment