@@ -22,7 +22,8 @@ function Compare-Version {
22
22
File name: Compare-Version.ps1
23
23
Author: Florian Carrier
24
24
Creation date: 19/10/2019
25
- Last modified: 19/10/2019
25
+ Last modified: 05/02/2020
26
+ WARNING In case of modified formatting, Compare-Version only checks the semantic versionned part
26
27
#>
27
28
[CmdletBinding (
28
29
SupportsShouldProcess = $true
@@ -80,13 +81,13 @@ function Compare-Version {
80
81
" semantic" {
81
82
# Prepare version numbers for comparison
82
83
try {
83
- $VersionNumber = [System.Version ]::Parse($Version )
84
+ $VersionNumber = [System.Version ]::Parse($Version )
84
85
} catch [FormatException ] {
85
86
Write-Log - Type " ERROR" - Object " The version number "" $Version "" does not match $Format numbering"
86
87
return $false
87
88
}
88
89
try {
89
- $ReferenceNumber = [System.Version ]::Parse($Reference )
90
+ $ReferenceNumber = [System.Version ]::Parse($Reference )
90
91
} catch [FormatException ] {
91
92
Write-Log - Type " ERROR" - Object " The version number "" $Reference "" does not match $Format numbering"
92
93
return $false
@@ -101,36 +102,23 @@ function Compare-Version {
101
102
}
102
103
" modified" {
103
104
if ($Operator -in (" eq" , " ne" )) {
104
- # Build comparison command
105
- $Command = " "" $Version "" -$Operator "" $Reference "" "
106
- Write-Log - Type " DEBUG" - Object $Command
107
- # Execute comparison
108
- $Result = Invoke-Expression - Command $Command
109
- # Return comparison result
110
- return $Result
105
+ # Compare strings as-is
106
+ $VersionNumber = $Version
107
+ $ReferenceNumber = $Reference
111
108
} else {
112
109
# Parse version numbers
113
- $VersionNumbers = $Version.Split (" ." )
114
- $ReferenceNumbers = $Reference.Split (" ." )
115
- # Check comparison operator
116
- if ($Operator -in (" gt" , " ge" )) {
117
- # TODO implement
118
- # for ($i = 0; $i -lt $Count; $i++) {
119
- # if ($i -lt ($Count - 1)) {
120
- # $Command = """$($VersionNumbers[$i])"" -ge ""$($ReferenceNumbers[$i])"""
121
- # } else {
122
- # $Command = """$($VersionNumbers[$i])"" -Operator ""$($ReferenceNumbers[$i])"""
123
- # }
124
- # Write-Log -Type "DEBUG" -Object $Command
125
- # $Result = Invoke-Expression -Command $Command
126
- # if ($Result -eq $false) {
127
- # return $false
128
- # }
129
- # }
130
- } elseif ($Operator -in (" lt" , " le" )) {
131
- # TODO implement
132
- }
110
+ $SemanticVersion = Select-String - InputObject $Version - Pattern ' (\d+.\d+\d+)(?=\D*)' | ForEach-Object { $_.Matches.Value }
111
+ $VersionNumber = [System.Version ]::Parse($SemanticVersion )
112
+ $SemanticReference = Select-String - InputObject $Reference - Pattern ' (\d+.\d+\d+)(?=\D*)' | ForEach-Object { $_.Matches.Value }
113
+ $ReferenceNumber = [System.Version ]::Parse($SemanticReference )
133
114
}
115
+ # Build comparison command
116
+ $Command = " "" $VersionNumber "" -$Operator "" $ReferenceNumber "" "
117
+ Write-Log - Type " DEBUG" - Object $Command
118
+ # Execute comparison
119
+ $Result = Invoke-Expression - Command $Command
120
+ # Return comparison result
121
+ return $Result
134
122
}
135
123
default {
136
124
Write-Log - Type " ERROR" - Object " The $Format versionning format is not yet supported"
0 commit comments