mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 17:31:56 +03:00
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:
parent
4ad498cd22
commit
99f7a0fb87
@ -1077,6 +1077,7 @@ test-suite graphql-engine-tests
|
|||||||
Hasura.Server.MigrateSuite
|
Hasura.Server.MigrateSuite
|
||||||
Hasura.Server.Migrate.VersionSpec
|
Hasura.Server.Migrate.VersionSpec
|
||||||
Hasura.Server.TelemetrySpec
|
Hasura.Server.TelemetrySpec
|
||||||
|
Hasura.Server.VersionSpec
|
||||||
Hasura.Server.InitSpec
|
Hasura.Server.InitSpec
|
||||||
Hasura.Server.Init.ArgSpec
|
Hasura.Server.Init.ArgSpec
|
||||||
Hasura.SessionSpec
|
Hasura.SessionSpec
|
||||||
|
@ -294,3 +294,4 @@ versionToTopic :: Version -> Topic
|
|||||||
versionToTopic = \case
|
versionToTopic = \case
|
||||||
VersionDev _ -> Topic "server_metrics_v2_test"
|
VersionDev _ -> Topic "server_metrics_v2_test"
|
||||||
VersionRelease _ -> Topic "server_metrics_v2"
|
VersionRelease _ -> Topic "server_metrics_v2"
|
||||||
|
VersionCE _ -> Topic "server_metrics_v2"
|
||||||
|
@ -4,6 +4,7 @@ module Hasura.Server.Version
|
|||||||
( Version (..),
|
( Version (..),
|
||||||
currentVersion,
|
currentVersion,
|
||||||
consoleAssetsVersion,
|
consoleAssetsVersion,
|
||||||
|
versionToAssetsVersion,
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
@ -20,16 +21,21 @@ import Language.Haskell.TH.Syntax
|
|||||||
import Text.Regex.TDFA ((=~~))
|
import Text.Regex.TDFA ((=~~))
|
||||||
|
|
||||||
data Version
|
data Version
|
||||||
= VersionDev !Text
|
= VersionDev Text
|
||||||
| VersionRelease !V.Version
|
| VersionRelease V.Version
|
||||||
|
| VersionCE Text
|
||||||
deriving (Show, Eq)
|
deriving (Show, Eq)
|
||||||
|
|
||||||
instance ToText Version where
|
instance ToText Version where
|
||||||
toText = \case
|
toText = \case
|
||||||
VersionDev txt -> txt
|
VersionDev txt -> txt
|
||||||
VersionRelease version -> "v" <> V.toText version
|
VersionRelease version -> "v" <> V.toText version
|
||||||
|
VersionCE txt -> txt
|
||||||
|
|
||||||
instance FromText Version where
|
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
|
fromText txt = case V.fromText $ T.dropWhile (== 'v') txt of
|
||||||
Left _ -> VersionDev txt
|
Left _ -> VersionDev txt
|
||||||
Right version -> VersionRelease version
|
Right version -> VersionRelease version
|
||||||
@ -61,15 +67,15 @@ currentVersion =
|
|||||||
runIO (readFile versionFileName `onException` error noFileErr) >>= stringE
|
runIO (readFile versionFileName `onException` error noFileErr) >>= stringE
|
||||||
)
|
)
|
||||||
|
|
||||||
-- | A version-based string used to form the CDN URL for fetching console assets.
|
versionToAssetsVersion :: Version -> Text
|
||||||
consoleAssetsVersion :: Text
|
versionToAssetsVersion = \case
|
||||||
consoleAssetsVersion = case currentVersion of
|
|
||||||
VersionDev txt -> "versioned/" <> txt
|
VersionDev txt -> "versioned/" <> txt
|
||||||
VersionRelease v -> case getReleaseChannel v of
|
VersionRelease v -> case getReleaseChannel v of
|
||||||
Nothing -> "versioned/" <> vMajMin
|
Nothing -> "versioned/" <> vMajMin
|
||||||
Just c -> "channel/" <> c <> "/" <> vMajMin
|
Just c -> "channel/" <> c <> "/" <> vMajMin
|
||||||
where
|
where
|
||||||
vMajMin = T.pack ("v" <> show (v ^. V.major) <> "." <> show (v ^. V.minor))
|
vMajMin = T.pack ("v" <> show (v ^. V.major) <> "." <> show (v ^. V.minor))
|
||||||
|
VersionCE txt -> "channel/versioned/" <> txt
|
||||||
where
|
where
|
||||||
getReleaseChannel :: V.Version -> Maybe Text
|
getReleaseChannel :: V.Version -> Maybe Text
|
||||||
getReleaseChannel sv = case sv ^. V.release of
|
getReleaseChannel sv = case sv ^. V.release of
|
||||||
@ -89,3 +95,7 @@ consoleAssetsVersion = case currentVersion of
|
|||||||
where
|
where
|
||||||
toTextualM _ Nothing = pure Nothing
|
toTextualM _ Nothing = pure Nothing
|
||||||
toTextualM f (Just a) = f a
|
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
|
||||||
|
41
server/src-test/Hasura/Server/VersionSpec.hs
Normal file
41
server/src-test/Hasura/Server/VersionSpec.hs
Normal 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
|
Loading…
Reference in New Issue
Block a user