Skip to content

Commit

Permalink
Make Livebook version accessible at compile time (#2280)
Browse files Browse the repository at this point in the history
Co-authored-by: José Valim <[email protected]>
  • Loading branch information
jonatanklosko and josevalim authored Oct 17, 2023
1 parent b5092c1 commit 5d78db6
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 9 deletions.
4 changes: 3 additions & 1 deletion lib/livebook/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -613,10 +613,12 @@ defmodule Livebook.Config do
end
end

@app_version Mix.Project.config()[:version]

@doc """
Returns the current version of running Livebook.
"""
def app_version, do: Application.spec(:livebook, :vsn) |> List.to_string()
def app_version(), do: @app_version

defp parse_connection_config!(config) do
{node, cookie} = split_at_last_occurrence(config, ":")
Expand Down
2 changes: 1 addition & 1 deletion lib/livebook/hubs/team_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ defmodule Livebook.Hubs.TeamClient do
derived_key = Teams.derive_key(team.teams_key)

headers = [
{"x-lb-version", to_string(Application.spec(:livebook, :vsn))},
{"x-lb-version", Livebook.Config.app_version()},
{"x-user", to_string(team.user_id)},
{"x-org", to_string(team.org_id)},
{"x-org-key", to_string(team.org_key_id)},
Expand Down
2 changes: 1 addition & 1 deletion lib/livebook/teams/requests.ex
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ defmodule Livebook.Teams.Requests do
token = "#{team.user_id}:#{team.org_id}:#{team.org_key_id}:#{team.session_token}"

[
{"x-lb-version", to_string(Application.spec(:livebook, :vsn))},
{"x-lb-version", Livebook.Config.app_version()},
{"authorization", "Bearer " <> token}
]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/livebook_cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ defmodule LivebookCLI do
IO.puts(:erlang.system_info(:system_version))
IO.puts("Elixir " <> System.build_info()[:build])

version = Application.spec(:livebook, :vsn)
version = Livebook.Config.app_version()
IO.puts("\nLivebook #{version}")
end
end
6 changes: 3 additions & 3 deletions lib/livebook_web/live/app_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ defmodule LivebookWeb.AppHelpers do

defp zta_options(), do: @zta_options

defp docker_tag_options() do
for image <- Livebook.Config.docker_images(), do: {image.tag, image.name}
end
@docker_tag_options for image <- Livebook.Config.docker_images(), do: {image.tag, image.name}

defp docker_tag_options(), do: @docker_tag_options

@doc """
Renders Docker deployment instruction for an app.
Expand Down
2 changes: 1 addition & 1 deletion lib/livebook_web/live/layout_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ defmodule LivebookWeb.LayoutHelpers do
</span>
</.link>
<span class="text-gray-300 text-xs font-normal font-sans mx-2.5 pt-3 cursor-default">
v<%= Application.spec(:livebook, :vsn) %>
v<%= Livebook.Config.app_version() %>
</span>
</div>
<.sidebar_link title="Home" icon="home-6-line" to={~p"/"} current={@current_page} />
Expand Down
2 changes: 1 addition & 1 deletion lib/livebook_web/live/settings_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ defmodule LivebookWeb.SettingsLive do
<% end %>
</.labeled_text>
<.labeled_text label="Livebook">
v<%= Application.spec(:livebook, :vsn) %>
v<%= Livebook.Config.app_version() %>
</.labeled_text>
<.labeled_text label="Elixir">
v<%= System.version() %>
Expand Down

0 comments on commit 5d78db6

Please sign in to comment.