Skip to content

Commit ea3e58c

Browse files
committed
- adds a script to auto-increment version number
1 parent 17bcc12 commit ea3e58c

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

Scripts/incrementMinorVersion.ps1

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
<#
5+
.Synopsis
6+
Increment the minor version string in the gradle.properties if the major,
7+
minor, or patch version hasn't been manually updated.
8+
.Description
9+
Assumptions:
10+
Targets Gradle.properties
11+
This script assumes it is run from the repo root.
12+
Minor version is typically auto-incremented.
13+
14+
#>
15+
16+
function Update-ReadmeVersion([string]$readmeFilePath, [string]$version) {
17+
$readmeFileContent = Get-Content -Path $readmeFilePath -Raw
18+
$readmeFileContent = $readmeFileContent -replace "\d{1,}\.\d{1,}\.\d{1,}", $version
19+
Set-Content -Path $readmeFilePath $readmeFileContent
20+
}
21+
22+
function Update-TelemetryVersion([string]$telemetryFilePath, [string]$version) {
23+
$telemetryFileContent = Get-Content -Path $telemetryFilePath -Raw
24+
$telemetryFileContent = $telemetryFileContent -replace "\d{1,}\.\d{1,}\.\d{1,}", $version
25+
Set-Content -Path $telemetryFilePath $telemetryFileContent
26+
}
27+
28+
function Update-PackageVersion([string]$propertiesFilePath, [string]$version) {
29+
$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+
}
41+
}
42+
function Get-CurrentTelemetryVersion([string]$telemetryFilePath) {
43+
$telemetryFileContent = Get-Content -Path $telemetryFilePath -Raw
44+
if($telemetryFileContent -match "(\d{1,}\.\d{1,}\.\d{1,})") {
45+
return $Matches[1]
46+
} else {
47+
Write-Error "Invalid version number format"
48+
return ""
49+
}
50+
}
51+
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+
}
62+
}
63+
64+
function Update-MinorVersion() {
65+
$readmeFilePath = Join-Path -Path $PWD.ToString() -ChildPath "../readme.md"
66+
$propertiesFilePath = Join-Path -Path $PWD.ToString() -ChildPath "../gradle.properties"
67+
$telemetryFilePath = Join-Path -Path $PWD.ToString() -ChildPath "../src/main/java/com/microsoft/graph/core/Constants.java"
68+
$currentVersion = Get-CurrentTelemetryVersion -telemetryFilePath $telemetryFilePath
69+
$nextVersion = Update-MinorVersionNumber -currentVersion $currentVersion
70+
Update-ReadmeVersion -version $nextVersion -readmeFilePath $readmeFilePath
71+
Update-TelemetryVersion -version $nextVersion -telemetryFilePath $telemetryFilePath
72+
Update-PackageVersion -version $nextVersion -propertiesFilePath $propertiesFilePath
73+
}
74+
Update-MinorVersion

0 commit comments

Comments
 (0)