Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git last commit hash and current version

In my Elixir/Phoenix application I want to show the current commit hash from git and version number from the mix.exs file on an html page. How can I do that? That is, is there access to this kind of information at all?

like image 912
Kotaa Avatar asked Oct 16 '25 05:10

Kotaa


1 Answers

To extract the current commit hash, I have this solution:

{hash, _} = System.cmd("git", ["rev-parse", "HEAD"])
# => {"5f6910ce1f42d5026d0ec5544ce6df9c3f8caf17\n", 0}

String.trim(hash)
# => "5f6910ce1f42d5026d0ec5544ce6df9c3f8caf17"

To get the app version you can try this:

{:ok, vsn} = :application.get_key(:my_app, :vsn)
# => {:ok, '0.1.1'}

vsn
# => '0.1.1'

List.to_string(vsn)
# => "0.1.1"

Replace the atom :my_app with your app atom.

Or you use:

Mix.Project.config[:version]
# => "0.1.1"

See Mix.Project.config for more information.

like image 115
guitarman Avatar answered Oct 19 '25 09:10

guitarman