release :my_release do
set(version: "0.1.1") # <--- here
set(
applications: [
# ...
]
)
end
and in each app’s mix.exs
def project do
[
app: :my_app,
version: "0.1.5", # <--- here
# ...
]
end
So far I’ve been naively setting them manually, but I’d like to somehow automate the process.
I’ve been thinking about setting the release version to a unix timestamp before each call to mix release. Are there any potential downsides to it? I mostly need it for hot code upgrades.
What can I do about individual app’s versions? Read them from environmental variables and add a pre-commit git hook that would increment those?
I’m not entirely happy with it, but for the time being each app in the umbrella sets its version by doing a Code.eval_file call to a common compile-time .exs file that reads the current git SHA and appends it to the base version.
defmodule GitVersion do
def version do
case System.cmd(
"git",
~w[describe --always --dirty=+dirty],
stderr_to_stdout: true
) do
{raw, 0} ->
case Version.parse(raw) do
{:ok, version} ->
version
|> bump_version()
|> to_string()
:error ->
"0.0.0-#{String.trim(raw)}"
end
_ ->
"0.0.0-dev"
end
end
defp bump_version(%Version{pre: []} = version), do: version
defp bump_version(%Version{patch: p} = version),
do: struct(version, patch: p + 1)
end
In my mix.exs to extract version from the Git tags. TBH I would <3 to see something like that in Mix itself like there is {version, git} in Rebar3. This would make version management so much simpler.