Skip to content
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

feat: extend version with more build info #4069

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/*

Expand Down
25 changes: 24 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading