[node] add commit hash (with expert feature flag)

Related to
#747

Needs corresponding backend API changes.
parent 76a7b40f
Pipeline #7697 passed with stages
in 29 minutes and 46 seconds
......@@ -116,7 +116,9 @@
# compile
echo "Bundling"
echo "{\"commit_hash\": \"$(git rev-parse HEAD)\"}" > .commit-hash.json
npm run bundle
rm .commit-hash.json
'';
};
test-ps = pkgs.writeShellApplication {
......
......@@ -11,6 +11,7 @@ import Data.Foldable (intercalate)
import Data.Map as Map
import Data.Maybe (Maybe(..), maybe)
import Data.String.Regex as Regex
import Data.Tuple (Tuple(..))
import Effect (Effect)
import Effect.Aff (Aff, launchAff)
import Effect.Class (liftEffect)
......@@ -36,6 +37,7 @@ import Gargantext.Context.Progress (asyncContext, asyncProgress)
import Gargantext.Ends (Frontends, url)
import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Hooks.UpdateEffect (useUpdateEffect1')
import Gargantext.Hooks.UseFeatureFlag as Feature
import Gargantext.Hooks.Version (Version, useVersion)
import Gargantext.Routes as Routes
import Gargantext.Sessions (Session, sessionId)
......@@ -738,7 +740,9 @@ listNodeActionsLoadedCpt = here.component "listNodeActionsLoaded" cpt
type VersionComparatorProps =
( clientVersion :: Version
, clientCommit :: String
, remoteVersion :: Version
, remoteCommit :: String
)
versionComparator :: R2.Leaf VersionComparatorProps
......@@ -747,41 +751,46 @@ versionComparator = R2.leaf versionComparatorCpt
versionComparatorCpt :: R.Component VersionComparatorProps
versionComparatorCpt = here.component "versionComparator" cpt
where
cpt { clientVersion, remoteVersion } _
| clientVersion == remoteVersion = pure $
B.caveat
{ variant: Success
, className: "mainleaf__version-comparator"
}
[ B.b_ "Versions match"
, content clientVersion remoteVersion
]
| otherwise = pure $
B.caveat
{ variant: Warning
, className: "mainleaf__version-comparator"
}
[ B.b_ "Versions mismatch"
, content clientVersion remoteVersion
cpt { clientCommit, clientVersion, remoteVersion, remoteCommit } _ = do
let
Tuple variant msg =
if clientVersion == remoteVersion then Tuple Success "Versions match"
else Tuple Warning "Versions mismatch"
commitEl hash =
H.span {}
[ H.text " ("
, B.code_ hash
, H.text ")"
]
content :: Version -> Version -> R.Element
content clientVersion remoteVersion =
H.ul
{}
[ H.li
{}
[ B.span_ "frontend: "
, H.text $ nbsp 1
, B.code_ clientVersion
]
, H.li
{}
[ B.span_ "backend: "
, H.text $ nbsp 1
, B.code_ remoteVersion
]
]
pure $
B.caveat
{ variant
, className: "mainleaf__version-comparator"
}
[ B.b_ msg
, H.ul {}
[ H.li {}
[ B.span_ "frontend: "
, H.text $ nbsp 1
, B.code_ clientVersion
, Feature.hide
{ keys: [ "expert" ]
, render: commitEl clientCommit
}
]
, H.li {}
[ B.span_ "backend: "
, H.text $ nbsp 1
, B.code_ remoteVersion
, Feature.hide
{ keys: [ "expert" ]
, render: commitEl remoteCommit
}
]
]
]
-------------------------------------------------------
......
'use strict';
import pkg from '../../package.json';
import ch from '../../.commit-hash.json';
let version = pkg.version
let version = pkg.version;
let commitHash = ch.commit_hash;
export { version };
export { version, commitHash };
......@@ -22,6 +22,7 @@ import Toestand as T
-- | (ie. Frontend Version)
foreign import version :: Version
foreign import commitHash :: String
type Version = String
......@@ -33,7 +34,9 @@ type R_Input =
type Output = Maybe R_Output
type R_Output =
{ clientVersion :: String
, clientCommit :: String
, remoteVersion :: String
, remoteCommit :: String
}
-- | Conditional Hooks checking release version match between client and remove
......@@ -49,7 +52,9 @@ useVersion mInput = do
Left err -> liftEffect $ log2 "[version] error" err
Right v -> liftEffect $ flip T.write_ mOutputBox $ Just
{ clientVersion: version
, remoteVersion: v
, clientCommit: commitHash
, remoteVersion: v.version
, remoteCommit: v.commitHash
}
-- Hooks
useFirstEffect' $ case mInput of
......@@ -58,5 +63,5 @@ useVersion mInput = do
-- Output
pure mOutput
getBackendVersion :: Session -> REST.AffRESTError Version
getBackendVersion :: Session -> REST.AffRESTError { version :: Version, commitHash :: String }
getBackendVersion (Session { backend }) = REST.get Nothing (toUrl backend "version")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment