forked from dotnetcore/Magicodes.IE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines.yml
148 lines (127 loc) · 5 KB
/
azure-pipelines.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
# 代码覆盖率参考:https://docs.microsoft.com/zh-cn/azure/devops/pipelines/ecosystems/dotnet-core?view=azure-devops#collect-code-coverage
# https://www.meziantou.net/computing-code-coverage-for-a-dotnet-core-project-with-azure-devops-and-coverlet.htm
# trigger
# https://docs.microsoft.com/zh-cn/azure/devops/pipelines/build/triggers?view=azure-devops&tabs=yaml
# ReportGenerator,将Coverlet,OpenCover,dotCover,Visual Studio,NCover,Cobertura,JaCoCo,Clover,gcov或lcov生成的覆盖率报告转换为各种格式的可读报告:
# https://github.com/danielpalme/ReportGenerator
# https://danielpalme.github.io/ReportGenerator/usage.html
# specific path build
trigger:
branches:
include:
- master
- develop
- release/*
paths:
include:
- src/*
exclude:
- src/*.md
pr:
- master
- develop
pool:
# https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops&tabs=yaml
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
disable.coverage.autogenerate: 'true'
steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '6.x'
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '7.x'
# 不再进行多框架全面测试
#- task: UseDotNet@2
# inputs:
# packageType: 'sdk'
# version: '5.x'
#- task: UseDotNet@2
# inputs:
# packageType: 'sdk'
# version: '3.1.x'
#- task: UseDotNet@2
# inputs:
# packageType: 'sdk'
# version: '2.2.x'
# - task: DotNetCoreCLI@2
# inputs:
# command: 'build'
# configuration: $(BuildConfiguration)
# vstsFeed: xinlaiopencode/xinlaiopencode
# includeNuGetOrg: true
# - task: DotNetCoreCLI@2
# inputs:
# command: 'test'
# configuration: $(BuildConfiguration)
# arguments: '--logger trx --collect "XPlat Code Coverage"'
- task: PowerShell@2
displayName: Run Tests and ReportGenerator
inputs:
targetType: 'inline'
script: |
#执行单元测试
dotnet test --logger:trx --collect:"XPlat Code Coverage" --configuration $(BuildConfiguration)
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator "-reports:**\TestResults\*\coverage.cobertura.xml;**\TestResults\cobertura-coverage.xml" "-targetdir:$(System.DefaultWorkingDirectory)\coveragereport" "-reporttypes:HtmlInline_AzurePipelines_Dark;Cobertura;Badges" "-assemblyfilters:-Dapper*;-Dommel*;-Magicodes.ExporterAndImporter.AspNetCore*;-Magicodes.IE.EPPlus*;-MagicodesWebSite*"
ls coveragereport
ls TestResults
failOnStderr: true
continueOnError: true
# - task: PowerShell@2
# displayName: Run Tests and ReportGenerator
# inputs:
# targetType: 'inline'
# script: |
# ls TestResults
# dotnet tool install -g dotnet-reportgenerator-globaltool
# reportgenerator "-reports:**\TestResults\*\coverage.cobertura.xml;**\TestResults\cobertura-coverage.xml" "-targetdir:$(System.DefaultWorkingDirectory)\coveragereport" "-reporttypes:HtmlInline_AzurePipelines_Dark;Cobertura;Badges" "-assemblyfilters:-Dapper*;-Dommel*;-Magicodes.ExporterAndImporter.AspNetCore*;-MagicodesWebSite*"
# failOnStderr: true
# continueOnError: false
- task: PublishTestResults@2
displayName: 'Publish Test Results'
inputs:
testResultsFormat: 'VSTest' # Options: JUnit, NUnit, VSTest, xUnit, cTest
testResultsFiles: '**/TestResults/*.trx'
testRunTitle: API.Tests
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage report'
inputs:
codeCoverageTool: 'cobertura'
summaryFileLocation: '$(System.DefaultWorkingDirectory)\coveragereport\Cobertura.xml'
reportDirectory: '$(System.DefaultWorkingDirectory)\coveragereport'
- task: PowerShell@2
displayName: 'Package Push'
condition: eq(variables['Build.SourceBranchName'], 'master')
env:
NUGET_API_KEY: ${nugetapikey}
GITHUB_API_KEY: ${githubapikey}
inputs:
targetType: 'inline'
script: |
# 打包
Get-ChildItem -Path ./ -Recurse |
Where-Object { $_.Name.EndsWith(".csproj") -and !$_.Name.Contains("Test") } |
ForEach-Object -Process {
Write-Host $_.Name
dotnet pack $_.FullName -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg --include-source --output $(Build.ArtifactStagingDirectory) -c $(BuildConfiguration)
}
ls $(Build.ArtifactStagingDirectory)
#推包
dotnet nuget push $(Build.ArtifactStagingDirectory)\*.nupkg -k $env:NUGET_API_KEY --skip-duplicate -s https://api.nuget.org/v3/index.json
#使用gpr工具推送到GitHub
dotnet tool install -g gpr --no-cache -v q
gpr push --api-key $env:GITHUB_API_KEY $(Build.ArtifactStagingDirectory)\*.nupkg
failOnStderr: true
showWarnings: true
ignoreLASTEXITCODE: true