Add Handler.BuildVersion

This commit is contained in:
Michael Snoyman 2015-01-06 10:10:47 +02:00
parent c5920c7a95
commit 2f0b328614
4 changed files with 32 additions and 0 deletions

View File

@ -70,6 +70,7 @@ import Handler.Tag
import Handler.BannedTags
import Handler.RefreshDeprecated
import Handler.Hoogle
import Handler.BuildVersion
-- This line actually creates our YesodDispatch instance. It is the second half
-- of the call to mkYesodData which occurs in Foundation.hs. Please see the

29
Handler/BuildVersion.hs Normal file
View File

@ -0,0 +1,29 @@
module Handler.BuildVersion where
import Import hiding (lift)
import Language.Haskell.TH.Syntax
import System.Process (rawSystem)
import System.Exit
getBuildVersionR :: Handler Text
getBuildVersionR = return $ pack $(do
let headFile = ".git/HEAD"
qAddDependentFile headFile
ehead <- qRunIO $ tryIO $ readFile $ fpFromString headFile
case decodeUtf8 <$> ehead of
Left e -> lift $ ".git/HEAD not read: " ++ show e
Right raw ->
case takeWhile (/= '\n') <$> stripPrefix "ref: " raw of
Nothing -> lift $ ".git/HEAD not in expected format: " ++ show raw
Just fp' -> do
let fp = ".git" </> fpFromText fp'
qAddDependentFile $ fpToString fp
bs <- qRunIO $ readFile fp
isDirty <- qRunIO
$ (/= ExitSuccess)
<$> rawSystem "git" ["diff-files", "--quiet"]
lift $ unpack $ unlines
[ "Most recent commit: " ++ asText (decodeUtf8 bs)
, "Working tree is " ++ (if isDirty then "dirty" else "clean")
]
)

View File

@ -54,3 +54,4 @@
/older-releases OlderReleasesR GET
/refresh-deprecated RefreshDeprecatedR GET
/build-version BuildVersionR GET

View File

@ -53,6 +53,7 @@ library
Handler.Tag
Handler.BannedTags
Handler.RefreshDeprecated
Handler.BuildVersion
if flag(dev) || flag(library-only)
cpp-options: -DDEVELOPMENT