(#1713) Previous package version as env variable #3689
Merged
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.
Description Of Changes
This commit adds the ability to output the previous package version, during say a
choco upgradecommand, as an environment variable. Prior to this commit, it was only the package version that was currently being installed/upgraded that was presented as an environment variable.The method that is responsible for writing the environment variables is the PreparePowerShellEnvironment method, which is defined by the IPowershellService interface. Rather than make a change to the interface to pass in this information, it was decided to add a property to the ChocolateyConfiguration class, which is currently being passed through to this method. This means that there is some maintainability in place, where additional information can be passed through as environment variables in the future, should the need arise. This would be done by simply adding another item into the Dictionary.
Pester tests have been updated to allow the testing for this new environment variable during the process of upgrading a package version.
Motivation and Context
This is needed since there are times that during an upgrade you want to do something based on which version is being upgraded from. For example, you might have to do "something" when upgrading from version 1.0.0 and "something else" when upgrading from version 2.0.0. Being able to inspect the previous package version as an environment variable, in the same way as you can the package version being currently installed is very useful, and also consistent with how package maintainers get other information.
Testing
NugetService.csclassinstall vscode --version 1.100.2 -nupgrade vscode -nvscode.installpackage, with the previous version of 1.100.2 and the current version 1.100.3vscodepackage, with the previous version of 1.100.2 and the current version 1.100.3config.Information.EnvironmentVariablesshould either have a Count of 0, or have a null value for theChocolateyPreviousPackageVersionentry.Operating Systems Testing
Change Types Made
Change Checklist
Related Issue
Fixes #1713