[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 @@ ...@@ -116,7 +116,9 @@
# compile # compile
echo "Bundling" echo "Bundling"
echo "{\"commit_hash\": \"$(git rev-parse HEAD)\"}" > .commit-hash.json
npm run bundle npm run bundle
rm .commit-hash.json
''; '';
}; };
test-ps = pkgs.writeShellApplication { test-ps = pkgs.writeShellApplication {
......
...@@ -11,6 +11,7 @@ import Data.Foldable (intercalate) ...@@ -11,6 +11,7 @@ import Data.Foldable (intercalate)
import Data.Map as Map import Data.Map as Map
import Data.Maybe (Maybe(..), maybe) import Data.Maybe (Maybe(..), maybe)
import Data.String.Regex as Regex import Data.String.Regex as Regex
import Data.Tuple (Tuple(..))
import Effect (Effect) import Effect (Effect)
import Effect.Aff (Aff, launchAff) import Effect.Aff (Aff, launchAff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
...@@ -36,6 +37,7 @@ import Gargantext.Context.Progress (asyncContext, asyncProgress) ...@@ -36,6 +37,7 @@ import Gargantext.Context.Progress (asyncContext, asyncProgress)
import Gargantext.Ends (Frontends, url) import Gargantext.Ends (Frontends, url)
import Gargantext.Hooks.Loader (useLoader) import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Hooks.UpdateEffect (useUpdateEffect1') import Gargantext.Hooks.UpdateEffect (useUpdateEffect1')
import Gargantext.Hooks.UseFeatureFlag as Feature
import Gargantext.Hooks.Version (Version, useVersion) import Gargantext.Hooks.Version (Version, useVersion)
import Gargantext.Routes as Routes import Gargantext.Routes as Routes
import Gargantext.Sessions (Session, sessionId) import Gargantext.Sessions (Session, sessionId)
...@@ -738,7 +740,9 @@ listNodeActionsLoadedCpt = here.component "listNodeActionsLoaded" cpt ...@@ -738,7 +740,9 @@ listNodeActionsLoadedCpt = here.component "listNodeActionsLoaded" cpt
type VersionComparatorProps = type VersionComparatorProps =
( clientVersion :: Version ( clientVersion :: Version
, clientCommit :: String
, remoteVersion :: Version , remoteVersion :: Version
, remoteCommit :: String
) )
versionComparator :: R2.Leaf VersionComparatorProps versionComparator :: R2.Leaf VersionComparatorProps
...@@ -747,39 +751,44 @@ versionComparator = R2.leaf versionComparatorCpt ...@@ -747,39 +751,44 @@ versionComparator = R2.leaf versionComparatorCpt
versionComparatorCpt :: R.Component VersionComparatorProps versionComparatorCpt :: R.Component VersionComparatorProps
versionComparatorCpt = here.component "versionComparator" cpt versionComparatorCpt = here.component "versionComparator" cpt
where where
cpt { clientVersion, remoteVersion } _ cpt { clientCommit, clientVersion, remoteVersion, remoteCommit } _ = do
| clientVersion == remoteVersion = pure $ let
B.caveat Tuple variant msg =
{ variant: Success if clientVersion == remoteVersion then Tuple Success "Versions match"
, className: "mainleaf__version-comparator" else Tuple Warning "Versions mismatch"
}
[ B.b_ "Versions match" commitEl hash =
, content clientVersion remoteVersion H.span {}
[ H.text " ("
, B.code_ hash
, H.text ")"
] ]
| otherwise = pure $
pure $
B.caveat B.caveat
{ variant: Warning { variant
, className: "mainleaf__version-comparator" , className: "mainleaf__version-comparator"
} }
[ B.b_ "Versions mismatch" [ B.b_ msg
, content clientVersion remoteVersion , H.ul {}
] [ H.li {}
content :: Version -> Version -> R.Element
content clientVersion remoteVersion =
H.ul
{}
[ H.li
{}
[ B.span_ "frontend: " [ B.span_ "frontend: "
, H.text $ nbsp 1 , H.text $ nbsp 1
, B.code_ clientVersion , B.code_ clientVersion
, Feature.hide
{ keys: [ "expert" ]
, render: commitEl clientCommit
}
] ]
, H.li , H.li {}
{}
[ B.span_ "backend: " [ B.span_ "backend: "
, H.text $ nbsp 1 , H.text $ nbsp 1
, B.code_ remoteVersion , B.code_ remoteVersion
, Feature.hide
{ keys: [ "expert" ]
, render: commitEl remoteCommit
}
]
] ]
] ]
......
'use strict'; 'use strict';
import pkg from '../../package.json'; 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 ...@@ -22,6 +22,7 @@ import Toestand as T
-- | (ie. Frontend Version) -- | (ie. Frontend Version)
foreign import version :: Version foreign import version :: Version
foreign import commitHash :: String
type Version = String type Version = String
...@@ -33,7 +34,9 @@ type R_Input = ...@@ -33,7 +34,9 @@ type R_Input =
type Output = Maybe R_Output type Output = Maybe R_Output
type R_Output = type R_Output =
{ clientVersion :: String { clientVersion :: String
, clientCommit :: String
, remoteVersion :: String , remoteVersion :: String
, remoteCommit :: String
} }
-- | Conditional Hooks checking release version match between client and remove -- | Conditional Hooks checking release version match between client and remove
...@@ -49,7 +52,9 @@ useVersion mInput = do ...@@ -49,7 +52,9 @@ useVersion mInput = do
Left err -> liftEffect $ log2 "[version] error" err Left err -> liftEffect $ log2 "[version] error" err
Right v -> liftEffect $ flip T.write_ mOutputBox $ Just Right v -> liftEffect $ flip T.write_ mOutputBox $ Just
{ clientVersion: version { clientVersion: version
, remoteVersion: v , clientCommit: commitHash
, remoteVersion: v.version
, remoteCommit: v.commitHash
} }
-- Hooks -- Hooks
useFirstEffect' $ case mInput of useFirstEffect' $ case mInput of
...@@ -58,5 +63,5 @@ useVersion mInput = do ...@@ -58,5 +63,5 @@ useVersion mInput = do
-- Output -- Output
pure mOutput pure mOutput
getBackendVersion :: Session -> REST.AffRESTError Version getBackendVersion :: Session -> REST.AffRESTError { version :: Version, commitHash :: String }
getBackendVersion (Session { backend }) = REST.get Nothing (toUrl backend "version") 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