mirror of
https://github.com/tribufu/ServerManagers
synced 2026-06-01 09:42:39 +00:00
253 lines
No EOL
8.5 KiB
YAML
253 lines
No EOL
8.5 KiB
YAML
name: $(VersionMajor).$(VersionMinor).$(VersionBuild).$(VersionRevision)
|
|
|
|
trigger:
|
|
branches:
|
|
include:
|
|
- source
|
|
paths:
|
|
include:
|
|
- src
|
|
|
|
pool:
|
|
# vmImage: windows-latest
|
|
demands: InnoSetup
|
|
|
|
variables:
|
|
- name: ApplicationName
|
|
value: $(Build.DefinitionName)
|
|
- name: SolutionFile
|
|
value: 'src/Server-Managers.sln'
|
|
- name: ProjectFile
|
|
value: 'src/$(ApplicationName)/$(ApplicationName).csproj'
|
|
- name: BuildPlatform
|
|
value: AnyCPU
|
|
- name: BuildConfiguration
|
|
value: Release
|
|
- name: PublishFolder
|
|
value: publish
|
|
|
|
stages:
|
|
- stage: build
|
|
displayName: Build and Publish
|
|
|
|
jobs:
|
|
- job: build
|
|
displayName: Build and Publish
|
|
|
|
steps:
|
|
- task: PowerShell@2
|
|
displayName: Create AgentCapabilities Environment Variables
|
|
enabled: false
|
|
env:
|
|
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
|
|
inputs:
|
|
targetType: 'inline'
|
|
script: |
|
|
Function Get-AzureDevopsBuild() {
|
|
param(
|
|
[Parameter(Mandatory = $true)] [string]$baseUri,
|
|
[Parameter(Mandatory = $true)] [string]$accessToken,
|
|
[Parameter(Mandatory = $true)] [int]$buildId
|
|
)
|
|
|
|
try {
|
|
[Net.ServicePointManager]::SecurityProtocol = "Tls12, Tls13"
|
|
|
|
$uri = "$($baseUri)/build/builds/$($buildId)?api-version=6.0"
|
|
$headers = @{
|
|
Authorization = "Bearer $accessToken"
|
|
}
|
|
|
|
return Invoke-RestMethod -Method Get -Uri $uri -Headers $headers -UseBasicParsing
|
|
}
|
|
catch {
|
|
Write-Host -ForeGroundColor Red 'Unhandled exception occurred during agent fetch!'
|
|
Write-Host -ForegroundColor Red $_.Exception.Message
|
|
throw
|
|
}
|
|
}
|
|
|
|
Function Get-AzureDevopsAgent() {
|
|
param(
|
|
[Parameter(Mandatory = $true)] [string]$baseUri,
|
|
[Parameter(Mandatory = $true)] [string]$accessToken,
|
|
[Parameter(Mandatory = $true)] [int]$poolId,
|
|
[Parameter(Mandatory = $true)] [int]$agentId
|
|
)
|
|
|
|
try {
|
|
|
|
[Net.ServicePointManager]::SecurityProtocol = "Tls12, Tls13"
|
|
|
|
$uri = "$($baseUri)/distributedtask/pools/$($poolId)/agents/$($agentId)?api-version=6.0&includeCapabilities=true"
|
|
$headers = @{
|
|
Authorization = "Bearer $accessToken"
|
|
}
|
|
|
|
return Invoke-RestMethod -Method Get -Uri $uri -Headers $headers -UseBasicParsing
|
|
}
|
|
catch {
|
|
Write-Host -ForeGroundColor Red 'Unhandled exception occurred during agent fetch!'
|
|
Write-Host -ForegroundColor Red $_.Exception.Message
|
|
throw
|
|
}
|
|
}
|
|
|
|
Function Output-AgentCapabilities() {
|
|
param(
|
|
[Parameter(Mandatory = $true)] [PSCustomObject]$capabilities,
|
|
[Parameter(Mandatory = $true)] [string]$capabilityType
|
|
)
|
|
|
|
foreach ($capability in $capabilities.PSObject.Properties) {
|
|
$envName = "AgentCapabilities.$($capabilityType).$($capability.Name)".Replace('_', '.')
|
|
$envValue = $($capability.Value)
|
|
|
|
[System.Environment]::SetEnvironmentVariable($envName, $envValue)
|
|
}
|
|
}
|
|
|
|
[int]$BuildId = $(Build.BuildId)
|
|
[int]$AgentId = $(Agent.Id)
|
|
Write-Host "BuildId = $BuildId; AgentId = $AgentId"
|
|
|
|
$BuildData = Get-AzureDevopsBuild -baseUri "$(System.CollectionUri)$(System.TeamProject)/_apis" -accessToken $(System.AccessToken) -buildId $BuildId
|
|
Write-Host $BuildData
|
|
|
|
[int]$PoolId = $BuildData.queue.pool.id
|
|
Write-Host "PoolId = $PoolId"
|
|
|
|
$AgentData = Get-AzureDevopsAgent -baseUri "$(System.CollectionUri)_apis" -accessToken $(System.AccessToken) -poolId $PoolId -agentId $AgentId
|
|
Write-Host $AgentData
|
|
|
|
Output-AgentCapabilities -capabilities $AgentData.systemCapabilities -capabilityType 'System'
|
|
Output-AgentCapabilities -capabilities $AgentData.userCapabilities -capabilityType 'User'
|
|
pwsh: true
|
|
|
|
- task: PowerShell@2
|
|
displayName: Output Environment Variables
|
|
condition: contains(variables['system.debug'], 'true')
|
|
inputs:
|
|
targetType: 'inline'
|
|
script: '(gci env:*).GetEnumerator() | Sort-Object Name | Out-String'
|
|
pwsh: true
|
|
|
|
- task: NuGetToolInstaller@1
|
|
displayName: 'Install NuGet 4.4.1'
|
|
inputs:
|
|
versionSpec: '4.4.1'
|
|
|
|
- task: NuGetCommand@2
|
|
displayName: 'NuGet restore'
|
|
inputs:
|
|
restoreSolution: '$(SolutionFile)'
|
|
|
|
- task: PowerShell@2
|
|
displayName: 'Apply Semantic Versioning to Assemblies'
|
|
inputs:
|
|
targetType: filePath
|
|
filePath: './.azure/scripts/ApplySemanticVersioningToAssemblies.ps1'
|
|
arguments: "-applicationName $(ApplicationName) -pathToSearch '$(Build.SourcesDirectory)/src' -buildNumber $(Build.BuildNumber) -searchFilter 'AssemblyInfo.*'"
|
|
pwsh: true
|
|
|
|
- task: projectfileprops@1
|
|
displayName: 'Modify ApplicationVersion In Project File'
|
|
inputs:
|
|
path: '$(ProjectFile)'
|
|
fieldOptions: ApplicationVersion
|
|
value: '$(VersionMajor).$(VersionMinor).$(VersionBuild).%2a'
|
|
|
|
- task: projectfileprops@1
|
|
displayName: 'Modify ApplicationRevision In Project File'
|
|
inputs:
|
|
path: '$(ProjectFile)'
|
|
fieldOptions: ApplicationRevision
|
|
value: '$(VersionRevision)'
|
|
|
|
- task: VSBuild@1
|
|
displayName: 'Build $(ApplicationName) Project'
|
|
inputs:
|
|
solution: '$(ProjectFile)'
|
|
msbuildArgs: '/t:publish /p:PublishDir="$(Build.ArtifactStagingDirectory)/bin"'
|
|
platform: '$(BuildPlatform)'
|
|
configuration: '$(BuildConfiguration)'
|
|
clean: true
|
|
|
|
- task: PowerShell@2
|
|
displayName: Create Installer Script File
|
|
env:
|
|
BUILD_BUILDNUMBER: $(Build.BuildNumber)
|
|
BUILD_ARTIFACTSTAGINGDIRECTORY: $(Build.ArtifactStagingDirectory)
|
|
inputs:
|
|
targetType: 'inline'
|
|
script: |
|
|
$appVersion = $env:BUILD_BUILDNUMBER
|
|
$appVersionShort = $appVersion.Substring(0, $appVersion.LastIndexOf('.'))
|
|
$appVersionWithUnderscores = $appVersion.Replace('.', '_')
|
|
$publishPath = "$env:BUILD_ARTIFACTSTAGINGDIRECTORY\bin"
|
|
$installTextFile = '.azure/scripts/Installer.txt'
|
|
|
|
$installTextFileContent = @"
|
|
#define AppVer "$appVersionShort"
|
|
#define AppVerFull "$appVersion"
|
|
#define AppVerPath "$appVersionWithUnderscores"
|
|
#define RootPath "$publishPath"
|
|
"@
|
|
$installTextFileContent | Out-File -LiteralPath:$installTextFile -Force -Encoding ascii
|
|
pwsh: true
|
|
|
|
- task: Installer@1
|
|
displayName: 'Install Inno Setup'
|
|
enabled: false
|
|
inputs:
|
|
version: '6.0.5'
|
|
|
|
- task: Build@1
|
|
displayName: 'Build Setup File'
|
|
enabled: false
|
|
inputs:
|
|
file: .azure/scripts/ArkServerManager.iss
|
|
|
|
- task: CopyFiles@2
|
|
displayName: 'Copy Artifact Files'
|
|
inputs:
|
|
SourceFolder: '$(Build.SourcesDirectory)'
|
|
Contents: |
|
|
src/$(ApplicationName)/VersionFeed.xml
|
|
src/$(ApplicationName)/VersionFeedBeta.xml
|
|
src/$(ApplicationName)/Art\favicon.ico
|
|
src/$(ApplicationName)/Globalization\en-US\en-US.xaml
|
|
TargetFolder: '$(Build.ArtifactStagingDirectory)'
|
|
OverWrite: true
|
|
flattenFolders: true
|
|
preserveTimestamp: true
|
|
|
|
- task: PublishBuildArtifacts@1
|
|
displayName: 'Publish Artifacts'
|
|
inputs:
|
|
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
|
|
ArtifactName: '$(PublishFolder)'
|
|
|
|
- stage: deployBeta
|
|
displayName: Beta
|
|
lockBehavior: runLatest
|
|
condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/source'))
|
|
dependsOn:
|
|
- build
|
|
|
|
jobs:
|
|
- deployment: deployBeta
|
|
displayName: Deploy Beta
|
|
environment: github-servermanager-beta
|
|
|
|
- stage: deployRelease
|
|
displayName: Production
|
|
lockBehavior: runLatest
|
|
condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/source'))
|
|
dependsOn:
|
|
- deployBeta
|
|
|
|
jobs:
|
|
- deployment: deployRelease
|
|
displayName: Deploy Production
|
|
environment: github-servermanager-release |