Version endpoint

This commit is contained in:
MasseR committed 2026-06-01 09:32:01 +03:00
1 parent b38294c784
commit e87aae3144
4 files changed
+53 -11

No files matched your search

+9 -9
View File
@@ -1,9 +1,9 @@
{ mkDerivation, aeson, annotated-exception, base, bytestring
, containers, directory, ekg-core, exceptions, filepath
, generic-lens, http-client, http-types, katip, lens, lens-aeson
, lib, monad-control, mtl, optparse-generic, pandoc, pipes
, pipes-concurrency, retry, servant, servant-server, stm, streamly
, streamly-core, text, time, transformers-base, unliftio
, generic-lens, githash, http-client, http-types, katip, lens
, lens-aeson, lib, monad-control, mtl, optparse-generic, pandoc
, pipes, pipes-concurrency, retry, servant, servant-server, stm
, streamly, streamly-core, text, time, transformers-base, unliftio
, unordered-containers, wai, warp, wreq
}:
mkDerivation {
@@ -14,14 +14,14 @@ mkDerivation {
isExecutable = true;
libraryHaskellDepends = [
aeson annotated-exception base bytestring containers directory
ekg-core exceptions filepath generic-lens http-client http-types
katip lens lens-aeson monad-control mtl optparse-generic pandoc
pipes pipes-concurrency retry servant servant-server stm streamly
streamly-core text time transformers-base unliftio
ekg-core exceptions filepath generic-lens githash http-client
http-types katip lens lens-aeson monad-control mtl optparse-generic
pandoc pipes pipes-concurrency retry servant servant-server stm
streamly streamly-core text time transformers-base unliftio
unordered-containers wai warp wreq
];
executableHaskellDepends = [ base ];
testHaskellDepends = [ base ];
license = lib.licenses.bsd3;
license = lib.meta.getLicenseFromSpdxId "BSD-3-Clause";
mainProgram = "wallabag-tagger";
}
+8 -2
View File
@@ -21,6 +21,7 @@ import System.Metrics.Distribution qualified as D
import UnliftIO (liftIO)
import UnliftIO.IORef (readIORef)
import Data.Coerce (coerce)
import Version (Version, version)
data Health
= OK
@@ -57,7 +58,8 @@ newtype Metrics = Metrics (HashMap Text SampleValue)
data WallabagRoutes mode = WallabagRoutes
{ _getHealth :: mode :- "health" :> Get '[PlainText, JSON] Health,
_getMetrics :: mode :- "metrics" :> Get '[JSON] Metrics
_getMetrics :: mode :- "metrics" :> Get '[JSON] Metrics,
_getVersion :: mode :- "metrics" :> Get '[JSON] Version
}
deriving (Generic)
@@ -67,12 +69,16 @@ wallabagServer :: IORef Health -> WallabagRoutes (AsServerT M)
wallabagServer health =
WallabagRoutes
{ _getHealth = getHealth health,
_getMetrics = getMetrics
_getMetrics = getMetrics,
_getVersion = getVersion
}
getHealth :: IORef Health -> M Health
getHealth = readIORef
getVersion :: M Version
getVersion = pure version -- Comes from TH during compile time
getMetrics :: M Metrics
getMetrics = do
sample <- view metricsStore >>= liftIO . EKG.sampleAll
+34
View File
@@ -0,0 +1,34 @@
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
{-# HLINT ignore "Unused LANGUAGE pragma" #-}
module Version where
import GitHash (tGitInfoCwd, giHash, giDirty, giCommitDate, giCommitMessage)
import qualified Data.Aeson as A
import qualified Data.ByteString.Lazy.Char8 as BL
import GHC.Generics (Generic)
-- Populate the version via the 'githash' package
data Version = Version
{ versionCommit :: String
, versionDirty :: Bool
, versionCommitDate :: String
, versionCommitMessage :: String
}
deriving (Show, Generic)
instance A.ToJSON Version
version :: Version
version = Version
{ versionCommit = giHash gi
, versionDirty = giDirty gi
, versionCommitDate = giCommitDate gi
, versionCommitMessage = giCommitMessage gi
}
where
gi = $$tGitInfoCwd
test :: IO ()
test = BL.putStrLn $ A.encode version
+2
View File
@@ -27,6 +27,7 @@ library
HTTP
Server
Tracer
Version
-- other-modules:
-- other-extensions:
build-depends: base ^>=4.18.2.1
@@ -64,6 +65,7 @@ library
, generic-lens
, optparse-generic
, containers
, githash
hs-source-dirs: src
default-language: GHC2021