Skip to content

Instantly share code, notes, and snippets.

@cybrox
Last active June 15, 2017 09:11
Show Gist options
  • Save cybrox/e00bbeb348d1f34b12bd5537fb5f05a9 to your computer and use it in GitHub Desktop.
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
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