2019-11-26 15:14:21 +03:00
|
|
|
{-# OPTIONS_GHC -fforce-recomp #-}
|
2018-07-03 18:34:25 +03:00
|
|
|
module Hasura.Server.Version
|
2018-07-27 12:34:50 +03:00
|
|
|
( currentVersion
|
2018-07-03 18:34:25 +03:00
|
|
|
, consoleVersion
|
2019-01-28 16:55:28 +03:00
|
|
|
, isDevVersion
|
2018-07-03 18:34:25 +03:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
2019-05-16 10:45:29 +03:00
|
|
|
import Control.Lens ((^.), (^?))
|
2019-05-29 14:51:09 +03:00
|
|
|
import Data.Either (isLeft)
|
2018-07-03 18:34:25 +03:00
|
|
|
|
|
|
|
import qualified Data.SemVer as V
|
|
|
|
import qualified Data.Text as T
|
|
|
|
|
|
|
|
import Hasura.Prelude
|
2019-04-11 07:11:48 +03:00
|
|
|
import Hasura.Server.Utils (getValFromEnvOrScript)
|
2018-07-03 18:34:25 +03:00
|
|
|
|
|
|
|
version :: T.Text
|
2019-05-16 10:45:29 +03:00
|
|
|
version = T.dropWhileEnd (== '\n')
|
|
|
|
$(getValFromEnvOrScript "VERSION" "../scripts/get-version.sh")
|
2018-07-03 18:34:25 +03:00
|
|
|
|
2019-05-16 10:45:29 +03:00
|
|
|
parsedVersion :: Either String V.Version
|
|
|
|
parsedVersion = V.fromText $ T.dropWhile (== 'v') version
|
2018-07-03 18:34:25 +03:00
|
|
|
|
2018-07-27 12:34:50 +03:00
|
|
|
currentVersion :: T.Text
|
|
|
|
currentVersion = version
|
2019-01-28 16:55:28 +03:00
|
|
|
|
|
|
|
isDevVersion :: Bool
|
2019-05-29 14:51:09 +03:00
|
|
|
isDevVersion = isLeft parsedVersion
|
2019-05-16 10:45:29 +03:00
|
|
|
|
|
|
|
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
|
2019-07-04 12:47:17 +03:00
|
|
|
[] -> Just "stable"
|
2019-05-16 10:45:29 +03:00
|
|
|
(mr:_) -> case getTextFromId mr of
|
|
|
|
Nothing -> Nothing
|
2019-07-04 12:47:17 +03:00
|
|
|
Just r -> if
|
|
|
|
| "alpha" `T.isPrefixOf` r -> Just "alpha"
|
|
|
|
| "beta" `T.isPrefixOf` r -> Just "beta"
|
|
|
|
| "rc" `T.isPrefixOf` r -> Just "rc"
|
|
|
|
| otherwise -> Nothing
|
2019-05-16 10:45:29 +03:00
|
|
|
|
|
|
|
getTextFromId :: V.Identifier -> Maybe T.Text
|
|
|
|
getTextFromId i = Just i ^? (toTextualM . V._Textual)
|
|
|
|
where
|
|
|
|
toTextualM _ Nothing = pure Nothing
|
|
|
|
toTextualM f (Just a) = f a
|