Amend console assets versioning scheme for CE

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5628
GitOrigin-RevId: 550cc987a7142f46f4c380d8217fe6ad8ce53fe9
This commit is contained in:
Auke Booij 2022-08-26 14:38:09 +02:00 committed by hasura-bot
parent 4ad498cd22
commit 99f7a0fb87
4 changed files with 58 additions and 5 deletions

View File

@ -1077,6 +1077,7 @@ test-suite graphql-engine-tests
Hasura.Server.MigrateSuite
Hasura.Server.Migrate.VersionSpec
Hasura.Server.TelemetrySpec
Hasura.Server.VersionSpec
Hasura.Server.InitSpec
Hasura.Server.Init.ArgSpec
Hasura.SessionSpec

View File

@ -294,3 +294,4 @@ versionToTopic :: Version -> Topic
versionToTopic = \case
VersionDev _ -> Topic "server_metrics_v2_test"
VersionRelease _ -> Topic "server_metrics_v2"
VersionCE _ -> Topic "server_metrics_v2"

View File

@ -4,6 +4,7 @@ module Hasura.Server.Version
( Version (..),
currentVersion,
consoleAssetsVersion,
versionToAssetsVersion,
)
where
@ -20,16 +21,21 @@ import Language.Haskell.TH.Syntax
import Text.Regex.TDFA ((=~~))
data Version
= VersionDev !Text
| VersionRelease !V.Version
= VersionDev Text
| VersionRelease V.Version
| VersionCE Text
deriving (Show, Eq)
instance ToText Version where
toText = \case
VersionDev txt -> txt
VersionRelease version -> "v" <> V.toText version
VersionCE txt -> txt
instance FromText Version where
-- Ensure that a -ce suffix is *not* interpreted as the release type of a
-- Data.SemVer-style semantic version
fromText txt | T.takeEnd 3 txt == "-ce" = VersionCE txt
fromText txt = case V.fromText $ T.dropWhile (== 'v') txt of
Left _ -> VersionDev txt
Right version -> VersionRelease version
@ -61,15 +67,15 @@ currentVersion =
runIO (readFile versionFileName `onException` error noFileErr) >>= stringE
)
-- | A version-based string used to form the CDN URL for fetching console assets.
consoleAssetsVersion :: Text
consoleAssetsVersion = case currentVersion of
versionToAssetsVersion :: Version -> Text
versionToAssetsVersion = \case
VersionDev txt -> "versioned/" <> txt
VersionRelease v -> case getReleaseChannel v of
Nothing -> "versioned/" <> vMajMin
Just c -> "channel/" <> c <> "/" <> vMajMin
where
vMajMin = T.pack ("v" <> show (v ^. V.major) <> "." <> show (v ^. V.minor))
VersionCE txt -> "channel/versioned/" <> txt
where
getReleaseChannel :: V.Version -> Maybe Text
getReleaseChannel sv = case sv ^. V.release of
@ -89,3 +95,7 @@ consoleAssetsVersion = case currentVersion of
where
toTextualM _ Nothing = pure Nothing
toTextualM f (Just a) = f a
-- | A version-based string used to form the CDN URL for fetching console assets.
consoleAssetsVersion :: Text
consoleAssetsVersion = versionToAssetsVersion currentVersion

View File

@ -0,0 +1,41 @@
module Hasura.Server.VersionSpec (spec) where
import Data.Text qualified as T
import Data.Text.Conversions (FromText (..))
import Hasura.Prelude
import Hasura.Server.Version
import Test.Hspec
versions :: [(Text, Text)]
versions =
[ ("v1.2.4", "channel/stable/v1.2"),
("2.3.4", "channel/stable/v2.3"),
("v1.0.0-alpha45", "channel/alpha/v1.0"),
("v1.0.0-beta.01", "channel/beta/v1.0"),
("v2.3.1-rc.11", "channel/rc/v2.3"),
("v1.2.0-rj.1", "channel/rj/v1.2"),
-- Apparently this one was generated in a different way?
-- ("v2.0.0-pro.9", "channel/stable/v2.0"),
("v2.0.0-alpha.pro.9", "channel/alpha/v2.0"),
("v2.12.0-ce", "channel/versioned/v2.12.0-ce"),
("v2.12.1-ce", "channel/versioned/v2.12.1-ce"),
("v2.12.0-beta.1-ce", "channel/versioned/v2.12.0-beta.1-ce"),
("v2.12.0-beta.2-ce", "channel/versioned/v2.12.0-beta.2-ce"),
("v2.12.0", "channel/stable/v2.12"),
("v2.12.1", "channel/stable/v2.12"),
("v2.12.0-beta.1", "channel/beta/v2.12"),
("v2.12.0-beta.2", "channel/beta/v2.12"),
("v2.12.0-alpha.1", "channel/alpha/v2.12"),
("v2.12.0-alpha.2", "channel/alpha/v2.12")
-- The Haskell server does not seem to be responsible for generating version strings for Cloud
-- ("v2.12.0-cloud.1", "channel/versioned/v2.12.0-cloud.1")
-- ("v2.0.0-cloud.9", "channel/stable/v2.0"),
-- ("v2.0.0-alpha.cloud.9", "channel/alpha/v2.0"),
]
spec :: Spec
spec = describe "console assets version" do
parallel $
for_ versions \(input, output) ->
it ("versionToAssetsVersion returns expected output for " <> T.unpack input) $
versionToAssetsVersion (fromText input) `shouldBe` output