show sha1 hash of aprs parser

This commit is contained in:
Graham McIntire 2025-07-07 12:57:28 -05:00
parent 32cfb36ee9
commit 52311f52da
No known key found for this signature in database
2 changed files with 82 additions and 0 deletions

View file

@ -0,0 +1,46 @@
defmodule Aprsme.DependencyInfo do
@moduledoc """
Provides information about dependencies, particularly for production builds.
"""
@doc """
Gets the SHA1 hash of the aprs library currently being used.
In development: reads from vendor/aprs directory
In production: fetches from GitHub API
"""
def get_aprs_library_sha do
if Mix.env() == :prod do
fetch_aprs_sha_from_github()
else
get_aprs_sha_from_vendor()
end
end
defp get_aprs_sha_from_vendor do
vendor_path = Path.join([File.cwd!(), "vendor", "aprs"])
if File.dir?(vendor_path) do
case System.cmd("git", ["rev-parse", "HEAD"], cd: vendor_path) do
{sha, 0} -> String.slice(String.trim(sha), 0, 7)
_ -> nil
end
end
rescue
_ -> nil
end
defp fetch_aprs_sha_from_github do
case HTTPoison.get("https://api.github.com/repos/aprsme/aprs/commits/main") do
{:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
case Jason.decode(body) do
{:ok, %{"sha" => sha}} -> String.slice(sha, 0, 7)
_ -> nil
end
_ ->
nil
end
rescue
_ -> nil
end
end

View file

@ -14,6 +14,7 @@ defmodule AprsmeWeb.StatusLive.Index do
page_title: "System Status",
aprs_status: get_aprs_status(),
version: get_app_version(),
aprs_library_sha: get_aprs_library_sha(),
current_time: DateTime.utc_now(),
health_score: calculate_health_score(get_aprs_status())
)
@ -48,6 +49,37 @@ defmodule AprsmeWeb.StatusLive.Index do
</div>
</div>
<!-- Application Information -->
<div class="mb-8">
<h2 class="text-xl font-semibold mb-4">{gettext("Application Information")}</h2>
<div class="card bg-base-200">
<div class="card-body">
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="flex items-center">
<span class="text-sm font-medium opacity-70 mr-2">{gettext("Version:")}</span>
<span class="text-sm font-mono">{@version}</span>
</div>
<%= if @aprs_library_sha do %>
<div class="flex items-center">
<span class="text-sm font-medium opacity-70 mr-2">
{gettext("APRS Library:")}
</span>
<span class="text-sm font-mono">
<a
href="https://github.com/aprsme/aprs/commit/{@aprs_library_sha}"
target="_blank"
class="link link-primary"
>
{@aprs_library_sha}
</a>
</span>
</div>
<% end %>
</div>
</div>
</div>
</div>
<!-- Overall Status Alert -->
<%= if not @aprs_status.connected do %>
<div class="alert alert-error mb-6">
@ -259,6 +291,10 @@ defmodule AprsmeWeb.StatusLive.Index do
:aprsme |> Application.spec(:vsn) |> List.to_string()
end
defp get_aprs_library_sha do
Aprsme.DependencyInfo.get_aprs_library_sha()
end
defp refresh_status(socket) do
aprs_status = get_aprs_status()