{-# LANGUAGE TemplateHaskell #-}
module Unison.Runtime.Version (runtimeVersion) where
import Control.Exception (SomeException, try)
import Data.Text (Text)
import Data.Text qualified as Text
import Language.Haskell.TH (Exp (LitE, TupE), Lit (StringL), runIO)
import System.Process (readProcess)
runtimeVersion :: Text
runtimeVersion :: Text
runtimeVersion = String -> Text
Text.pack String
tag Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" (built on " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack String
date Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
")"
where
(String
tag, String
date) :: (String, String) =
$( runIO $ do
let git args fallback =
either (\(_ :: SomeException) -> fallback) (takeWhile (/= '\n'))
<$> try (readProcess "git" args "")
date <- git ["show", "-s", "--format=%cs"] ""
tag <- git ["describe", "--tags", "--always", "--dirty='"] "unknown"
pure (TupE [Just (LitE (StringL tag)), Just (LitE (StringL date))])
)