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(explorer): add aligned latest version in nav #922

Merged
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
14 changes: 14 additions & 0 deletions explorer/lib/explorer_web/components/nav.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
defmodule NavComponent do
use ExplorerWeb, :live_component

@impl true
def mount(socket) do
{:ok, assign(socket, latest_release: ReleasesHelper.get_latest_release())}
end

@impl true
def render(assigns) do
~H"""
Expand Down Expand Up @@ -46,6 +51,12 @@ defmodule NavComponent do
GitHub
</.link>
<DarkMode.button />
<.badge :if={@latest_release != nil} class="hidden md:inline">
<%= @latest_release %>
<.tooltip>
Latest Aligned version
</.tooltip>
</.badge>
<button
class="md:hidden z-50"
id="menu-toggle"
Expand All @@ -61,6 +72,9 @@ defmodule NavComponent do
phx-click={toggle_menu()}
>
<div class="h-full flex flex-col gap-y-10 text-2xl justify-end items-center p-12">
<.badge :if={@latest_release != nil}>
<%= @latest_release %>
</.badge>
<.link
class="text-foreground/80 hover:text-foreground font-semibold"
navigate={~p"/batches"}
Expand Down
40 changes: 40 additions & 0 deletions explorer/lib/explorer_web/live/releases_helper.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
defmodule ReleasesHelper do
require Logger

def get_latest_release do
case do_fetch_latest_release() do
{:ok, tag} ->
tag

{:error, reason} ->
Logger.error("Failed to fetch latest release: #{reason}")
nil
end
end

defp do_fetch_latest_release do
with :ok <- fetch_tags(),
{:ok, tag} <- get_latest_tag() do
{:ok, tag}
end
end

defp fetch_tags do
case System.cmd("git", ["fetch", "--tags"]) do
{_, 0} -> :ok
{error, _} -> {:error, "Failed to fetch tags: #{error}"}
end
end

defp get_latest_tag do
case System.cmd("git", ["rev-list", "--tags", "--max-count=1"]) do
{sha, 0} ->
sha = String.trim(sha)
case System.cmd("git", ["describe", "--tags", sha]) do
{tag, 0} -> {:ok, String.trim(tag)}
{_, _} -> {:error, "Failed to describe tag"}
end
{_, _} -> {:error, "No tags found or not a git repository"}
end
end
end