mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-20 01:07:18 +03:00
Add snapshot version support in daml-assistant. (#5410)
* Add snapshot version support in daml-assistant. changelog_begin - [DAML SDK] ``daml version`` can now list the available snapshot versions by passing the flag ``--snapshots=yes``. - [DAML SDK] ``daml install latest`` can now include the latest snapshot version by passing the flag ``--snapshots=yes``. changelog_end * Keep backward-compatible --all behavior * Fix comment * Delete spurious punctuation
This commit is contained in:
parent
2d1e22fe33
commit
36e8c8fccd
@ -131,6 +131,7 @@ autoInstall env@Env{..} = do
|
||||
let sdkVersion = fromJust envSdkVersion
|
||||
options = InstallOptions
|
||||
{ iTargetM = Nothing
|
||||
, iSnapshots = False
|
||||
, iQuiet = QuietInstall False
|
||||
, iAssistant = InstallAssistant Auto
|
||||
, iActivate = ActivateInstall False
|
||||
@ -174,12 +175,16 @@ handleCommand env@Env{..} logger command = do
|
||||
]
|
||||
|
||||
runCommand :: Env -> Command -> IO ()
|
||||
runCommand env@Env{..} = \case
|
||||
runCommand env@Env{..} = \case
|
||||
Builtin (Version VersionOptions{..}) -> do
|
||||
installedVersionsE <- tryAssistant $ getInstalledSdkVersions envDamlPath
|
||||
availableVersionsE <- tryAssistant $ refreshAvailableSdkVersions envDamlPath
|
||||
defaultVersionM <- tryAssistantM $ getDefaultSdkVersion envDamlPath
|
||||
projectVersionM <- mapM getSdkVersionFromProjectPath envProjectPath
|
||||
snapshotVersionsE <- tryAssistant $
|
||||
if vSnapshots
|
||||
then getAvailableSdkSnapshotVersions
|
||||
else pure []
|
||||
|
||||
let asstVersion = unwrapDamlAssistantSdkVersion <$> envDamlAssistantSdkVersion
|
||||
envVersions = catMaybes
|
||||
@ -223,6 +228,7 @@ runCommand env@Env{..} = \case
|
||||
[ envVersions
|
||||
, fromRight [] installedVersionsE
|
||||
, if vAll then fromRight [] availableVersionsE else []
|
||||
, fromRight [] snapshotVersionsE
|
||||
]
|
||||
versionTable = [ (versionToText v, versionAttrs v) | v <- versions ]
|
||||
versionWidth = maximum (1 : map (T.length . fst) versionTable)
|
||||
|
@ -104,11 +104,13 @@ commandParser cmds | (hidden, visible) <- partition isHidden cmds = asum
|
||||
versionParser :: Parser VersionOptions
|
||||
versionParser = VersionOptions
|
||||
<$> flagYesNoAuto "all" False "Display all available versions." idm
|
||||
<*> flagYesNoAuto "snapshots" False "Display all available snapshot versions." idm
|
||||
<*> flagYesNoAuto "assistant" False "Display DAML assistant version." idm
|
||||
|
||||
installParser :: Parser InstallOptions
|
||||
installParser = InstallOptions
|
||||
<$> optional (RawInstallTarget <$> argument str (metavar "TARGET" <> completeWith ["latest"] <> help "The SDK version to install. Use 'latest' to download and install the latest stable SDK version available. Run 'daml install' to see the full set of options."))
|
||||
<*> flagYesNoAuto "snapshots" False "Pick up snapshot versions with daml install latest." idm
|
||||
<*> (InstallAssistant <$> flagYesNoAuto' "install-assistant" "Install associated DAML assistant version. Can be set to \"yes\" (always installs), \"no\" (never installs), or \"auto\" (installs if newer). Default is \"auto\"." idm)
|
||||
<*> iflag ActivateInstall "activate" hidden "Activate installed version of daml"
|
||||
<*> iflag ForceInstall "force" (short 'f') "Overwrite existing installation"
|
||||
|
@ -17,6 +17,7 @@ import DA.Daml.Assistant.Util
|
||||
import qualified DA.Daml.Assistant.Install.Github as Github
|
||||
import DA.Daml.Assistant.Install.Path
|
||||
import DA.Daml.Assistant.Install.Completion
|
||||
import DA.Daml.Assistant.Version (getLatestSdkSnapshotVersion)
|
||||
import DA.Daml.Project.Consts
|
||||
import DA.Daml.Project.Config
|
||||
import Safe
|
||||
@ -355,10 +356,14 @@ versionInstall env@InstallEnv{..} version = do
|
||||
"Activating assistant version " <> versionToString version
|
||||
activateDaml env (SdkPath path)
|
||||
|
||||
-- | Install the latest stable version of the SDK.
|
||||
-- | Install the latest version of the SDK.
|
||||
latestInstall :: InstallEnv -> IO ()
|
||||
latestInstall env = do
|
||||
version <- getLatestVersion
|
||||
latestInstall env@InstallEnv{..} = do
|
||||
version1 <- getLatestVersion
|
||||
version2M <- if iSnapshots options
|
||||
then getLatestSdkSnapshotVersion
|
||||
else pure Nothing
|
||||
let version = maybe version1 (max version1) version2M
|
||||
versionInstall env version
|
||||
|
||||
-- | Get the latest stable version.
|
||||
|
@ -76,13 +76,15 @@ newtype UserCommandArgs = UserCommandArgs
|
||||
|
||||
-- | Command-line options for daml version command.
|
||||
data VersionOptions = VersionOptions
|
||||
{ vAll :: Bool -- ^ list all available versions
|
||||
{ vAll :: Bool -- ^ show all versions (stable + snapshot)
|
||||
, vSnapshots :: Bool -- ^ show all snapshot versions
|
||||
, vAssistant :: Bool -- ^ show assistant version
|
||||
} deriving (Eq, Show)
|
||||
|
||||
-- | Command-line options for daml install command.
|
||||
data InstallOptions = InstallOptions
|
||||
{ iTargetM :: Maybe RawInstallTarget -- ^ version to install
|
||||
, iSnapshots :: Bool -- ^ include snapshots for latest target
|
||||
, iAssistant :: InstallAssistant -- ^ install the assistant
|
||||
, iActivate :: ActivateInstall -- ^ install the assistant if true (deprecated, delete with 0.14.x)
|
||||
, iForce :: ForceInstall -- ^ force reinstall if already installed
|
||||
|
@ -12,6 +12,8 @@ module DA.Daml.Assistant.Version
|
||||
, getAvailableSdkVersionsCached
|
||||
, refreshAvailableSdkVersions
|
||||
, getLatestSdkVersionCached
|
||||
, getAvailableSdkSnapshotVersions
|
||||
, getLatestSdkSnapshotVersion
|
||||
) where
|
||||
|
||||
import DA.Daml.Assistant.Types
|
||||
@ -109,7 +111,7 @@ getDefaultSdkVersion damlPath = do
|
||||
required "There are no installed SDK versions." $
|
||||
maximumMay installedVersions
|
||||
|
||||
-- | Get the list of available versions afresh. This will fetch.
|
||||
-- | Get the list of available versions afresh. This will fetch
|
||||
-- https://docs.daml.com/versions.json and parse the obtained list
|
||||
-- of versions.
|
||||
getAvailableSdkVersions :: IO [SdkVersion]
|
||||
@ -130,6 +132,27 @@ getAvailableSdkVersions = wrapErr "Fetching list of available SDK versions" $ do
|
||||
|
||||
pure . sort $ mapMaybe (eitherToMaybe . parseVersion) (M.keys versionsMap)
|
||||
|
||||
-- | Get the list of available snapshot versions. This will fetch
|
||||
-- https://docs.daml.com/snapshots.json and parse the obtained list
|
||||
-- of versions.
|
||||
getAvailableSdkSnapshotVersions :: IO [SdkVersion]
|
||||
getAvailableSdkSnapshotVersions = wrapErr "Fetching list of available SDK snapshot versions" $ do
|
||||
response <- requiredAny "HTTP connection to docs.daml.com failed" $ do
|
||||
request <- parseRequest "GET http://docs.daml.com/snapshots.json"
|
||||
httpBS request { responseTimeout = responseTimeoutMicro 2000000 }
|
||||
|
||||
when (getResponseStatusCode response /= 200) $ do
|
||||
throwIO $ assistantErrorBecause
|
||||
"Fetching list of available SDK snapshot versions from docs.daml.com failed"
|
||||
(pack . show $ getResponseStatus response)
|
||||
|
||||
versionsMap :: M.HashMap Text Text <-
|
||||
fromRightM
|
||||
(throwIO . assistantErrorBecause "Snapshot versions list from docs.daml.com does not contain valid JSON" . pack)
|
||||
(eitherDecodeStrict' (getResponseBody response))
|
||||
|
||||
pure . sort $ mapMaybe (eitherToMaybe . parseVersion) (M.keys versionsMap)
|
||||
|
||||
-- | Same as getAvailableSdkVersions, but writes result to cache.
|
||||
refreshAvailableSdkVersions :: DamlPath -> IO [SdkVersion]
|
||||
refreshAvailableSdkVersions damlPath = do
|
||||
@ -150,3 +173,11 @@ getLatestSdkVersionCached damlPath = do
|
||||
pure $ do
|
||||
versions <- eitherToMaybe versionsE
|
||||
maximumMay versions
|
||||
|
||||
-- | Get the latest snapshot SDK version.
|
||||
getLatestSdkSnapshotVersion :: IO (Maybe SdkVersion)
|
||||
getLatestSdkSnapshotVersion = do
|
||||
versionsE <- tryAssistant getAvailableSdkSnapshotVersions
|
||||
pure $ do
|
||||
versions <- eitherToMaybe versionsE
|
||||
maximumMay versions
|
||||
|
@ -350,6 +350,7 @@ testInstall = Tasty.testGroup "DA.Daml.Assistant.Install"
|
||||
let damlPath = DamlPath (base </> "daml")
|
||||
options = InstallOptions
|
||||
{ iTargetM = Just (RawInstallTarget "source.tar.gz")
|
||||
, iSnapshots = False
|
||||
, iAssistant = InstallAssistant Yes
|
||||
, iActivate = ActivateInstall True
|
||||
, iQuiet = QuietInstall True
|
||||
@ -385,6 +386,7 @@ testInstallUnix = Tasty.testGroup "unix-specific tests"
|
||||
let damlPath = DamlPath (base </> "daml")
|
||||
options = InstallOptions
|
||||
{ iTargetM = Just (RawInstallTarget "source.tar.gz")
|
||||
, iSnapshots = False
|
||||
, iAssistant = InstallAssistant Yes
|
||||
, iActivate = ActivateInstall True
|
||||
, iQuiet = QuietInstall True
|
||||
@ -415,6 +417,7 @@ testInstallUnix = Tasty.testGroup "unix-specific tests"
|
||||
let damlPath = DamlPath (base </> "daml")
|
||||
options = InstallOptions
|
||||
{ iTargetM = Just (RawInstallTarget "source.tar.gz")
|
||||
, iSnapshots = False
|
||||
, iAssistant = InstallAssistant No
|
||||
, iActivate = ActivateInstall False
|
||||
, iQuiet = QuietInstall True
|
||||
@ -445,6 +448,7 @@ testInstallUnix = Tasty.testGroup "unix-specific tests"
|
||||
let damlPath = DamlPath (base </> "daml")
|
||||
options = InstallOptions
|
||||
{ iTargetM = Just (RawInstallTarget "source.tar.gz")
|
||||
, iSnapshots = False
|
||||
, iAssistant = InstallAssistant No
|
||||
, iActivate = ActivateInstall False
|
||||
, iQuiet = QuietInstall True
|
||||
|
Loading…
Reference in New Issue
Block a user