diff --git a/CHANGELOG.md b/CHANGELOG.md index 912f4e35a2..06f85666db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ #### Build, CI, internal - ci: fix coverage report env variable (#4066 - @JakobLichterfeld) +- feat: extend version with more build info (#4069 - @JakobLichterfeld) #### Dashboards diff --git a/Dockerfile b/Dockerfile index 857c7e1899..9ad57049ca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,7 @@ RUN apt-get update \ | tee /etc/apt/sources.list.d/nodesource.list \ && apt-get update \ && apt-get install nodejs -y \ + && apt-get install -y git \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* diff --git a/mix.exs b/mix.exs index d159eefd6e..bbc3bde580 100644 --- a/mix.exs +++ b/mix.exs @@ -103,9 +103,32 @@ defmodule TeslaMate.MixProject do end defp version do + case System.cmd("git", ~w[describe --dirty=+dirty], stderr_to_stdout: true) do + {version, 0} -> + case Version.parse(version) do + {:ok, parsed_version} -> + parsed_version + |> bump_version() + |> to_string() + + _error -> + fallback_to_version_from_file() + end + + _ -> + fallback_to_version_from_file() + end + end + + defp bump_version(%Version{pre: []} = version), do: version + + defp bump_version(%Version{patch: p} = version), + do: struct(version, patch: p + 1) + + defp fallback_to_version_from_file do case File.read("VERSION") do {:ok, version} -> String.trim(version) - {:error, _reason} -> "0.0.0" + {:error, _reason} -> "0.0.0-dev" end end end