Closed phbits closed 3 years ago
Merging #271 (1fc2c70) into master (00fd55d) will not change coverage. The diff coverage is
n/a
.
@@ Coverage Diff @@
## master #271 +/- ##
=====================================
Coverage 13% 13%
=====================================
Files 24 24
Lines 431 431
=====================================
Hits 58 58
Misses 373 373
@phbits we should update the Plaster template the same way I think: https://github.com/gaelcolas/Sampler/blob/master/Sampler/Templates/Build/Resolve-Dependency.ps1
@gaelcolas what do you think about the validation @phbits is mentioning?
@johlju Thanks for the suggestion. Just made the change.
The part I'm not clear on is how this change will impact scripts which call Resolve-Dependency.ps1.
This script is dot-sourced from within the build.ps1, and is normally not executed on its own. The parameter MinimumPSDependVersion
is read from Resolve-Dependency.psd1
), but it can also exist as a variable in the parent scope.
I suggest we skip parameter validation due to the script is being dot-sourced by the build.ps1 script.
When using the below code the variable $MinimumPSDependVersion
is automatically converted to [System.Version]
because that type is on the left-hand of the operator.
$psDependModule = $psDependModule | Where-Object -FilterScript { $_.Version -ge $MinimumPSDependVersion }
Using that and providing the value '1' it will actually give an even better error message:
PS > $a = Get-Module -Name 'PSDepend' -ListAvailable
PS > $a | Where-Object -FilterScript { $_.Version -ge '1' }
InvalidOperation: Could not compare "0.3.8" to "1". Error: "Cannot convert value "1" to type "System.Version". Error: "Version string portion was too short or too long. (Parameter 'input')""
PSDepend is using sematic versioning, so providing a value other than that should be rare. But if we want to point the user to where the error happened, if providing just '1', or '2', then we should wrap the comparison within a try-catch block.
So then the suggestion would be that we use:
try
{
$psDependModule = $psDependModule | Where-Object -FilterScript { $_.Version -ge $MinimumPSDependVersion }
}
catch
{
throw ('There was a problem finding the minimum version of PSDepend. Error: {0}' -f $_)
}
@johlju Thanks for the feedback! Updated the files with your try/catch approach and resolved the CHANGELOG conflict.
@phbits thank you for your contribution! 😃
Pull Request
Pull Request (PR) description
Updated MinimumPSDependVersion to use
[System.Version]::New(<string>)
.The only issue I've found with using this technique is using a single digit will create an error:
Adding
.0
fixes this.Could add parameter validation though that would require a separate function since the following attribute throws an error if no value is specified.
I'm impartial on how you'd like to handle input validation. All I know is comparing version numbers works best using
System.Version
.Fixed
Task list
build.ps1 -ResolveDependency
).This change is