Use yesod-gitrev and githash

This commit is contained in:
Michael Snoyman 2018-06-25 12:35:42 +03:00
parent 96e9a53a17
commit 760b356c0c
No known key found for this signature in database
GPG Key ID: A048E8C057E86876
6 changed files with 8 additions and 32 deletions

View File

@ -42,7 +42,7 @@
/install InstallR GET
/older-releases OlderReleasesR GET
/build-version BuildVersionR GET
/build-version BuildVersionR GitRev appGitRev
/download DownloadR GET
/download/snapshots.json DownloadSnapshotsJsonR GET

View File

@ -70,6 +70,7 @@ dependencies:
- blaze-html
- haddock-library
- yesod-gitrepo
- yesod-gitrev
- hoogle
- deepseq
- auto-update

View File

@ -37,6 +37,7 @@ import Stackage.Database (openStackageDatabase, PostgresConf (..))
import Stackage.Database.Cron (newHoogleLocker, singleRun)
import Control.AutoUpdate
import Control.Concurrent (threadDelay)
import Yesod.GitRev (tGitRev)
-- Import all relevant handler modules here.
-- Don't forget to add new modules to your cabal file!
@ -51,7 +52,6 @@ import Handler.Package
import Handler.PackageDeps
import Handler.PackageList
import Handler.Hoogle
import Handler.BuildVersion
import Handler.Sitemap
import Handler.BuildPlan
import Handler.Download
@ -144,6 +144,7 @@ makeFoundation appSettings = do
appMirrorStatus <- mkUpdateMirrorStatus
hoogleLocker <- newHoogleLocker True appHttpManager
let appGetHoogleDB = singleRun hoogleLocker
let appGitRev = $$tGitRev
return App {..}

View File

@ -12,6 +12,7 @@ import Yesod.AtomFeed
import Yesod.GitRepo
import Stackage.Database
import qualified Yesod.Core.Unsafe as Unsafe
import Yesod.GitRev (GitRev)
-- | The site argument for your application. This can be a good place to
-- keep settings and values requiring initialization before your application
@ -31,6 +32,7 @@ data App = App
-- https://github.com/fpco/stackage-server/issues/172
, appMirrorStatus :: IO (Status, WidgetFor App ())
, appGetHoogleDB :: SnapName -> IO (Maybe FilePath)
, appGitRev :: GitRev
}
instance HasHttpManager App where

View File

@ -1,29 +0,0 @@
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 $ 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" </> unpack (fp' :: Text)
qAddDependentFile 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

@ -1,4 +1,5 @@
resolver: nightly-2018-06-20
extra-deps:
- archive: https://github.com/snoyberg/gitrev/archive/6a1a639f493ac08959eb5ddf540ca1937baaaaf9.tar.gz
- archive: https://github.com/bitemyapp/esqueleto/archive/b81e0d951e510ebffca03c5a58658ad884cc6fbd.tar.gz
- archive: https://github.com/snoyberg/githash/archive/a80ff63bb32d2a3920bb870b4395ee231df0bd6e.tar.gz
- archive: https://github.com/snoyberg/yesod-gitrev/archive/98383b2d5ddad23b1503468d83b2ced76e6c6fe8.tar.gz