Skip to content

Commit 028e2cc

Browse files
committed
- adds a script to automatically increment minor version
1 parent d0fbb70 commit 028e2cc

File tree

5 files changed

+76
-106
lines changed

5 files changed

+76
-106
lines changed

.azure-pipelines/buildAndPackage.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ steps:
8585
settings.gradle
8686
gradle.properties
8787
**/gradle/wrapper/*
88-
Scripts/getLatestVersion.ps1
8988
TargetFolder: '$(Build.ArtifactStagingDirectory)/'
9089

9190
- task: PublishBuildArtifacts@1

.azure-pipelines/prValidate.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,6 @@ steps:
4343
inputs:
4444
debugMode: false
4545

46-
- task: PowerShell@2
47-
condition: and(failed(), eq(variables['Build.SourceBranchName'], 'dev'))
48-
inputs:
49-
filePath: '$(System.DefaultWorkingDirectory)\Scripts\validateMavenVersion.ps1'
50-
pwsh: true
51-
arguments: '-packageName "$(PACKAGE_NAME)" -propertiesPath "$(PROPERTIES_PATH)"'
52-
5346
- task: Gradle@2
5447
inputs:
5548
gradleWrapperFile: 'gradlew'

Scripts/getLatestVersion.ps1

Lines changed: 0 additions & 31 deletions
This file was deleted.

Scripts/incrementMinorVersion.ps1

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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

Scripts/validateMavenVersion.ps1

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)