Maui.Markup/azure-pipelines.yml

240 строки
9.0 KiB
YAML

variables:
CurrentSemanticVersionBase: '1.0.0'
PreviewNumber: $[counter(variables['CurrentSemanticVersionBase'], 1001)]
CurrentSemanticVersion: '$(CurrentSemanticVersionBase)-preview$(PreviewNumber)'
NugetPackageVersion: '$(CurrentSemanticVersion)'
NET_VERSION: '6.0.x'
RunPoliCheck: false
PathToLibrarySolution: 'src/CommunityToolkit.Maui.Markup.sln'
PathToSamplesSolution: 'samples/CommunityToolkit.Maui.Markup.Sample.sln'
PathToCommunityToolkitCsproj: 'src/CommunityToolkit.Maui.Markup/CommunityToolkit.Maui.Markup.csproj'
PathToCommunityToolkitSampleCsproj: 'samples/CommunityToolkit.Maui.Markup.Sample/CommunityToolkit.Maui.Markup.Sample.csproj'
PathToCommunityToolkitUnitTestCsproj: 'src/CommunityToolkit.Maui.Markup.UnitTests/CommunityToolkit.Maui.Markup.UnitTests.csproj'
XcodeVersion: '13.3.1'
ShouldCheckDependencies: true
trigger:
branches:
include:
- main
tags:
include:
- '*'
paths:
exclude:
- README.md
pr:
autoCancel: 'true'
branches:
include:
- main
paths:
exclude:
- README.md
schedules:
- cron: "0 0 * * *"
displayName: Daily midnight build
branches:
include:
- main
jobs:
- job: build_windows
displayName: Build Windows Library
pool:
vmImage: windows-latest
steps:
- task: UseDotNet@2
displayName: 'Install .NET SDK'
inputs:
packageType: 'sdk'
version: '$(NET_VERSION)'
- task: CmdLine@2
displayName: 'Install .NET MAUI Workload'
inputs:
script : |
dotnet --info
dotnet workload install maui
# if this is a tagged build, then update the version number
- powershell: |
$buildSourceBranch = "$(Build.SourceBranch)"
$tagVersion = $buildSourceBranch.Substring($buildSourceBranch.LastIndexOf("/") + 1)
Write-Host("Branch = $buildSourceBranch, Version = $tagVersion");
Write-Host ("##vso[task.setvariable variable=NugetPackageVersion;]$tagVersion")
displayName: Set NuGet Version to Tag Number
condition: startsWith(variables['Build.SourceBranch'], 'refs/tags/')
# if this is a PR build, then update the version number
- powershell: |
$prNumber = $env:System_PullRequest_PullRequestNumber
$commitId = "$($env:System_PullRequest_SourceCommitId)".Substring(0, 7)
$fullVersionString = "$(CurrentSemanticVersionBase)-build-$prNumber.$(Build.BuildId)+$commitId"
Write-Host("GitHub PR = $prNumber, Commit = $commitId");
Write-Host ("##vso[task.setvariable variable=NugetPackageVersion;]$fullVersionString")
Write-Host "##vso[build.updatebuildnumber]$fullVersionString"
displayName: Set NuGet Version to PR Version
condition: and(succeeded(), eq(variables['build.reason'], 'PullRequest'))
# test
- task: DotNetCoreCLI@2
displayName: 'Run Unit Tests'
inputs:
command: 'test'
projects: '$(PathToCommunityToolkitUnitTestCsproj)'
arguments: '--configuration Release --settings ".runsettings" --collect "XPlat code coverage" --logger trx --results-directory $(Agent.TempDirectory)'
publishTestResults: false
- task: PublishTestResults@2
displayName: 'Publish Test Results'
inputs:
testResultsFormat: VSTest
testResultsFiles: '**/*.trx'
searchFolder: $(Agent.TempDirectory)
- task: PublishCodeCoverageResults@1
displayName: 'Publish Code Coverage Results'
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '$(Agent.TempDirectory)/**/coverage.cobertura.xml'
failIfCoverageEmpty: true
# build sample
- task: VSBuild@1
displayName: 'Build Markup CommunityToolkit.Maui.Markup.Sample'
inputs:
solution: '$(PathToCommunityToolkitSampleCsproj)'
configuration: 'Release'
msbuildArgs: '/restore'
# pack
- task: VSBuild@1
displayName: 'Build and Pack CommunityToolkit.Maui.Markup'
inputs:
solution: '$(PathToCommunityToolkitCsproj)'
configuration: 'Release'
msbuildArgs: '/restore -t:pack -p:PackageVersion=$(NugetPackageVersion) -p:Version=$(NugetPackageVersion) -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg'
# check vulnerabilities
- powershell: |
dotnet list $(PathToLibrarySolution) package --vulnerable --include-transitive | findstr /S /c:"has the following vulnerable packages";
if ($LastExitCode -ne 1)
{
dotnet list $(PathToLibrarySolution) package --vulnerable --include-transitive;
exit 1;
}
exit 0;
displayName: 'Check Dependencies'
condition: eq(variables.ShouldCheckDependencies, true)
# publish
- task: PowerShell@2
displayName: 'Copy NuGet Packages to Staging Directory'
inputs:
targetType: 'inline'
script: |
$source = ".\src"
$filter = "nupkg"
Get-ChildItem -Path $source -Recurse | Where-Object { $_.Extension -match $filter } | Copy-Item -Destination "$(Build.ArtifactStagingDirectory)"
pwsh: true
# Sign NuGet Packages
- task: PowerShell@2
displayName: Authenticode Sign Packages
inputs:
filePath: build/Sign-Package.ps1
env:
SignClientUser: $(SignClientUser)
SignClientSecret: $(SignClientSecret)
ArtifactDirectory: $(Build.ArtifactStagingDirectory)
condition: and(succeeded(), not(eq(variables['build.reason'], 'PullRequest')), not(eq(variables['SignClientSecret'], '')), not(eq(variables['SignClientUser'], '')))
# publish the packages
- task: PublishBuildArtifacts@1
displayName: 'Publish Unsigned NuGets'
inputs:
artifactName: nuget
pathToPublish: '$(Build.ArtifactStagingDirectory)'
- job: verify_formatting_windows
displayName: Verify Code Formatting on Windows
pool:
vmImage: windows-latest
steps:
- task: UseDotNet@2
displayName: 'Install Latest .NET SDK'
inputs:
packageType: 'sdk'
version: '$(NET_VERSION)'
- powershell: dotnet workload install maui
displayName: Install Latest .NET MAUI Workload
- task: Bash@3
displayName: 'Verify Formatting'
env:
PathToSamplesSolution: $(PathToSamplesSolution)
inputs:
targetType: 'inline'
script: |
dotnet format $PathToSamplesSolution --verify-no-changes --exclude-diagnostics CA1416
status=$?
[ $status -eq 0 ] && echo "No errors found"
[ $status -ne 0 ] && echo "Formatting errors found. In the Windows Command Line, please run \`dotnet format $PathToSamplesSolution\`, then commit + push the newly formatted code"
exit $status
- job: build_macos
displayName: Build macOS Library
pool:
vmImage: macos-12
steps:
# if this is a tagged build, then update the version number
- powershell: |
$buildSourceBranch = "$(Build.SourceBranch)"
$tagVersion = $buildSourceBranch.Substring($buildSourceBranch.LastIndexOf("/") + 1)
Write-Host("Branch = $buildSourceBranch, Version = $tagVersion");
Write-Host ("##vso[task.setvariable variable=NugetPackageVersion;]$tagVersion")
displayName: Set NuGet Version to Tag Number
condition: startsWith(variables['Build.SourceBranch'], 'refs/tags/')
- task: CmdLine@2
displayName: 'Set Xcode Version'
inputs:
script: echo '##vso[task.setvariable variable=MD_APPLE_SDK_ROOT;]'/Applications/Xcode_$(XcodeVersion).app;sudo xcode-select --switch /Applications/Xcode_$(XcodeVersion).app/Contents/Developer
- task: UseDotNet@2
displayName: 'Install .NET SDK'
inputs:
packageType: 'sdk'
version: '$(NET_VERSION)'
- task: CmdLine@2
displayName: 'Install .NET MAUI workload'
inputs:
script: 'dotnet workload install maui'
- task: CmdLine@2
displayName: 'Restore NuGet Packages'
inputs:
script: 'dotnet restore $(PathToCommunityToolkitCsproj)'
- task: CmdLine@2
displayName: 'Build Community Toolkit'
inputs:
script: dotnet build $(PathToCommunityToolkitCsproj) -c Release
- task: CmdLine@2
displayName: 'Build Community Toolkit Sample'
inputs:
script: dotnet build $(PathToCommunityToolkitSampleCsproj) -c Release
- task: CmdLine@2
displayName: 'Run Unit Tests'
inputs:
script: dotnet test $(PathToCommunityToolkitUnitTestCsproj) -c Release
- task: CmdLine@2
displayName: 'Pack CommunityToolkit NuGets'
inputs:
script: 'dotnet pack -c Release $(PathToCommunityToolkitCsproj) -p:PackageVersion=$(NugetPackageVersion) --output $(Build.ArtifactStagingDirectory)/nuget -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg'