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 csproj if the major,
7+ minor, or patch version hasn't been manually updated.
8+ . Description
9+ Assumptions:
10+ Targets Microsoft.Graph.csproj
11+ This script assumes it is run from the repo root.
12+ VersionPrefix is set in the first property group in the csproj.
13+ Major or patch update versions are manually set by dev.
14+ Minor version is typically auto-incremented.
15+
16+ #>
17+
18+ function Update-ReadmeVersion ([string ]$readmeFilePath , [string ]$version ) {
19+ $readmeFileContent = Get-Content - Path $readmeFilePath - Raw
20+ $readmeFileContent = $readmeFileContent -replace " \d{1,}\.\d{1,}\.\d{1,}" , $version
21+ Set-Content - Path $readmeFilePath $readmeFileContent
22+ }
23+
24+ function Update-TelemetryVersion ([string ]$telemetryFilePath , [string ]$version ) {
25+ $telemetryFileContent = Get-Content - Path $telemetryFilePath - Raw
26+ $telemetryFileContent = $telemetryFileContent -replace " \d{1,}\.\d{1,}\.\d{1,}" , $version
27+ Set-Content - Path $telemetryFilePath $telemetryFileContent
28+ }
29+
30+ function Update-PackageVersion ([string ]$propertiesFilePath , [string ]$version ) {
31+ $propertiesFileContent = Get-Content - Path $propertiesFilePath - Raw
32+ if ($version -match " (\d{1,})\.(\d{1,})\.(\d{1,})" ) {
33+ $patch = $Matches [3 ]
34+ $minor = $Matches [2 ]
35+ $major = $Matches [1 ]
36+ $propertiesFileContent = $propertiesFileContent -replace " mavenMajorVersion\s+=\s+\d{1,}" , " mavenMajorVersion = $major "
37+ $propertiesFileContent = $propertiesFileContent -replace " mavenMinorVersion\s+=\s+\d{1,}" , " mavenMinorVersion = $minor "
38+ $propertiesFileContent = $propertiesFileContent -replace " mavenPatchVersion\s+=\s+\d{1,}" , " mavenPatchVersion = $patch "
39+ Set-Content - Path $propertiesFilePath $propertiesFileContent
40+ } else {
41+ Write-Error " Invalid version number format $version "
42+ }
43+ }
44+ function Get-CurrentTelemetryVersion ([string ]$telemetryFilePath ) {
45+ $telemetryFileContent = Get-Content - Path $telemetryFilePath - Raw
46+ if ($telemetryFileContent -match " (\d{1,}\.\d{1,}\.\d{1,})" ) {
47+ return $Matches [1 ]
48+ } else {
49+ Write-Error " Invalid version number format"
50+ return " "
51+ }
52+ }
53+
54+ function Update-MinorVersionNumber ([string ]$currentVersion ) {
55+ if ($currentVersion -match " (\d{1,})\.(\d{1,})\.(\d{1,})" ) {
56+ [int ]$minor = [convert ]::ToInt32($Matches [2 ])
57+ $minor ++ ;
58+ $major = $Matches [1 ]
59+ return " $major .$minor .0"
60+ } else {
61+ Write-Error " Invalid version number format $currentVersion "
62+ return " "
63+ }
64+ }
65+
66+ function Update-MinorVersion () {
67+ $readmeFilePath = Join-Path - Path $PWD.ToString () - ChildPath " ../readme.md"
68+ $propertiesFilePath = Join-Path - Path $PWD.ToString () - ChildPath " ../gradle.properties"
69+ $telemetryFilePath = Join-Path - Path $PWD.ToString () - ChildPath " ../src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java"
70+ $currentVersion = Get-CurrentTelemetryVersion - telemetryFilePath $telemetryFilePath
71+ $nextVersion = Update-MinorVersionNumber - currentVersion $currentVersion
72+ Update-ReadmeVersion - version $nextVersion - readmeFilePath $readmeFilePath
73+ Update-TelemetryVersion - version $nextVersion - telemetryFilePath $telemetryFilePath
74+ Update-PackageVersion - version $nextVersion - propertiesFilePath $propertiesFilePath
75+ }
76+ Update-MinorVersion
0 commit comments