-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read Git Revision (Hash) in Elixir #53
Comments
https://stackoverflow.com/questions/22594988/run-shell-commands-in-elixir
so the Git Revision in Elixir is:
|
surprisingly easy even with my paltry Elixir/Phoenix skills ... 😮 add the following handler to: def git_revision_hash(conn, _params) do
{rev, i} = System.cmd("git", ["rev-parse", "HEAD"])
text conn, String.replace(rev, "\n", "")
end add route to get "/_version", PageController, :git_revision_hash Which is exactly what I wanted. ✅ |
Learned how to render text from: |
def git_revision_hash(conn, _params) do
IO.inspect(System.cmd("pwd", []))
{ls, _} = IO.inspect(System.cmd("ls", ["-a"]))
ls = String.split(ls, "\n")
IO.inspect ls
unless Enum.member?(ls, ".git") do
File.cd("./builds")
IO.inspect(System.cmd("pwd", []))
end
{rev, _} = System.cmd("git", ["rev-parse", "HEAD"])
IO.puts(String.replace(rev, "\n", ""))
text conn, String.replace(rev, "\n", "")
end still debugging it, will reduce debug lines once it's working. |
Result! This Git Hash corresponds to this commit: nelsonic/hello_world_edeliver@7cb64a0 So it's trivial to see exactly which version of the project is running in a given environment! |
Got it working in: dwyl/learn-devops#19 (comment) |
I would like to display the git revision hash when visiting a url in an application
so that everyone on the project knows exactly which version of the app
is in "staging" or production.
e.g visiting: https://www.healthlocker.uk/_version
healthlocker/healthlocker@cc66a3c
We made the Git Revision available in dwyl/aws-lambda-deploy/lib/utils.js#L80-L81
So it's a matter of running a similar command in Elixir and returning that when visiting the route.
Todo
edeliver
(I don't see a reason why not, we need to be certain)The text was updated successfully, but these errors were encountered: