From 52311f52dae780b42eae1f985650546a1f699b3e Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Mon, 7 Jul 2025 12:57:28 -0500 Subject: [PATCH] show sha1 hash of aprs parser --- lib/aprsme/dependency_info.ex | 46 ++++++++++++++++++++++++ lib/aprsme_web/live/status_live/index.ex | 36 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 lib/aprsme/dependency_info.ex diff --git a/lib/aprsme/dependency_info.ex b/lib/aprsme/dependency_info.ex new file mode 100644 index 0000000..e29e417 --- /dev/null +++ b/lib/aprsme/dependency_info.ex @@ -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 diff --git a/lib/aprsme_web/live/status_live/index.ex b/lib/aprsme_web/live/status_live/index.ex index bdc55b9..d4791a7 100644 --- a/lib/aprsme_web/live/status_live/index.ex +++ b/lib/aprsme_web/live/status_live/index.ex @@ -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 + +
+

{gettext("Application Information")}

+
+
+
+
+ {gettext("Version:")} + {@version} +
+ <%= if @aprs_library_sha do %> +
+ + {gettext("APRS Library:")} + + + + {@aprs_library_sha} + + +
+ <% end %> +
+
+
+
+ <%= if not @aprs_status.connected do %>
@@ -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()