Skip to content

Commit b1fd425

Browse files
authored
Merge pull request #201 from Z-bit-Systems-LLC/develop
Test version increment script
2 parents 6b1cfac + 03fb803 commit b1fd425

File tree

13 files changed

+482
-60
lines changed

13 files changed

+482
-60
lines changed

Directory.Build.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<Project>
2-
<PropertyGroup>
3-
<!-- Version properties will be set by GitVersion -->
4-
<VersionPrefix>5.0.5</VersionPrefix>
5-
2+
<PropertyGroup>
63
<!-- Common properties for all projects -->
4+
<VersionPrefix>5.0.5</VersionPrefix>
5+
<VersionSuffix>beta</VersionSuffix>
6+
77
<Authors>Jonathan Horvath</Authors>
88
<Company>Z-bit Systems LLC</Company>
99
<Copyright>Copyright © $(Company) $([System.DateTime]::Now.Year)</Copyright>

azure-pipelines.yml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,16 @@ jobs:
2121
vmImage: 'windows-latest'
2222
steps:
2323
- checkout: self
24-
fetchDepth: 0
2524
- template: ci/build.yml
26-
- task: PowerShell@2
27-
displayName: 'Set GitVersion variables for package job'
28-
inputs:
29-
targetType: 'inline'
30-
script: |
31-
Write-Host "##vso[task.setvariable variable=GitVersion.SemVer;isOutput=true]$(GITVERSION_SEMVER)"
32-
Write-Host "##vso[task.setvariable variable=GitVersion.MajorMinorPatch;isOutput=true]$(GITVERSION_MAJORMINORPATCH)"
33-
name: GitVersionOutput
34-
25+
3526
- job: package
3627
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
3728
pool:
3829
vmImage: 'windows-latest'
3930
dependsOn:
4031
build
41-
variables:
42-
GitVersionSemVer: $[ dependencies.build.outputs['GitVersionOutput.GitVersion.SemVer'] ]
43-
GitVersionAssembly: $[ dependencies.build.outputs['GitVersionOutput.GitVersion.MajorMinorPatch'] ]
4432
steps:
4533
- checkout: self
46-
fetchDepth: 0
34+
persistCredentials: true
35+
clean: true
4736
- template: ci/package.yml

ci/GitVersion.yml

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

ci/Update-Version.ps1

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
param(
2+
[Parameter(Mandatory = $false)]
3+
[string]$BuildSourceBranch,
4+
5+
[Parameter(Mandatory = $false)]
6+
[string]$BuildReason
7+
)
8+
9+
# Function to parse version from Directory.Build.props
10+
function Get-CurrentVersion {
11+
$propsFile = "Directory.Build.props"
12+
if (-not (Test-Path $propsFile)) {
13+
throw "Directory.Build.props not found"
14+
}
15+
16+
[xml]$xml = Get-Content $propsFile
17+
$versionPrefix = $xml.Project.PropertyGroup.VersionPrefix
18+
19+
if (-not $versionPrefix) {
20+
throw "VersionPrefix not found in Directory.Build.props"
21+
}
22+
23+
return $versionPrefix
24+
}
25+
26+
# Function to update version in Directory.Build.props
27+
function Update-VersionInProps {
28+
param([string]$NewVersion)
29+
30+
$propsFile = "Directory.Build.props"
31+
[xml]$xml = Get-Content $propsFile
32+
33+
$xml.Project.PropertyGroup.VersionPrefix = $NewVersion
34+
$xml.Save((Resolve-Path $propsFile))
35+
36+
Write-Host "Updated version to $NewVersion in Directory.Build.props"
37+
}
38+
39+
# Function to increment patch version
40+
function Get-IncrementedVersion {
41+
param([string]$CurrentVersion)
42+
43+
if ($CurrentVersion -match '^(\d+)\.(\d+)\.(\d+)$') {
44+
$major = [int]$matches[1]
45+
$minor = [int]$matches[2]
46+
$patch = [int]$matches[3] + 1
47+
48+
return "$major.$minor.$patch"
49+
}
50+
else {
51+
throw "Invalid version format: $CurrentVersion"
52+
}
53+
}
54+
55+
56+
# Main execution
57+
try {
58+
Write-Host "Starting version management script..."
59+
Write-Host "Build Source Branch: $BuildSourceBranch"
60+
Write-Host "Build Reason: $BuildReason"
61+
62+
# Get current version
63+
$currentVersion = Get-CurrentVersion
64+
Write-Host "Current version: $currentVersion"
65+
66+
# Check if this should trigger a version increment
67+
# In Azure DevOps, we want to increment when:
68+
# 1. We're building the master branch
69+
# 2. The source branch was develop (indicating a merge from develop to master)
70+
$shouldIncrement = $false
71+
72+
if ($BuildSourceBranch -eq "refs/heads/master" -or $BuildSourceBranch -eq "refs/heads/main") {
73+
# Check if this is a merge from develop by looking at the commit message
74+
$lastCommitMessage = git log -1 --pretty=format:"%s"
75+
Write-Host "Checking commit message: $lastCommitMessage"
76+
77+
if ($lastCommitMessage -match "Merge.*develop.*master|Merge.*develop.*main|Merge pull request.*develop") {
78+
Write-Host "Detected develop to master merge from commit message"
79+
$shouldIncrement = $true
80+
}
81+
else {
82+
# Alternative check using git merge-base to see if develop was recently merged
83+
$developCommit = git rev-parse origin/develop 2>$null
84+
$masterCommit = git rev-parse HEAD
85+
86+
if ($developCommit) {
87+
$mergeBase = git merge-base $developCommit $masterCommit 2>$null
88+
if ($mergeBase -eq $developCommit) {
89+
Write-Host "Detected that develop branch was merged (develop is ancestor of current commit)"
90+
$shouldIncrement = $true
91+
}
92+
}
93+
}
94+
}
95+
96+
if ($shouldIncrement) {
97+
Write-Host "Detected develop to master merge - incrementing version"
98+
99+
# Increment version
100+
$newVersion = Get-IncrementedVersion -CurrentVersion $currentVersion
101+
Write-Host "New version: $newVersion"
102+
103+
# Update Directory.Build.props
104+
Update-VersionInProps -NewVersion $newVersion
105+
106+
# Create git tag
107+
$tagName = "v$newVersion"
108+
Write-Host "Creating tag: $tagName"
109+
110+
git config user.email "[email protected]"
111+
git config user.name "Azure DevOps Build"
112+
113+
git add Directory.Build.props
114+
git commit -m "Bump version to $newVersion"
115+
git tag -a $tagName -m "Release version $newVersion"
116+
117+
# Push tag to origin
118+
git push origin $tagName
119+
Write-Host "Pushed tag $tagName to origin"
120+
121+
# Switch to develop and merge the version update
122+
Write-Host "Switching to develop branch to merge version update"
123+
git checkout develop
124+
git merge master --no-ff -m "Merge version update from master"
125+
git push origin develop
126+
Write-Host "Merged version update to develop branch"
127+
128+
# Switch back to master
129+
git checkout master
130+
131+
# Set output variables for Azure DevOps
132+
Write-Host "##vso[task.setvariable variable=NewVersion;isOutput=true]$newVersion"
133+
Write-Host "##vso[task.setvariable variable=VersionIncremented;isOutput=true]true"
134+
}
135+
else {
136+
Write-Host "No version increment needed"
137+
Write-Host "##vso[task.setvariable variable=NewVersion;isOutput=true]$currentVersion"
138+
Write-Host "##vso[task.setvariable variable=VersionIncremented;isOutput=true]false"
139+
}
140+
141+
# Always output current version for build purposes
142+
Write-Host "##vso[task.setvariable variable=BuildVersion;isOutput=true]$currentVersion"
143+
144+
Write-Host "Version management script completed successfully"
145+
}
146+
catch {
147+
Write-Error "Error in version management script: $_"
148+
exit 1
149+
}

ci/build.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,13 @@ steps:
44
inputs:
55
packageType: 'sdk'
66
version: '8.x'
7-
8-
9-
displayName: 'Install GitVersion'
10-
inputs:
11-
versionSpec: '6.3.x'
12-
13-
14-
displayName: 'Execute GitVersion'
15-
inputs:
16-
useConfigFile: true
17-
configFilePath: 'ci/GitVersion.yml'
187

198
- task: DotNetCoreCLI@2
209
displayName: 'dotnet build'
2110
inputs:
2211
command: 'build'
2312
projects: '**/*.csproj'
2413
arguments: '--configuration $(buildConfiguration)'
25-
versioningScheme: 'byEnvVar'
26-
versionEnvVar: 'GitVersion.MajorMinorPatch'
2714

2815
- task: DotNetCoreCLI@2
2916
displayName: 'dotnet test'

ci/package.yml

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ steps:
33
displayName: 'Install .NET 8 SDK'
44
inputs:
55
packageType: 'sdk'
6-
version: '8.x'
6+
version: '8.x'
77

88
- task: DotNetCoreCLI@2
99
displayName: 'dotnet pack'
1010
inputs:
1111
command: 'pack'
12-
arguments: '--configuration $(buildConfiguration) /p:PackageVersion=$(GitVersionNuGet)'
12+
arguments: '--configuration $(buildConfiguration)'
1313
packagesToPack: 'src/OSDP.Net/OSDP.Net.csproj'
1414

1515
- task: DotNetCoreCLI@2
@@ -18,7 +18,7 @@ steps:
1818
command: 'publish'
1919
publishWebProjects: false
2020
projects: 'src/ACUConsole/ACUConsole.csproj'
21-
arguments: '-r osx-arm64 --configuration $(BuildConfiguration) /p:PublishSingleFile=true /p:IncludeAllContentForSelfExtract=true --self-contained true --output $(Build.ArtifactStagingDirectory)/TestConsole/osx-arm64 /p:Version=$(GitVersionAssembly)'
21+
arguments: '-r osx-arm64 --configuration $(BuildConfiguration) /p:PublishSingleFile=true /p:IncludeAllContentForSelfExtract=true --self-contained true --output $(Build.ArtifactStagingDirectory)/TestConsole/osx-arm64'
2222
zipAfterPublish: false
2323
modifyOutputPath: false
2424

@@ -30,7 +30,7 @@ steps:
3030
zipAfterPublish: false
3131
modifyOutputPath: false
3232
projects: 'src/ACUConsole/ACUConsole.csproj'
33-
arguments: '-r win-x64 --configuration $(BuildConfiguration) /p:PublishSingleFile=true /p:IncludeAllContentForSelfExtract=true --self-contained true --output $(Build.ArtifactStagingDirectory)/TestConsole/win-x64 /p:Version=$(GitVersionAssembly)'
33+
arguments: '-r win-x64 --configuration $(BuildConfiguration) /p:PublishSingleFile=true /p:IncludeAllContentForSelfExtract=true --self-contained true --output $(Build.ArtifactStagingDirectory)/TestConsole/win-x64'
3434

3535
- task: DotNetCoreCLI@2
3636
displayName: 'dotnet publish for linux-x64'
@@ -40,7 +40,7 @@ steps:
4040
zipAfterPublish: false
4141
modifyOutputPath: false
4242
projects: 'src/ACUConsole/ACUConsole.csproj'
43-
arguments: '-r linux-x64 --configuration $(BuildConfiguration) /p:PublishSingleFile=true /p:IncludeAllContentForSelfExtract=true --self-contained true --output $(Build.ArtifactStagingDirectory)/TestConsole/linux-x64 /p:Version=$(GitVersionAssembly)'
43+
arguments: '-r linux-x64 --configuration $(BuildConfiguration) /p:PublishSingleFile=true /p:IncludeAllContentForSelfExtract=true --self-contained true --output $(Build.ArtifactStagingDirectory)/TestConsole/linux-x64'
4444

4545
- task: DotNetCoreCLI@2
4646
displayName: 'dotnet publish for linux-arm64'
@@ -50,7 +50,7 @@ steps:
5050
zipAfterPublish: false
5151
modifyOutputPath: false
5252
projects: 'src/ACUConsole/ACUConsole.csproj'
53-
arguments: '-r linux-arm64 --configuration $(BuildConfiguration) --self-contained true -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -p:IncludeAllContentForSelfExtract=true --output $(Build.ArtifactStagingDirectory)/TestConsole/linux-arm64 /p:Version=$(GitVersionAssembly)'
53+
arguments: '-r linux-arm64 --configuration $(BuildConfiguration) --self-contained true -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -p:IncludeAllContentForSelfExtract=true --output $(Build.ArtifactStagingDirectory)/TestConsole/linux-arm64'
5454

5555
- task: ArchiveFiles@2
5656
inputs:
@@ -63,3 +63,67 @@ steps:
6363
- task: PublishPipelineArtifact@1
6464
inputs:
6565
targetPath: '$(Build.ArtifactStagingDirectory)'
66+
67+
- task: PowerShell@2
68+
displayName: 'Increment patch version after successful packaging'
69+
inputs:
70+
targetType: 'inline'
71+
script: |
72+
# Configure git for the build agent
73+
git config --global user.email "[email protected]"
74+
git config --global user.name "Azure DevOps Build Agent"
75+
76+
# Get current version for display
77+
$currentVersion = & "$(Build.SourcesDirectory)/scripts/Get-Version.ps1" -Format Simple
78+
Write-Host "Packaging completed successfully. Current version: $currentVersion"
79+
80+
# Increment patch version
81+
& "$(Build.SourcesDirectory)/scripts/Increment-Version.ps1" -IncrementType Patch
82+
83+
# Get new version
84+
$newVersion = & "$(Build.SourcesDirectory)/scripts/Get-Version.ps1" -Format Simple
85+
Write-Host "New version: $newVersion"
86+
87+
# Set pipeline variable for later use
88+
Write-Host "##vso[task.setvariable variable=NewVersion]$newVersion"
89+
90+
- task: PowerShell@2
91+
displayName: 'Commit version update and create tag'
92+
inputs:
93+
targetType: 'inline'
94+
script: |
95+
$newVersion = "$(NewVersion)"
96+
97+
# Stage the Directory.Build.props file
98+
git add Directory.Build.props
99+
100+
# Commit the version update
101+
git commit -m "Bump version to $newVersion [skip ci]"
102+
103+
# Create a tag for the release
104+
git tag -a "v$newVersion" -m "Release version $newVersion"
105+
106+
# Push the commit and tag to master
107+
git push origin HEAD:master
108+
git push origin "v$newVersion"
109+
110+
Write-Host "Version $newVersion committed and tagged successfully"
111+
112+
- task: PowerShell@2
113+
displayName: 'Merge version update back to develop'
114+
inputs:
115+
targetType: 'inline'
116+
script: |
117+
$newVersion = "$(NewVersion)"
118+
119+
# Checkout develop branch
120+
git fetch origin develop
121+
git checkout develop
122+
123+
# Merge the version update from master
124+
git merge origin/master --no-ff -m "Merge version bump $newVersion from master [skip ci]"
125+
126+
# Push the merge back to develop
127+
git push origin develop
128+
129+
Write-Host "Version update $newVersion merged back to develop successfully"

0 commit comments

Comments
 (0)