graphql-engine/server/src-lib/Hasura/Server/Version.hs

62 lines
1.7 KiB
Haskell
Raw Normal View History

{-# OPTIONS_GHC -fforce-recomp #-}
module Hasura.Server.Version
( currentVersion
, consoleVersion
2019-01-28 16:55:28 +03:00
, isDevVersion
)
where
import Control.Lens ((^.), (^?))
import Data.Either (isLeft)
import qualified Data.SemVer as V
import qualified Data.Text as T
import Hasura.Prelude
import Hasura.Server.Utils (getValFromEnvOrScript)
version :: T.Text
version = T.dropWhileEnd (== '\n')
$(getValFromEnvOrScript "VERSION" "../scripts/get-version.sh")
parsedVersion :: Either String V.Version
parsedVersion = V.fromText $ T.dropWhile (== 'v') version
currentVersion :: T.Text
currentVersion = version
2019-01-28 16:55:28 +03:00
isDevVersion :: Bool
isDevVersion = isLeft parsedVersion
rawVersion :: T.Text
rawVersion = "versioned/" <> version
consoleVersion :: T.Text
consoleVersion = case parsedVersion of
Left _ -> rawVersion
Right v -> mkConsoleV v
mkConsoleV :: V.Version -> T.Text
mkConsoleV v = case getReleaseChannel v of
Nothing -> rawVersion
Just c -> T.pack $ "channel/" <> c <> "/" <> vMajMin
where
vMajMin = "v" <> show (v ^. V.major) <> "." <> show (v ^. V.minor)
getReleaseChannel :: V.Version -> Maybe String
getReleaseChannel sv = case sv ^. V.release of
[] -> Just "stable"
(mr:_) -> case getTextFromId mr of
Nothing -> Nothing
Just r -> if
| "alpha" `T.isPrefixOf` r -> Just "alpha"
| "beta" `T.isPrefixOf` r -> Just "beta"
| "rc" `T.isPrefixOf` r -> Just "rc"
| otherwise -> Nothing
getTextFromId :: V.Identifier -> Maybe T.Text
getTextFromId i = Just i ^? (toTextualM . V._Textual)
where
toTextualM _ Nothing = pure Nothing
toTextualM f (Just a) = f a