mirror of
https://github.com/commercialhaskell/stackage-server.git
synced 2026-01-23 09:21:56 +01:00
Add Handler.BuildVersion
This commit is contained in:
parent
c5920c7a95
commit
2f0b328614
@ -70,6 +70,7 @@ import Handler.Tag
|
|||||||
import Handler.BannedTags
|
import Handler.BannedTags
|
||||||
import Handler.RefreshDeprecated
|
import Handler.RefreshDeprecated
|
||||||
import Handler.Hoogle
|
import Handler.Hoogle
|
||||||
|
import Handler.BuildVersion
|
||||||
|
|
||||||
-- This line actually creates our YesodDispatch instance. It is the second half
|
-- 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
|
-- of the call to mkYesodData which occurs in Foundation.hs. Please see the
|
||||||
|
|||||||
29
Handler/BuildVersion.hs
Normal file
29
Handler/BuildVersion.hs
Normal 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")
|
||||||
|
]
|
||||||
|
)
|
||||||
@ -54,3 +54,4 @@
|
|||||||
/older-releases OlderReleasesR GET
|
/older-releases OlderReleasesR GET
|
||||||
|
|
||||||
/refresh-deprecated RefreshDeprecatedR GET
|
/refresh-deprecated RefreshDeprecatedR GET
|
||||||
|
/build-version BuildVersionR GET
|
||||||
|
|||||||
@ -53,6 +53,7 @@ library
|
|||||||
Handler.Tag
|
Handler.Tag
|
||||||
Handler.BannedTags
|
Handler.BannedTags
|
||||||
Handler.RefreshDeprecated
|
Handler.RefreshDeprecated
|
||||||
|
Handler.BuildVersion
|
||||||
|
|
||||||
if flag(dev) || flag(library-only)
|
if flag(dev) || flag(library-only)
|
||||||
cpp-options: -DDEVELOPMENT
|
cpp-options: -DDEVELOPMENT
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user