-
Notifications
You must be signed in to change notification settings - Fork 27
Adding zpm "ci" command to install from a lock file #1080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
26c1f47
dedd323
6a759be
90daa5e
15eed15
d5bdbc1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,12 +69,12 @@ ClassMethod CreateLockFileForModule( | |
| $$$ThrowOnError(lockFile.Dependencies.SetAt(dependencyVal, mod.Name)) | ||
|
|
||
| // Add the dependency's repository to the lock file | ||
| do AddRepositoryToLockFile(.lockFile, mod.Repository, verbose) | ||
| do ..AddRepositoryToLockFile(.lockFile, mod.Repository, verbose) | ||
| } | ||
| // Add repository for base module if not already added by a dependency | ||
| // Skip undefined repositories as that means the module was installed via the zpm "load" command | ||
| if (module.Repository '= "") { | ||
| do AddRepositoryToLockFile(.lockFile, module.Repository, verbose) | ||
| do ..AddRepositoryToLockFile(.lockFile, module.Repository, verbose) | ||
| } | ||
|
|
||
| $$$ThrowOnError(lockFile.%JSONExportToStream(.lockFileJSON, "LockFileMapping")) | ||
|
|
@@ -116,4 +116,88 @@ ClassMethod GetRepo(repoName As %String) As %IPM.Repo.Definition [ Internal ] | |
| } | ||
| } | ||
|
|
||
| ClassMethod InstallFromLockFile( | ||
| directory As %String, | ||
| ByRef params) | ||
| { | ||
| set verbose = $get(params("Verbose"), 0) | ||
|
|
||
| set lockFilePath = ##class(%File).NormalizeFilename("module-lock.json", directory) | ||
| set lockFileJSON = ##class(%DynamicObject).%FromJSONFile(lockFilePath) | ||
|
|
||
| set repositories = lockFileJSON.%Get("repositories", {}) | ||
| set dependencies = lockFileJSON.%Get("dependencies", {}) | ||
|
|
||
| // Install repositories (if they don't already exist) | ||
| set repoIter = repositories.%GetIterator() | ||
| while repoIter.%GetNext(.repoName, .repoVals) { | ||
| if ##class(%IPM.Repo.Definition).ServerDefinitionKeyExists(repoName) { | ||
| if (verbose) { | ||
| write !, "Repo: "_repoName_" already exists, skipping creating new one from lock file" | ||
| } | ||
| continue | ||
| } | ||
| elseif (verbose) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: change to one line like |
||
| write !, "Creating repo: "_repoName_" from lock file" | ||
| } | ||
| do ##class(%IPM.Repo.Definition).CollectServerTypes(.types) | ||
| set repoClass = types(repoVals.type) | ||
| set repoVals.name = repoName | ||
| do $classmethod(repoClass, "LockFileValuesToModifiers", repoVals, .modifiers) | ||
| $$$ThrowOnError($classmethod(repoClass,"Configure",0,.modifiers,.tData,repoClass)) | ||
| } | ||
|
|
||
| // Install modules (even if they already exist) | ||
| do ..GetOrderedDependenciesList(dependencies, .orderedDependenciesList) | ||
| set depName = "" | ||
| for i=1:1:$listlength(orderedDependenciesList) { | ||
| set depName = $list(orderedDependenciesList, i) | ||
| set depVals = dependencies.%Get(depName) | ||
|
|
||
| set version = depVals.version | ||
| set repository = depVals.repository | ||
|
|
||
| // Call CleanInstall() on dependency modules but set flag "LockFileInstallStarted" so we don't try installing from the dependency module's lock file | ||
| set commandInfo = "ci" | ||
| set commandInfo("data", "Verbose") = verbose | ||
| set commandInfo("parameters","module") = repository_"/"_depName | ||
| set commandInfo("parameters", "version") = version | ||
| set commandInfo("data", "LockFileInstallStarted") = 1 | ||
| do ##class(%IPM.Main).CleanInstall(.commandInfo) | ||
| } | ||
| } | ||
|
|
||
| /// The dependencies list in a lock file is listed alphabetically. | ||
| /// This method compiles the dependencies and creates an ordered list such that no module is listed | ||
| /// before one of its dependencies. Can then trace the list this outputs and install in order | ||
| ClassMethod GetOrderedDependenciesList( | ||
| dependencies As %DynamicObject, | ||
| ByRef orderedDependenciesList As %List = "") [ Internal ] | ||
| { | ||
| set depIter = dependencies.%GetIterator() | ||
| while depIter.%GetNext(.depName, .depVals) { | ||
| do ..AddToOrderedDependenciesList(depName, dependencies, .orderedDependenciesList) | ||
| } | ||
| } | ||
|
|
||
| /// For a dependency, recursively adds all dependencies to the ordered list, followed by this dependency | ||
| ClassMethod AddToOrderedDependenciesList( | ||
| dependencyName As %String, | ||
| dependencies As %DynamicObject, | ||
| ByRef orderedDependenciesList As %List) [ Internal, Private ] | ||
| { | ||
| set depVals = dependencies.%Get(dependencyName) | ||
| set transientDeps = depVals.%Get("dependencies", {}) | ||
| set transientIter = transientDeps.%GetIterator() | ||
| while transientIter.%GetNext(.transDepName) { | ||
| // If dependency hasn't been installed yet, then recursively run this method on it | ||
| if '$listfind(orderedDependenciesList, transDepName) { | ||
| do ..AddToOrderedDependenciesList(transDepName, dependencies, .orderedDependenciesList) | ||
| } | ||
| } | ||
| if '$listfind(orderedDependenciesList, dependencyName) { | ||
| set orderedDependenciesList = orderedDependenciesList _ $listbuild(dependencyName) | ||
| } | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -791,6 +791,25 @@ generate /my/path -export 00000,PacketName2,IgnorePacket2^00000,PacketName3,Igno | |
| <example description="Show details of history item with ID 3 and information for each undergone lifecyle phase">history details 3 -phases</example> | ||
| </command> | ||
|
|
||
| <command name="ci"> | ||
| <summary>Installs a module from a lock file</summary> | ||
| <description> | ||
| Installs a module from its lock file. Will first install all listed repositories followed by dependency modules and then the base module. | ||
| </description> | ||
|
|
||
| <!-- Examples --> | ||
| <example description="Reads from the module-lock.json defined for mymodule and installs the repositories, module, and dependencies"> | ||
| ci mymodule 3.0.0 | ||
| </example> | ||
|
|
||
| <!-- Parameters --> | ||
| <parameter name="module" required="true" description="Name of module on which to perform update actions" /> | ||
| <parameter name="version" description="Version (or version expression) of module to install; defaults to the latest available if unspecified." /> | ||
|
|
||
| <!-- Modifiers --> | ||
| <modifier name="verbose" aliases="v" dataAlias="Verbose" dataValue="1" description="Produces verbose output from the command." /> | ||
| </command> | ||
|
|
||
| </commands> | ||
| } | ||
|
|
||
|
|
@@ -1031,8 +1050,10 @@ ClassMethod ShellInternal( | |
| do ..ModuleVersion(.tCommandInfo) | ||
| } elseif (tCommandInfo = "information") { | ||
| do ..Information(.tCommandInfo) | ||
| } elseif (tCommandInfo = "history") { | ||
| do ..History(.tCommandInfo) | ||
| } elseif (tCommandInfo = "history") { | ||
| do ..History(.tCommandInfo) | ||
| } elseif (tCommandInfo = "ci") { | ||
| do ..CleanInstall(.tCommandInfo) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a bit confusing to me to have "ci" stand for "CleanInstall", since 1) CI=continuous integration, and 2) it doesn't mention the lock file like "LockFileInstall" would for example. But taking a step back, what's the benefit of having a new command versus using a flag on |
||
| } | ||
| } catch pException { | ||
| if (pException.Code = $$$ERCTRLC) { | ||
|
|
@@ -2396,12 +2417,11 @@ ClassMethod Install( | |
| $$$ThrowStatus($$$ERROR($$$GeneralError, "Deployed package '" _ tModuleName _ "' " _ tResult.VersionString _ " not supported on this platform " _ platformVersion _ ".")) | ||
| } | ||
| } | ||
| $$$ThrowOnError(log.SetSource(tResult.ServerName)) | ||
| $$$ThrowOnError(log.SetVersion(tResult.Version)) | ||
| $$$ThrowOnError(log.SetSource(tResult.ServerName)) | ||
| $$$ThrowOnError(log.SetVersion(tResult.Version)) | ||
| $$$ThrowOnError(##class(%IPM.Utils.Module).LoadQualifiedReference(tResult, .tParams, , log)) | ||
| } | ||
| } else { | ||
| set tPrefix = "" | ||
| if (tModuleName '= "") { | ||
| if (tVersion '= "") { | ||
| $$$ThrowStatus($$$ERROR($$$GeneralError, tModuleName_" "_tVersion_" not found in any repository.")) | ||
|
|
@@ -2415,10 +2435,32 @@ ClassMethod Install( | |
| } | ||
| } | ||
| } catch ex { | ||
| $$$ThrowOnError(log.Finalize(ex.AsStatus(), devMode)) | ||
| throw ex | ||
| } | ||
| $$$ThrowOnError(log.Finalize($$$OK, devMode)) | ||
| $$$ThrowOnError(log.Finalize(ex.AsStatus(), devMode)) | ||
| throw ex | ||
| } | ||
| $$$ThrowOnError(log.Finalize($$$OK, devMode)) | ||
| } | ||
|
|
||
| ClassMethod CleanInstall(ByRef commandInfo) [ Internal ] | ||
| { | ||
| set moduleName = $get(commandInfo("parameters","module")) | ||
| set version = $get(commandInfo("parameters","version")) | ||
| set verbose = $get(commandInfo("data","Verbose")) | ||
| set log = ##class(%IPM.General.HistoryTemp).CleanInstallInit(moduleName) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also add a test to check that the history log is being populated correctly (see Test.PM.Integration.History) |
||
|
|
||
| // TODO: Add "path"? (see Update() for more info of calling install v load) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When is this todo being done or removed? |
||
|
|
||
| if verbose { | ||
| write !, "Going to run a clean install on "_moduleName | ||
| } | ||
|
|
||
| // Indicating to commandInfo that this is a clean install command, not an install or load command. commandInfo will be passed to either Install() or Load() to continue performing the update. | ||
| set commandInfo("data","cmd") = "ci" | ||
| set commandInfo("data","CleanInstall") = 1 | ||
| set log = ##class(%IPM.General.HistoryTemp).UpdateInit(moduleName) | ||
|
|
||
| // Forward execution to install | ||
| do ..Install(.commandInfo, log) | ||
| } | ||
|
|
||
| ClassMethod Reinstall(ByRef pCommandInfo) [ Internal ] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll need to pull from main and move this entry to 0.10.7