-
Notifications
You must be signed in to change notification settings - Fork 18
/
.azure-pipelines.yml
266 lines (261 loc) · 10.9 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
trigger:
branches:
include:
- '*'
exclude:
- 'benchmarks'
variables:
solution: 'yacep.sln'
buildConfiguration: 'Release'
dotnetCoreVersion: '6.0.302'
jobs:
- ${{ if ne(variables['Build.SourceBranchName'], 'master') }}:
- job: StatusChecksOnLinux
pool:
vmImage: 'ubuntu-22.04'
steps:
- task: UseDotNet@2
displayName: '.NET install'
inputs:
version: '$(dotnetCoreVersion)'
- task: DotNetCoreCLI@2
displayName: 'Install coverlet.console'
inputs:
command: custom
custom: tool
arguments: 'install -g coverlet.console'
- task: DotNetCoreCLI@2
displayName: 'Install dotnet-reportgenerator-globaltool'
inputs:
command: custom
custom: tool
arguments: 'install -g dotnet-reportgenerator-globaltool'
- script: dotnet test ./tests/TupacAmaru.Yacep.Test/TupacAmaru.Yacep.Test.csproj --configuration $(buildConfiguration) /p:CollectCoverage=true /p:Exclude=\"[xunit.*]*,[TupacAmaru.Yacep.Test*]*\" /p:CoverletOutputFormat=\"opencover\" /p:CoverletOutput=$(Agent.WorkFolder)/coverage/
displayName: '.NET unit tests'
- script: reportgenerator "-reports:$(Agent.WorkFolder)/coverage/coverage.opencover.xml" "-targetdir:$(Agent.WorkFolder)/coverage/reports" -reporttypes:Cobertura
displayName: 'Generate cobertura report'
- task: PublishCodeCoverageResults@1
displayName: 'Upload azure pipeline code coverage report'
inputs:
codeCoverageTool: cobertura
summaryFileLocation: $(Agent.WorkFolder)/coverage/reports/Cobertura.xml
- bash: |
set -e
minCodeCoverageValue=100
value=`cat $(Agent.WorkFolder)/coverage/coverage.opencover.xml | head -n 3 |tail -n 1 | grep -oP 'sequenceCoverage="\K([0-9.]+)'`
if [ "$value" = "$minCodeCoverageValue" ]
then
exit 0
else
echo "Line coverage is below 100%($value%)" 1>&2
exit 1
fi
failOnStderr: false
displayName: Check code coverage rate
- job: StatusChecksOnWindows
pool:
vmImage: 'windows-2019'
steps:
- task: UseDotNet@2
displayName: '.NET install'
inputs:
version: '$(dotnetCoreVersion)'
- task: DotNetCoreCLI@2
displayName: '.NET unit tests'
inputs:
command: test
publishTestResults: false
projects: '**/tests/TupacAmaru.Yacep.Test/*.csproj'
arguments: '--configuration $(buildConfiguration) --logger trx --results-directory $(Agent.WorkFolder)'
- task: PublishTestResults@2
displayName: 'Upload unit test report'
inputs:
testRunner: VSTest
testResultsFiles: '$(Agent.WorkFolder)/*.trx'
- ${{ if eq(variables['Build.SourceBranchName'], 'master') }}:
- job: Linux
pool:
vmImage: 'ubuntu-22.04'
steps:
- task: UseDotNet@2
displayName: '.NET install'
inputs:
version: '$(dotnetCoreVersion)'
- task: DotNetCoreCLI@2
displayName: 'Install coverlet.console'
inputs:
command: custom
custom: tool
arguments: 'install -g coverlet.console'
- task: DotNetCoreCLI@2
displayName: 'Install Codecov.Tool'
inputs:
command: custom
custom: tool
arguments: 'install -g Codecov.Tool'
- task: DotNetCoreCLI@2
displayName: 'Install dotnet-reportgenerator-globaltool'
inputs:
command: custom
custom: tool
arguments: 'install -g dotnet-reportgenerator-globaltool'
- task: DotNetCoreCLI@2
displayName: 'Install sonarscanner'
inputs:
command: custom
custom: tool
arguments: 'install -g dotnet-sonarscanner'
- script: dotnet sonarscanner begin /k:"tupac-amaru_yacep" /o:"tupac-amaru" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.login="$(sonarcloud.token)" /d:sonar.cs.opencover.reportsPaths="$(Agent.WorkFolder)/coverage/coverage.opencover.xml"
displayName: 'Config sonarscanner'
- task: DotNetCoreCLI@2
displayName: '.NET build'
inputs:
command: build
projects: '$(solution)'
arguments: '--configuration $(buildConfiguration)'
- script: dotnet test ./tests/TupacAmaru.Yacep.Test/TupacAmaru.Yacep.Test.csproj --configuration $(buildConfiguration) /p:CollectCoverage=true /p:Exclude=\"[xunit.*]*,[TupacAmaru.Yacep.Test*]*\" /p:CoverletOutputFormat=\"opencover\" /p:CoverletOutput=$(Agent.WorkFolder)/coverage/
displayName: '.NET unit tests'
- script: dotnet sonarscanner end /d:sonar.login="$(sonarcloud.token)"
displayName: 'Upload sonarscanner report'
- script: coverlet -f "$(Agent.WorkFolder)/coverage/coverage.opencover.xml" -t $(codecov.token)
displayName: 'Upload coverage report to coverlet'
- script: reportgenerator "-reports:$(Agent.WorkFolder)/coverage/coverage.opencover.xml" "-targetdir:$(Agent.WorkFolder)/coverage/reports" -reporttypes:Cobertura
displayName: 'Generate cobertura report'
- task: PublishCodeCoverageResults@1
displayName: 'Upload azure pipeline code coverage report'
inputs:
codeCoverageTool: cobertura
summaryFileLocation: $(Agent.WorkFolder)/coverage/reports/Cobertura.xml
- job: Windows
pool:
vmImage: 'windows-2019'
steps:
- task: UseDotNet@2
displayName: '.NET install'
inputs:
version: '$(dotnetCoreVersion)'
- task: DotNetCoreCLI@2
displayName: '.NET unit tests'
inputs:
command: test
publishTestResults: false
projects: '**/tests/TupacAmaru.Yacep.Test/*.csproj'
arguments: '--configuration $(buildConfiguration) --logger trx --results-directory $(Agent.WorkFolder)'
- task: PublishTestResults@2
displayName: 'Upload unit test report'
inputs:
testRunner: VSTest
testResultsFiles: '$(Agent.WorkFolder)/*.trx'
- job: Benchmark
pool:
vmImage: 'ubuntu-22.04'
steps:
- task: UseDotNet@2
displayName: '.NET install'
inputs:
version: '$(dotnetCoreVersion)'
- task: DotNetCoreCLI@2
displayName: '.NET build'
inputs:
command: build
projects: '**/tests/TupacAmaru.Yacep.Benchmark/*.csproj'
arguments: '--configuration $(buildConfiguration)'
- bash: |
prefix=TupacAmaru.Yacep.Benchmark.
prefixLength=${#prefix}
finishedTasks=benchmarks
readme="# This file was generated by [Azure Pipelines](https://dev.azure.com/tupac-amaru/yacep/_build/latest?definitionId=5&branchName=master)"
mkdir $(Agent.HomeDirectory)/benchmark-reports
git config --global user.name "codemonk"
git config --global user.email "[email protected]"
git init $(Agent.HomeDirectory)/benchmark-reports/
for benchmarkName in `dotnet run --project ./tests/TupacAmaru.Yacep.Benchmark --list flat`
do
realName=${benchmarkName%.*}
filename=${realName:$prefixLength}
filename=${filename:0:0-9}
if [[ $benchmarkName =~ "CompoundValue" ]]
then
if [[ $finishedTasks =~ $realName ]]; then
echo "$benchmarkName has finished in $realName"
else
echo "run benchmark for $realName"
dotnet run --project ./tests/TupacAmaru.Yacep.Benchmark \
-c Release \
--artifacts ./results/benchmark/ \
-j Dry \
--unrollFactor 4 \
--invocationCount 8 \
--warmupCount 1 \
-i true \
--strategy Throughput \
--stopOnFirstError true \
-e GitHub \
--iterationCount 200 \
--filter \*$realName\* >/dev/null
cat ./results/benchmark/results/$realName-report-github.md
readme=$readme"\n\n## $filename\n\n`cat ./results/benchmark/results/$realName-report-github.md`"
finishedTasks=$finishedTasks","$realName
fi
else
echo "run benchmark for $benchmarkName"
dotnet run --project ./tests/TupacAmaru.Yacep.Benchmark \
-c Release \
--artifacts ./results/benchmark/ \
-j Dry \
--unrollFactor 4 \
--invocationCount 8 \
--warmupCount 1 \
-i true \
--strategy Throughput \
--stopOnFirstError true \
-e GitHub \
--iterationCount 200 \
--filter \*$benchmarkName\* >/dev/null
cat ./results/benchmark/results/$realName-report-github.md
readme=$readme"\n\n## $filename\n\n`cat ./results/benchmark/results/$realName-report-github.md`"
fi
done
cd $(Agent.HomeDirectory)/benchmark-reports/
cat > README.md <<EOF
`echo -e "${readme}"`
## Thanks
Powerful .NET library for benchmarking-[BenchmarkDotNet](https://github.com/dotnet/BenchmarkDotNet)
EOF
git add README.md
git status
git commit -m "upload benchmark reports [skip ci]"
git push -f "https://$(github.pat)@github.com/tupac-amaru/yacep.git" master:_benchmark
failOnStderr: false
displayName: Generate benchmark reports
- job: Publish
dependsOn:
- Linux
- Windows
pool:
vmImage: 'ubuntu-22.04'
variables:
isPushblish: false
steps:
- bash: |
set -e
if git log --no-merges -1 --format='%B' | grep -q 'bump version'; then
echo "##vso[task.setvariable variable=isPushblish]true"
fi
exit 0
failOnStderr: true
displayName: Check if bump version commit
- task: DotNetCoreCLI@2
displayName: 'Create NuGet packages'
inputs:
command: pack
projects: '**/src/TupacAmaru.Yacep/*.csproj'
arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)/artifact'
condition: eq(variables['isPushblish'], True)
- task: NuGetCommand@2
displayName: 'Publish NuGet packages'
inputs:
command: push
nuGetFeedType: external
publishFeedCredentials: pushToNuget
condition: eq(variables['isPushblish'], True)