Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project>
<PropertyGroup>
<!-- Version properties will be set by GitVersion -->
<VersionPrefix>5.0.5</VersionPrefix>

<PropertyGroup>
<!-- Common properties for all projects -->
<VersionPrefix>5.0.5</VersionPrefix>
<VersionSuffix>beta</VersionSuffix>

<Authors>Jonathan Horvath</Authors>
<Company>Z-bit Systems LLC</Company>
<Copyright>Copyright © $(Company) $([System.DateTime]::Now.Year)</Copyright>
Expand Down
17 changes: 3 additions & 14 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,16 @@ jobs:
vmImage: 'windows-latest'
steps:
- checkout: self
fetchDepth: 0
- template: ci/build.yml
- task: PowerShell@2
displayName: 'Set GitVersion variables for package job'
inputs:
targetType: 'inline'
script: |
Write-Host "##vso[task.setvariable variable=GitVersion.SemVer;isOutput=true]$(GITVERSION_SEMVER)"
Write-Host "##vso[task.setvariable variable=GitVersion.MajorMinorPatch;isOutput=true]$(GITVERSION_MAJORMINORPATCH)"
name: GitVersionOutput


- job: package
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
pool:
vmImage: 'windows-latest'
dependsOn:
build
variables:
GitVersionSemVer: $[ dependencies.build.outputs['GitVersionOutput.GitVersion.SemVer'] ]
GitVersionAssembly: $[ dependencies.build.outputs['GitVersionOutput.GitVersion.MajorMinorPatch'] ]
steps:
- checkout: self
fetchDepth: 0
persistCredentials: true
clean: true
- template: ci/package.yml
22 changes: 0 additions & 22 deletions ci/GitVersion.yml

This file was deleted.

149 changes: 149 additions & 0 deletions ci/Update-Version.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
param(
[Parameter(Mandatory = $false)]
[string]$BuildSourceBranch,

[Parameter(Mandatory = $false)]
[string]$BuildReason
)

# Function to parse version from Directory.Build.props
function Get-CurrentVersion {
$propsFile = "Directory.Build.props"
if (-not (Test-Path $propsFile)) {
throw "Directory.Build.props not found"
}

[xml]$xml = Get-Content $propsFile
$versionPrefix = $xml.Project.PropertyGroup.VersionPrefix

if (-not $versionPrefix) {
throw "VersionPrefix not found in Directory.Build.props"
}

return $versionPrefix
}

# Function to update version in Directory.Build.props
function Update-VersionInProps {
param([string]$NewVersion)

$propsFile = "Directory.Build.props"
[xml]$xml = Get-Content $propsFile

$xml.Project.PropertyGroup.VersionPrefix = $NewVersion
$xml.Save((Resolve-Path $propsFile))

Write-Host "Updated version to $NewVersion in Directory.Build.props"
}

# Function to increment patch version
function Get-IncrementedVersion {
param([string]$CurrentVersion)

if ($CurrentVersion -match '^(\d+)\.(\d+)\.(\d+)$') {
$major = [int]$matches[1]
$minor = [int]$matches[2]
$patch = [int]$matches[3] + 1

return "$major.$minor.$patch"
}
else {
throw "Invalid version format: $CurrentVersion"
}
}


# Main execution
try {
Write-Host "Starting version management script..."
Write-Host "Build Source Branch: $BuildSourceBranch"
Write-Host "Build Reason: $BuildReason"

# Get current version
$currentVersion = Get-CurrentVersion
Write-Host "Current version: $currentVersion"

# Check if this should trigger a version increment
# In Azure DevOps, we want to increment when:
# 1. We're building the master branch
# 2. The source branch was develop (indicating a merge from develop to master)
$shouldIncrement = $false

if ($BuildSourceBranch -eq "refs/heads/master" -or $BuildSourceBranch -eq "refs/heads/main") {
# Check if this is a merge from develop by looking at the commit message
$lastCommitMessage = git log -1 --pretty=format:"%s"
Write-Host "Checking commit message: $lastCommitMessage"

if ($lastCommitMessage -match "Merge.*develop.*master|Merge.*develop.*main|Merge pull request.*develop") {
Write-Host "Detected develop to master merge from commit message"
$shouldIncrement = $true
}
else {
# Alternative check using git merge-base to see if develop was recently merged
$developCommit = git rev-parse origin/develop 2>$null
$masterCommit = git rev-parse HEAD

if ($developCommit) {
$mergeBase = git merge-base $developCommit $masterCommit 2>$null
if ($mergeBase -eq $developCommit) {
Write-Host "Detected that develop branch was merged (develop is ancestor of current commit)"
$shouldIncrement = $true
}
}
}
}

if ($shouldIncrement) {
Write-Host "Detected develop to master merge - incrementing version"

# Increment version
$newVersion = Get-IncrementedVersion -CurrentVersion $currentVersion
Write-Host "New version: $newVersion"

# Update Directory.Build.props
Update-VersionInProps -NewVersion $newVersion

# Create git tag
$tagName = "v$newVersion"
Write-Host "Creating tag: $tagName"

git config user.email "[email protected]"
git config user.name "Azure DevOps Build"

git add Directory.Build.props
git commit -m "Bump version to $newVersion"
git tag -a $tagName -m "Release version $newVersion"

# Push tag to origin
git push origin $tagName
Write-Host "Pushed tag $tagName to origin"

# Switch to develop and merge the version update
Write-Host "Switching to develop branch to merge version update"
git checkout develop
git merge master --no-ff -m "Merge version update from master"
git push origin develop
Write-Host "Merged version update to develop branch"

# Switch back to master
git checkout master

# Set output variables for Azure DevOps
Write-Host "##vso[task.setvariable variable=NewVersion;isOutput=true]$newVersion"
Write-Host "##vso[task.setvariable variable=VersionIncremented;isOutput=true]true"
}
else {
Write-Host "No version increment needed"
Write-Host "##vso[task.setvariable variable=NewVersion;isOutput=true]$currentVersion"
Write-Host "##vso[task.setvariable variable=VersionIncremented;isOutput=true]false"
}

# Always output current version for build purposes
Write-Host "##vso[task.setvariable variable=BuildVersion;isOutput=true]$currentVersion"

Write-Host "Version management script completed successfully"
}
catch {
Write-Error "Error in version management script: $_"
exit 1
}
13 changes: 0 additions & 13 deletions ci/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,13 @@ steps:
inputs:
packageType: 'sdk'
version: '8.x'

- task: [email protected]
displayName: 'Install GitVersion'
inputs:
versionSpec: '6.3.x'

- task: [email protected]
displayName: 'Execute GitVersion'
inputs:
useConfigFile: true
configFilePath: 'ci/GitVersion.yml'

- task: DotNetCoreCLI@2
displayName: 'dotnet build'
inputs:
command: 'build'
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration)'
versioningScheme: 'byEnvVar'
versionEnvVar: 'GitVersion.MajorMinorPatch'

- task: DotNetCoreCLI@2
displayName: 'dotnet test'
Expand Down
76 changes: 70 additions & 6 deletions ci/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ steps:
displayName: 'Install .NET 8 SDK'
inputs:
packageType: 'sdk'
version: '8.x'
version: '8.x'

- task: DotNetCoreCLI@2
displayName: 'dotnet pack'
inputs:
command: 'pack'
arguments: '--configuration $(buildConfiguration) /p:PackageVersion=$(GitVersionNuGet)'
arguments: '--configuration $(buildConfiguration)'
packagesToPack: 'src/OSDP.Net/OSDP.Net.csproj'

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

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

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

- task: DotNetCoreCLI@2
displayName: 'dotnet publish for linux-arm64'
Expand All @@ -50,7 +50,7 @@ steps:
zipAfterPublish: false
modifyOutputPath: false
projects: 'src/ACUConsole/ACUConsole.csproj'
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)'
arguments: '-r linux-arm64 --configuration $(BuildConfiguration) --self-contained true -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -p:IncludeAllContentForSelfExtract=true --output $(Build.ArtifactStagingDirectory)/TestConsole/linux-arm64'

- task: ArchiveFiles@2
inputs:
Expand All @@ -63,3 +63,67 @@ steps:
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'

- task: PowerShell@2
displayName: 'Increment patch version after successful packaging'
inputs:
targetType: 'inline'
script: |
# Configure git for the build agent
git config --global user.email "[email protected]"
git config --global user.name "Azure DevOps Build Agent"

# Get current version for display
$currentVersion = & "$(Build.SourcesDirectory)/scripts/Get-Version.ps1" -Format Simple
Write-Host "Packaging completed successfully. Current version: $currentVersion"

# Increment patch version
& "$(Build.SourcesDirectory)/scripts/Increment-Version.ps1" -IncrementType Patch

# Get new version
$newVersion = & "$(Build.SourcesDirectory)/scripts/Get-Version.ps1" -Format Simple
Write-Host "New version: $newVersion"

# Set pipeline variable for later use
Write-Host "##vso[task.setvariable variable=NewVersion]$newVersion"

- task: PowerShell@2
displayName: 'Commit version update and create tag'
inputs:
targetType: 'inline'
script: |
$newVersion = "$(NewVersion)"

# Stage the Directory.Build.props file
git add Directory.Build.props

# Commit the version update
git commit -m "Bump version to $newVersion [skip ci]"

# Create a tag for the release
git tag -a "v$newVersion" -m "Release version $newVersion"

# Push the commit and tag to master
git push origin HEAD:master
git push origin "v$newVersion"

Write-Host "Version $newVersion committed and tagged successfully"

- task: PowerShell@2
displayName: 'Merge version update back to develop'
inputs:
targetType: 'inline'
script: |
$newVersion = "$(NewVersion)"

# Checkout develop branch
git fetch origin develop
git checkout develop

# Merge the version update from master
git merge origin/master --no-ff -m "Merge version bump $newVersion from master [skip ci]"

# Push the merge back to develop
git push origin develop

Write-Host "Version update $newVersion merged back to develop successfully"
Loading