Skip to content

Commit 70a53d3

Browse files
authored
Merge pull request #580 from microsoftgraph/feature/increment-version-pr-review
- applies recommendations from core PR
2 parents b064798 + 3108e71 commit 70a53d3

File tree

1 file changed

+13
-28
lines changed

1 file changed

+13
-28
lines changed

Scripts/incrementMinorVersion.ps1

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,52 +13,37 @@
1313
1414
#>
1515

16-
function Update-ReadmeVersion([string]$readmeFilePath, [string]$version) {
16+
function Update-ReadmeVersion([string]$readmeFilePath, [version]$version) {
1717
$readmeFileContent = Get-Content -Path $readmeFilePath -Raw
18-
$readmeFileContent = $readmeFileContent -replace "\d{1,}\.\d{1,}\.\d{1,}", $version
18+
$readmeFileContent = $readmeFileContent -replace "\d{1,}\.\d{1,}\.\d{1,}", $version.ToString()
1919
Set-Content -Path $readmeFilePath $readmeFileContent
2020
}
2121

22-
function Update-TelemetryVersion([string]$telemetryFilePath, [string]$version) {
22+
function Update-TelemetryVersion([string]$telemetryFilePath, [version]$version) {
2323
$telemetryFileContent = Get-Content -Path $telemetryFilePath -Raw
24-
$telemetryFileContent = $telemetryFileContent -replace "\d{1,}\.\d{1,}\.\d{1,}", $version
24+
$telemetryFileContent = $telemetryFileContent -replace "\d{1,}\.\d{1,}\.\d{1,}", $version.ToString()
2525
Set-Content -Path $telemetryFilePath $telemetryFileContent
2626
}
2727

28-
function Update-PackageVersion([string]$propertiesFilePath, [string]$version) {
28+
function Update-PackageVersion([string]$propertiesFilePath, [version]$version) {
2929
$propertiesFileContent = Get-Content -Path $propertiesFilePath -Raw
30-
if($version -match "(\d{1,})\.(\d{1,})\.(\d{1,})") {
31-
$patch = $Matches[3]
32-
$minor = $Matches[2]
33-
$major = $Matches[1]
34-
$propertiesFileContent = $propertiesFileContent -replace "mavenMajorVersion\s+=\s+\d{1,}", "mavenMajorVersion = $major"
35-
$propertiesFileContent = $propertiesFileContent -replace "mavenMinorVersion\s+=\s+\d{1,}", "mavenMinorVersion = $minor"
36-
$propertiesFileContent = $propertiesFileContent -replace "mavenPatchVersion\s+=\s+\d{1,}", "mavenPatchVersion = $patch"
37-
Set-Content -Path $propertiesFilePath $propertiesFileContent
38-
} else {
39-
Write-Error "Invalid version number format $version"
40-
}
30+
$propertiesFileContent = $propertiesFileContent -replace "mavenMajorVersion\s+=\s+\d{1,}", "mavenMajorVersion = $($version.Major)"
31+
$propertiesFileContent = $propertiesFileContent -replace "mavenMinorVersion\s+=\s+\d{1,}", "mavenMinorVersion = $($version.Minor)"
32+
$propertiesFileContent = $propertiesFileContent -replace "mavenPatchVersion\s+=\s+\d{1,}", "mavenPatchVersion = $($version.Build)"
33+
Set-Content -Path $propertiesFilePath $propertiesFileContent
4134
}
4235
function Get-CurrentTelemetryVersion([string]$telemetryFilePath) {
4336
$telemetryFileContent = Get-Content -Path $telemetryFilePath -Raw
4437
if($telemetryFileContent -match "(\d{1,}\.\d{1,}\.\d{1,})") {
45-
return $Matches[1]
38+
return [version]::Parse($Matches[1])
4639
} else {
4740
Write-Error "Invalid version number format"
48-
return ""
41+
return $null;
4942
}
5043
}
5144

52-
function Update-MinorVersionNumber([string]$currentVersion) {
53-
if($currentVersion -match "(\d{1,})\.(\d{1,})\.(\d{1,})") {
54-
[int]$minor = [convert]::ToInt32($Matches[2])
55-
$minor++;
56-
$major = $Matches[1]
57-
return "$major.$minor.0"
58-
} else {
59-
Write-Error "Invalid version number format $currentVersion"
60-
return ""
61-
}
45+
function Update-MinorVersionNumber([version]$currentVersion) {
46+
return [version]::new($currentVersion.Major, $currentVersion.Minor + 1, 0);
6247
}
6348

6449
function Update-MinorVersion() {

0 commit comments

Comments
 (0)