-
Notifications
You must be signed in to change notification settings - Fork 24
Package Manager should support creation of a lock file #963
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
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
f52b402
Initial commit. Not ready for a PR yet but should be in source contro…
f338bd6
Splitting up work so that this is only creating a lock file + adding …
375456b
Adding changelog
2ba5e1b
Updating test lock files to be multi-line for better json readability
c530c4c
Printing out lock file values to see why tests are failing
5ef88ed
Attempt #2 to print out testing values
e9f5109
Attempt #3
f7ef50e
Delete all repos prior to lock file tests to avoid conflicts
80a2015
Adding repository value for the base module on the top level of the l…
a0eb905
Refactoring to use %JSON.Adaptor for exporting to and creating lock file
dc4ee30
Adding alias, maxlens to string properties
6db5567
Adding multiple repo types test
b837b48
Using XData blocks instead of new repo class + adding data types
8522c6d
Adding create lock file to load and update in addition to install
8f1f497
Uninstalling modules in OnAfterOneTest() instead of in each individua…
6f586e4
Updating changelog to pick up changes from main
0c53936
middle update
c2f5185
Re-updating changelog
4462a47
Removing "enabled" and "deploymentEnabled" fields from repository def…
22ee017
Merge remote-tracking branch 'origin/main' into lock-file
49fc412
Moving CreateLockFileForModule() call to where dependency graph was c…
6b738c7
Merge remote-tracking branch 'origin/main' into lock-file
170b6c7
Using moniker instead of repeated definition of LockFileTypeGet()
db18027
More descriptive naming of lock file test modules
9ec3d48
Adding test class with updated module names
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Class %IPM.DataType.VersionString Extends %Library.String [ ClassType = datatype ] | ||
| { | ||
|
|
||
| /// The maximum number of characters the string can contain. | ||
| Parameter MAXLEN As INTEGER = 100; | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| /// This class is used for interacting with a lock file for a given module | ||
| /// Covers functionality for both creating a lock file and installing from a lock file | ||
| Class %IPM.General.LockFile Extends (%RegisteredObject, %JSON.Adaptor) | ||
| { | ||
|
|
||
| /// Name of the JSON lock file | ||
| Parameter LockFileName As String = "module-lock.json"; | ||
|
|
||
| /// Name of the module the lock file is for | ||
| Property ModuleName As %IPM.DataType.ModuleName(%JSONFIELDNAME = "name") [ Required ]; | ||
isc-jlechtne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// Version string of the module | ||
| Property VersionString As %IPM.DataType.VersionString(%JSONFIELDNAME = "version") [ Required ]; | ||
|
|
||
| /// Repository where the base module used to create the lock file comes from | ||
| Property Repository As %IPM.DataType.RepoName(%JSONFIELDNAME = "repository"); | ||
|
|
||
| /// Version of the lock file schema used in creating the lock file | ||
| Property LockFileVersion As %String(%JSONFIELDNAME = "lockFileVersion", MAXLEN = "") [ InitialExpression = "1" ]; | ||
isc-jlechtne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// Array of repository definitions from where at least one of the base module or dependency comes from | ||
| Property Repositories As array Of %IPM.Repo.Definition(%JSONFIELDNAME = "repositories"); | ||
|
|
||
| /// Array of dependency modules required by the module. Ordered by least dependent to most dependent | ||
| Property Dependencies As array Of %IPM.General.LockFile.Dependency(%JSONFIELDNAME = "dependencies"); | ||
isc-jlechtne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// When given the name of a module, creates the lock file for it and saves it to module.Root_..#LockFileName | ||
| /// flatDependencyList is the output from ##class(%IPM.Utils.Module).GetFlatDependencyListFromInvertedDependencyGraph() | ||
| ClassMethod CreateLockFileForModule( | ||
isc-jlechtne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| module As %IPM.Storage.Module, | ||
| ByRef flatDependencyList, | ||
| ByRef params) | ||
isc-jlechtne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| set verbose = $get(params("Verbose"), 0) | ||
| if (verbose) { | ||
| write !, "Creating lock file for module "_module.DisplayName | ||
| } | ||
|
|
||
| // Create lock file object and set values for the base module | ||
| set lockFile = ##class(%IPM.General.LockFile).%New() | ||
| set lockFile.ModuleName = module.Name | ||
| set lockFile.VersionString = module.VersionString | ||
| set lockFile.Repository = module.Repository | ||
|
|
||
| // Iterate over module dependency list | ||
| // For each module: | ||
| // 1. Set values for module name, version, repository (name), and direct dependencies | ||
| // 2. Add repository information to the list (if the module is from a new repo) | ||
| set moduleName = "" | ||
| for i = 1:1:flatDependencyList.Count() { | ||
| set moduleName = flatDependencyList.GetAt(i).Name | ||
| set mod = ##class(%IPM.Storage.Module).NameOpen(moduleName, 0, .sc) | ||
| $$$ThrowOnError(sc) | ||
|
|
||
| if (verbose) { | ||
| write !, "Adding "_mod.DisplayName_" to the lock file" | ||
| } | ||
|
|
||
| // Add the dependency to the lock file | ||
| set dependencyVal = ##class(%IPM.General.LockFile.Dependency).%New() | ||
| set dependencyVal.VersionString = mod.VersionString | ||
| set dependencyVal.Repository = mod.Repository | ||
| set depKey = "" | ||
| for { | ||
| set depMod = mod.Dependencies.GetNext(.depKey) | ||
| quit:depKey="" | ||
| $$$ThrowOnError(dependencyVal.Dependencies.SetAt(depMod.VersionString, depMod.Name)) | ||
| } | ||
| $$$ThrowOnError(lockFile.Dependencies.SetAt(dependencyVal, mod.Name)) | ||
|
|
||
| // Add the dependency's repository to the lock file | ||
| 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) | ||
| } | ||
|
|
||
| $$$ThrowOnError(lockFile.%JSONExportToStream(.lockFileJSON, "LockFileMapping")) | ||
|
|
||
| set lockFilePath = module.Root_..#LockFileName | ||
| if (verbose) { | ||
| write !, "Saving lock file for "_module.Name_" to: "_lockFilePath | ||
| } | ||
| set file = ##class(%Stream.FileCharacter).%New() | ||
| $$$ThrowOnError(file.LinkToFile(lockFilePath)) | ||
| $$$ThrowOnError(file.CopyFrom(lockFileJSON)) | ||
isc-jlechtne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $$$ThrowOnError(file.%Save()) | ||
| } | ||
|
|
||
| /// Adds a module's repository to the lock file | ||
| ClassMethod AddRepositoryToLockFile( | ||
| ByRef lockFile As %IPM.General.LockFile, | ||
| repositoryName As %String, | ||
| verbose As %Boolean = 0) [ Internal ] | ||
| { | ||
| set repo = ..GetRepo(repositoryName) | ||
| if 'lockFile.Repositories.IsDefined(repo.Name) { | ||
| if (verbose) { | ||
| write !, "Adding new repository to the lock file: "_repo.Name | ||
| } | ||
| $$$ThrowOnError(lockFile.Repositories.SetAt(repo, repo.Name)) | ||
| } | ||
| } | ||
|
|
||
| /// Returns a repo based on its name | ||
| ClassMethod GetRepo(repoName As %String) As %IPM.Repo.Definition [ Internal ] | ||
| { | ||
| if ##class(%IPM.Repo.Definition).ServerDefinitionKeyExists(repoName, .id) { | ||
| set repo = ##class(%IPM.Repo.Definition).%OpenId(id, , .sc) | ||
| $$$ThrowOnError(sc) | ||
| return repo | ||
| } else { | ||
| $$$ThrowStatus($$$ERROR($$$GeneralError,$$$FormatText("Tried getting repo ""%1"" but none found with that name", repoName))) | ||
| } | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /// Class which defines the schema to be used for a dependency object within a lock file | ||
| Class %IPM.General.LockFile.Dependency Extends (%RegisteredObject, %JSON.Adaptor) | ||
isc-jlechtne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
|
|
||
| /// Version string for this dependency module | ||
| Property VersionString As %IPM.DataType.VersionString(%JSONFIELDNAME = "version"); | ||
|
|
||
| /// Name of the repository this module comes from | ||
| Property Repository As %IPM.DataType.RepoName(%JSONFIELDNAME = "repository"); | ||
|
|
||
| /// Array of transient dependencies required by this dependency module. | ||
| /// key: module name | ||
| /// value: semantic version expression (required by this module) | ||
| /// | ||
| /// Example: { | ||
| /// "moduleOne": "^1.0.0", | ||
| /// "moduleTwo": "^2.1.3" | ||
| /// } | ||
| Property Dependencies As array Of %IPM.DataType.VersionString(%JSONFIELDNAME = "dependencies"); | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
With regards to separation of concerns, it may be better for this class to just be the interface for interacting with the lock file and have the creation/install methods in a utils class?