azure-pipelines.ymlโข15.1 kB
# Azure Pipelines for COA Goldfish MCP
# Supports both CI builds (automatic) and Release builds (manual)
# CI: Builds and publishes to Azure DevOps feed only
# Release: Manual trigger with option to publish to NuGet.org
name: 'COA Goldfish MCP - v$(majorVersion).$(minorVersion).$(patchVersion)'
trigger:
branches:
include:
- main
- develop
- release/*
tags:
include:
- v*
paths:
exclude:
- "**/*.md"
- ".gitignore"
- "docs/**"
- "archive/**"
- "Templates/**"
pr:
branches:
include:
- main
- develop
# Parameters for manual runs
parameters:
- name: publishToNuGet
displayName: 'Publish to NuGet.org?'
type: boolean
default: false
- name: createGitTag
displayName: 'Create Git tag for release?'
type: boolean
default: true
pool:
name: "Default" # Using local Windows agent pool
variables:
buildConfiguration: "Release"
dotnetSdkVersion: "9.x"
# Base version for Goldfish MCP - v3.0.0 (major version bump for .NET migration)
majorVersion: 3
minorVersion: 0
# Auto-incrementing patch version - increments on every build
# The counter is keyed by major.minor version, so it resets when those change
patchVersion: $[counter(format('{0}.{1}', variables['majorVersion'], variables['minorVersion']), 0)]
versionPrefix: "$(majorVersion).$(minorVersion).$(patchVersion)"
versionSuffix: ""
# Windows-specific settings
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
NUGET_PACKAGES: $(Pipeline.Workspace)\.nuget\packages
# Manual run parameters (only available for manual runs)
shouldPublishToNuGet: ${{ parameters.publishToNuGet }}
shouldCreateTag: ${{ parameters.createGitTag }}
# Determine if this is a release build
isRelease: ${{ eq(variables['Build.Reason'], 'Manual') }}
stages:
- stage: Build
displayName: "Build and Test"
jobs:
- job: BuildAndTest
displayName: "Build, Test, and Pack"
steps:
- checkout: self
fetchDepth: 0
clean: true
- powershell: |
Write-Host "Agent Information:"
Write-Host "=================="
Write-Host "Agent Name: $env:AGENT_NAME"
Write-Host "Agent OS: $env:AGENT_OS"
Write-Host "Agent Version: $env:AGENT_VERSION"
Write-Host "OS Version: $([System.Environment]::OSVersion.VersionString)"
Write-Host "PowerShell Version: $($PSVersionTable.PSVersion)"
Write-Host "=================="
displayName: "Display agent information"
- task: Cache@2
displayName: "Cache NuGet packages"
inputs:
key: 'nuget | "$(Agent.OS)" | **/*.csproj,!**/bin/**,!**/obj/**'
restoreKeys: |
nuget | "$(Agent.OS)"
nuget
path: "$(NUGET_PACKAGES)"
- powershell: |
# Calculate version based on branch/tag
$majorVersion = $(majorVersion)
$minorVersion = $(minorVersion)
$patchVersion = $(patchVersion)
# Get the build counter for the current version
$buildRevision = $env:BUILD_BUILDNUMBER.Split('.')[-1]
Write-Host "Build Source Branch: $env:BUILD_SOURCEBRANCH"
Write-Host "Build Reason: $env:BUILD_REASON"
Write-Host "Patch Version (auto-incremented): $patchVersion"
if ($env:BUILD_SOURCEBRANCH -match "^refs/tags/v(.*)") {
# Tag build - use the version from the tag
$version = $matches[1]
$versionSuffix = ""
Write-Host "Tag build detected. Version from tag: $version"
}
elseif ($env:BUILD_SOURCEBRANCH -eq "refs/heads/main") {
# Main branch - use auto-incremented patch version
$version = "$majorVersion.$minorVersion.$patchVersion"
$versionSuffix = ""
Write-Host "Main branch build. Version: $version"
}
elseif ($env:BUILD_SOURCEBRANCH -match "^refs/heads/release/(.*)") {
# Release branch
$releaseName = $matches[1]
if ($releaseName -match "^(\d+)\.(\d+)") {
$majorVersion = $matches[1]
$minorVersion = $matches[2]
}
$version = "$majorVersion.$minorVersion.$patchVersion"
$versionSuffix = "rc.$buildRevision"
Write-Host "Release branch build. Version: $version-$versionSuffix"
}
elseif ($env:BUILD_SOURCEBRANCH -eq "refs/heads/develop") {
# Develop branch - preview versions
$version = "$majorVersion.$minorVersion.$patchVersion"
$versionSuffix = "preview.$buildRevision"
Write-Host "Develop branch build. Version: $version-$versionSuffix"
}
else {
# Feature branches or PRs
$version = "$majorVersion.$minorVersion.$patchVersion"
$branchName = $env:BUILD_SOURCEBRANCHNAME -replace '[^a-zA-Z0-9]', ''
$versionSuffix = "alpha.$branchName.$buildRevision"
Write-Host "Feature branch build. Version: $version-$versionSuffix"
}
# Set pipeline variables
Write-Host "##vso[task.setvariable variable=versionPrefix]$version"
Write-Host "##vso[task.setvariable variable=versionSuffix]$versionSuffix"
if ($versionSuffix) {
Write-Host "##vso[build.updatebuildnumber]$version-$versionSuffix"
Write-Host "Final version: $version-$versionSuffix"
}
else {
Write-Host "##vso[build.updatebuildnumber]$version"
Write-Host "Final version: $version"
}
displayName: "Calculate version number"
name: VersionStep
- powershell: |
Write-Host "========================================="
Write-Host "Package Version Information:"
Write-Host "========================================="
Write-Host "Major Version: $(majorVersion)"
Write-Host "Minor Version: $(minorVersion)"
Write-Host "Patch Version: $(patchVersion)"
Write-Host "Version Prefix: $(versionPrefix)"
Write-Host "Version Suffix: $(versionSuffix)"
if ("$(versionSuffix)") {
Write-Host "Full Version: $(versionPrefix)-$(versionSuffix)"
}
else {
Write-Host "Full Version: $(versionPrefix)"
}
Write-Host "Counter Key: $(majorVersion).$(minorVersion)"
Write-Host "========================================="
displayName: "Display version information"
- task: UseDotNet@2
displayName: "Install .NET SDK"
inputs:
version: $(dotnetSdkVersion)
includePreviewVersions: false
- task: DotNetCoreCLI@2
displayName: "Restore packages"
inputs:
command: "restore"
projects: "**/*.csproj"
feedsToUse: "select"
vstsFeed: "COA"
includeNuGetOrg: true
- powershell: |
# Prepare build/pack arguments based on version suffix
$versionArgs = "-p:VersionPrefix=$(versionPrefix)"
if ("$(versionSuffix)") {
$versionArgs += " -p:VersionSuffix=$(versionSuffix)"
}
Write-Host "##vso[task.setvariable variable=versionArguments]$versionArgs"
Write-Host "Version arguments: $versionArgs"
displayName: "Prepare version arguments"
- task: DotNetCoreCLI@2
displayName: "Build solution"
inputs:
command: "build"
projects: "**/*.sln"
arguments: "--configuration $(buildConfiguration) --no-restore $(versionArguments)"
- task: DotNetCoreCLI@2
displayName: "Run tests"
inputs:
command: "test"
projects: "**/*Tests.csproj"
arguments: '--configuration $(buildConfiguration) --no-build --collect:"XPlat Code Coverage"'
publishTestResults: true
- task: PublishCodeCoverageResults@2
displayName: "Publish code coverage"
inputs:
summaryFileLocation: '$(Agent.TempDirectory)\**\coverage.cobertura.xml'
- task: DotNetCoreCLI@2
displayName: "Pack COA.Goldfish MCP Server"
inputs:
command: "pack"
packagesToPack: "COA.Goldfish.McpServer/COA.Goldfish.McpServer.csproj"
configuration: $(buildConfiguration)
packDirectory: "$(Build.ArtifactStagingDirectory)/packages"
nobuild: true
versioningScheme: "off"
arguments: "$(versionArguments) --no-restore"
- task: DotNetCoreCLI@2
displayName: "Pack COA.Goldfish Migration Tool"
inputs:
command: "pack"
packagesToPack: "COA.Goldfish.Migration/COA.Goldfish.Migration.csproj"
configuration: $(buildConfiguration)
packDirectory: "$(Build.ArtifactStagingDirectory)/packages"
nobuild: true
versioningScheme: "off"
arguments: "$(versionArguments) --no-restore"
- powershell: |
Write-Host "Generated NuGet packages:"
Write-Host "========================="
$packagesPath = "$(Build.ArtifactStagingDirectory)/packages"
if (Test-Path $packagesPath) {
Get-ChildItem -Path $packagesPath -Filter "*.nupkg" | ForEach-Object {
Write-Host "$($_.Name) - Size: $([math]::Round($_.Length / 1MB, 2)) MB"
}
} else {
Write-Host "Packages directory not found at: $packagesPath"
}
Write-Host "========================="
displayName: "List generated packages"
- task: PublishBuildArtifacts@1
displayName: "Publish artifacts"
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/packages'
ArtifactName: "packages"
publishLocation: "Container"
- stage: PublishInternal
displayName: "Publish to Azure DevOps"
dependsOn: Build
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
jobs:
- job: PublishToAzureDevOps
displayName: "Publish to COA Feed"
steps:
- task: DownloadBuildArtifacts@1
displayName: "Download artifacts"
inputs:
buildType: "current"
downloadType: "single"
artifactName: "packages"
downloadPath: "$(System.ArtifactsDirectory)"
- task: NuGetCommand@2
displayName: "Push packages to COA Azure DevOps feed"
inputs:
command: 'push'
packagesToPush: '$(System.ArtifactsDirectory)/packages/*.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: 'COA'
allowPackageConflicts: true
- stage: PublishNuGetOrg
displayName: "Publish to NuGet.org"
dependsOn: PublishInternal
condition: and(succeeded(), eq(variables['shouldPublishToNuGet'], 'true'), eq(variables['isRelease'], 'true'))
jobs:
- job: PublishToNuGetOrg
displayName: "Publish to NuGet.org"
steps:
- task: DownloadBuildArtifacts@1
displayName: "Download artifacts"
inputs:
buildType: "current"
downloadType: "single"
artifactName: "packages"
downloadPath: "$(System.ArtifactsDirectory)"
- powershell: |
Write-Host "Packages to publish to NuGet.org:"
Write-Host "================================="
$packagesPath = "$(System.ArtifactsDirectory)/packages"
if (Test-Path $packagesPath) {
Get-ChildItem -Path $packagesPath -Filter "*.nupkg" | ForEach-Object {
Write-Host $_.Name
}
} else {
Write-Host "Packages directory not found at: $packagesPath"
}
Write-Host "================================="
displayName: "List packages to publish"
- task: NuGetCommand@2
displayName: "Push COA.Goldfish.McpServer to NuGet.org"
inputs:
command: 'push'
packagesToPush: '$(System.ArtifactsDirectory)/packages/COA.Goldfish.McpServer.*.nupkg'
nuGetFeedType: 'external'
publishFeedCredentials: 'NuGetOrg-ServiceConnection'
verbosityPush: 'Detailed'
- task: NuGetCommand@2
displayName: "Push COA.Goldfish.Migration to NuGet.org"
inputs:
command: 'push'
packagesToPush: '$(System.ArtifactsDirectory)/packages/COA.Goldfish.Migration.*.nupkg'
nuGetFeedType: 'external'
publishFeedCredentials: 'NuGetOrg-ServiceConnection'
verbosityPush: 'Detailed'
- powershell: |
Write-Host "Successfully published COA.Goldfish packages to NuGet.org!"
Write-Host "Packages should appear at:"
Write-Host "- https://www.nuget.org/packages/COA.Goldfish.McpServer"
Write-Host "- https://www.nuget.org/packages/COA.Goldfish.Migration"
displayName: "Publish success message"
- stage: CreateGitTag
displayName: "Create Git Tag"
dependsOn: PublishNuGetOrg
condition: and(succeeded(), eq(variables['shouldCreateTag'], 'true'), eq(variables['isRelease'], 'true'))
jobs:
- job: CreateTag
displayName: "Create Git Tag"
steps:
- checkout: self
persistCredentials: true
clean: true
- powershell: |
$version = "$(versionPrefix)"
if ("$(versionSuffix)") {
$version = "$(versionPrefix)-$(versionSuffix)"
}
$tagName = "v$version"
Write-Host "Creating tag: $tagName"
git config user.name "Azure DevOps Build"
git config user.email "build@coateam.dev"
git tag -a $tagName -m "Release $version - .NET Migration"
git push origin $tagName
Write-Host "Successfully created and pushed tag: $tagName"
displayName: "Create and push git tag"