@@ -28,9 +28,100 @@ jobs:
28
28
# vmImage: 'windows-latest'
29
29
# steps:
30
30
# - template: ci/winui-build.yml
31
-
32
- - job : testing
33
- pool :
34
- vmImage : ' windows-latest'
35
- steps :
36
- - template : ci/testing.yml
31
+
32
+ - job : testing
33
+ pool :
34
+ vmImage : ' windows-latest'
35
+ steps :
36
+ - template : ci/testing.yml
37
+
38
+ - job : version_bump
39
+ condition : and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
40
+ pool :
41
+ vmImage : ' windows-latest'
42
+ dependsOn :
43
+ testing
44
+ steps :
45
+ - checkout : self
46
+ persistCredentials : true
47
+
48
+ - powershell : |
49
+ # Find version file (could be Directory.Build.props, .csproj, or AssemblyInfo.cs)
50
+ # This example assumes Directory.Build.props
51
+ $versionFile = "Directory.Build.props"
52
+
53
+ if (Test-Path $versionFile) {
54
+ Write-Host "Using $versionFile for version"
55
+ } else {
56
+ # Try to find the main project file
57
+ $versionFile = Get-ChildItem -Path . -Filter "*.csproj" -Recurse | Select-Object -First 1 -ExpandProperty FullName
58
+ Write-Host "Using $versionFile for version"
59
+ }
60
+
61
+ # Read current version
62
+ $fileContent = Get-Content $versionFile -Raw
63
+ if ($fileContent -match '<AssemblyVersion>(.*?)</AssemblyVersion>') {
64
+ $currentVersion = $matches[1]
65
+ Write-Host "Current version: $currentVersion"
66
+
67
+ # Parse version components
68
+ $versionParts = $currentVersion.Split('.')
69
+ $major = $versionParts[0]
70
+ $minor = $versionParts[1]
71
+ $patch = [int]$versionParts[2]
72
+ $build = $versionParts[3]
73
+
74
+ # Increment patch number instead of build number
75
+ $patch++
76
+
77
+ # Keep build number if it exists, otherwise just use major.minor.patch
78
+ if ($versionParts.Length -gt 3) {
79
+ $build = $versionParts[3]
80
+ $newVersion = "$major.$minor.$patch.$build"
81
+ } else {
82
+ $newVersion = "$major.$minor.$patch"
83
+ }
84
+
85
+ Write-Host "New version: $newVersion"
86
+
87
+ # Update version in file
88
+ $fileContent = $fileContent -replace '<AssemblyVersion>(.*?)</AssemblyVersion>', "<AssemblyVersion>$newVersion</AssemblyVersion>"
89
+ $fileContent = $fileContent -replace '<FileVersion>(.*?)</FileVersion>', "<FileVersion>$newVersion</FileVersion>"
90
+ Set-Content -Path $versionFile -Value $fileContent
91
+
92
+ # Set version number as build variable
93
+ Write-Host "##vso[task.setvariable variable=BuildVersion]$newVersion"
94
+
95
+ # Configure git
96
+ git config user.email "azuredevops@z-bitco.com"
97
+ git config user.name "Azure DevOps Pipeline"
98
+
99
+ # Commit and push changes
100
+ git add $versionFile
101
+ git commit -m "Bump version to $newVersion [skip ci]"
102
+
103
+ # Set remote url with credentials
104
+ $accessToken = "$(System.AccessToken)"
105
+ $repoUrl = "$(Build.Repository.Uri)"
106
+
107
+ # Remove the 'https://' prefix and add the PAT
108
+ $repoUrl = $repoUrl -replace "https://", "https://`:$accessToken@"
109
+
110
+ git push $repoUrl HEAD:main
111
+
112
+ Write-Host "Version bumped to $newVersion"
113
+ } else {
114
+ Write-Host "##vso[task.logissue type=warning]No version tag found in $versionFile"
115
+ }
116
+ displayName: 'Bump patch version'
117
+ env:
118
+ SYSTEM_ACCESSTOKEN: $(System.AccessToken)
119
+
120
+ # Update build number with the version we just set
121
+ - powershell : |
122
+ # Set the build number to the version
123
+ if ("$(BuildVersion)" -ne "") {
124
+ Write-Host "##vso[build.updatebuildnumber]$(BuildVersion)"
125
+ }
126
+ displayName: 'Update build number'
127
+ condition: and(succeeded(), ne(variables['BuildVersion'], ''))
0 commit comments