show sha1 hash of aprs parser
This commit is contained in:
parent
32cfb36ee9
commit
52311f52da
2 changed files with 82 additions and 0 deletions
46
lib/aprsme/dependency_info.ex
Normal file
46
lib/aprsme/dependency_info.ex
Normal 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
|
||||||
|
|
@ -14,6 +14,7 @@ defmodule AprsmeWeb.StatusLive.Index do
|
||||||
page_title: "System Status",
|
page_title: "System Status",
|
||||||
aprs_status: get_aprs_status(),
|
aprs_status: get_aprs_status(),
|
||||||
version: get_app_version(),
|
version: get_app_version(),
|
||||||
|
aprs_library_sha: get_aprs_library_sha(),
|
||||||
current_time: DateTime.utc_now(),
|
current_time: DateTime.utc_now(),
|
||||||
health_score: calculate_health_score(get_aprs_status())
|
health_score: calculate_health_score(get_aprs_status())
|
||||||
)
|
)
|
||||||
|
|
@ -48,6 +49,37 @@ defmodule AprsmeWeb.StatusLive.Index do
|
||||||
</div>
|
</div>
|
||||||
</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 -->
|
<!-- Overall Status Alert -->
|
||||||
<%= if not @aprs_status.connected do %>
|
<%= if not @aprs_status.connected do %>
|
||||||
<div class="alert alert-error mb-6">
|
<div class="alert alert-error mb-6">
|
||||||
|
|
@ -259,6 +291,10 @@ defmodule AprsmeWeb.StatusLive.Index do
|
||||||
:aprsme |> Application.spec(:vsn) |> List.to_string()
|
:aprsme |> Application.spec(:vsn) |> List.to_string()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp get_aprs_library_sha do
|
||||||
|
Aprsme.DependencyInfo.get_aprs_library_sha()
|
||||||
|
end
|
||||||
|
|
||||||
defp refresh_status(socket) do
|
defp refresh_status(socket) do
|
||||||
aprs_status = get_aprs_status()
|
aprs_status = get_aprs_status()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue