-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy path.gitlab-ci.yml
361 lines (345 loc) · 12.5 KB
/
.gitlab-ci.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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# This is a simple gitlab continuous integration example project (compatible with the shared runner provided on gitlab.com)
# using the official debian linux based dotnet docker image to build a .NET Core project.
#
# MyProject.sln
# MyProject\
# MyProject.csproj (console application)
# MyProject.Test\
# MyProject.Test.csproj (test library)
#
# Please find the full example project here:
# https://gitlab.com/tobiaskoch/gitlab-ci-example-dotnetcore
# see https://hub.docker.com/r/microsoft/dotnet/
image: mcr.microsoft.com/dotnet/sdk:3.1
variables:
NUGET_PACKAGES_DIRECTORY: '.nupkg'
RESHARPER_CLI_NAME: 'JetBrains.ReSharper.CommandLineTools.Unix'
RESHARPER_CLI_VERSION: "2019.2.3"
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- .nupkg
.only-default: &only-default
only:
- merge_requests
stages:
- test
- deploy
- quality
unit_test_db_mssql:
variables:
GIT_SUBMODULE_STRATEGY: recursive
ACCEPT_EULA: Y
SA_PASSWORD: yourStrong(!)Password
stage: test
services:
- name: mcr.microsoft.com/mssql/server:2019-latest
alias: localhost_mssql
rules:
- if: '$DATABASE_DISABLED || $DATABASE_MSSQL_DISABLED'
when: never
- if: '$CI_COMMIT_BRANCH == "master"'
when: manual
allow_failure: true
- if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
allow_failure: true
# rules:
# - if: '$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /^feature/ && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"' # This rule will be evaluated
before_script:
- 'ls'
- 'cp ${CI_PROJECT_DIR}/MyProject.Api/appsettings-Dev.json ${CI_PROJECT_DIR}/MyProject.Api/appsettings.json'
- 'cp ${CI_PROJECT_DIR}/MyProject.Api/Properties/launchSettings-dev.json ${CI_PROJECT_DIR}/MyProject.Api/Properties/launchSettings.json'
- 'echo | dotnet --version'
- 'dotnet restore'
script:
- cd MyProject.Repository.Test
- cp ./Data/appSettings.gitlab.mssql.json ./Data/AppSettings.json
- dotnet test --logger "junit"
- cd ..
- ls -ld *.Test/TestResults/*
artifacts:
paths:
- '*.Test/TestResults/TestResults.xml'
reports:
junit:
- '*.Test/TestResults/TestResults.xml'
unit_test_db_mysql:
variables:
GIT_SUBMODULE_STRATEGY: recursive
MYSQL_DATABASE: "mockDb"
MYSQL_ROOT_PASSWORD: "mysecretpw"
stage: test
rules:
- if: '$DATABASE_DISABLED || $DATABASE_MYSQL_DISABLED'
when: never
- if: '$CI_COMMIT_BRANCH == "master"'
when: manual
allow_failure: true
- if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
when: always
services:
- name: mysql:5.7.29
alias: localhost_mysql
# rules:
# - if: '$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /^feature/ && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"' # This rule will be evaluated
before_script:
- 'ls'
- 'cp ${CI_PROJECT_DIR}/MyProject.Api/appsettings-Dev.json ${CI_PROJECT_DIR}/MyProject.Api/appsettings.json'
- 'cp ${CI_PROJECT_DIR}/MyProject.Api/Properties/launchSettings-dev.json ${CI_PROJECT_DIR}/MyProject.Api/Properties/launchSettings.json'
- 'echo | dotnet --version'
- 'dotnet restore'
script:
- cd MyProject.Repository.Test
- cp ./Data/appSettings.gitlab.mysql.json ./Data/AppSettings.json
- dotnet test --logger "junit"
- cd ..
- ls -ld *.Test/TestResults/*
artifacts:
paths:
- '*.Test/TestResults/TestResults.xml'
reports:
junit:
- '*.Test/TestResults/TestResults.xml'
unit_test_db_postgres:
variables:
GIT_SUBMODULE_STRATEGY: recursive
POSTGRES_DB: mockDb
POSTGRES_USER: postgres
POSTGRES_PASSWORD: "mysecretpassword"
POSTGRES_HOST_AUTH_METHOD: trust
stage: test
rules:
- if: '$DATABASE_DISABLED || $DATABASE_POSTGRES_DISABLED'
when: never
- if: '$CI_COMMIT_BRANCH == "master"'
when: manual
allow_failure: true
- if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
when: always
services:
- name: postgres:12.2-alpine
alias: localhost_postgres
# rules:
# - if: '$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /^feature/ && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"' # This rule will be evaluated
before_script:
- 'ls'
- 'cp ${CI_PROJECT_DIR}/MyProject.Api/appsettings-Dev.json ${CI_PROJECT_DIR}/MyProject.Api/appsettings.json'
- 'cp ${CI_PROJECT_DIR}/MyProject.Api/Properties/launchSettings-dev.json ${CI_PROJECT_DIR}/MyProject.Api/Properties/launchSettings.json'
- 'echo | dotnet --version'
- 'dotnet restore'
script:
- cd MyProject.Repository.Test
- cp ./Data/appSettings.gitlab.postgres.json ./Data/AppSettings.json
- dotnet test --logger "junit"
- cd ..
- ls -ld *.Test/TestResults/*
artifacts:
paths:
- '*.Test/TestResults/TestResults.xml'
reports:
junit:
- '*.Test/TestResults/TestResults.xml'
release:
stage: deploy
only:
- master
artifacts:
paths:
- publish/
script:
# The output path is relative to the position of the csproj-file
- dotnet publish -c Release -o ../publish MyProject/MyProject.csproj
# run unit tests, with sonarqube code quality
sonarcloud_check_master:
only:
- master
variables:
GIT_SUBMODULE_STRATEGY: recursive
stage: quality
before_script:
- apt-get update && apt-get install -qq -y openjdk-8-jre > /dev/null
- java -version
- dotnet tool install dotnet-sonarscanner --tool-path tools --version 4.10.0
- cp SonarQube.Analysis.xml tools/.store/dotnet-sonarscanner/4.10.0/dotnet-sonarscanner/4.10.0/tools/netcoreapp3.0/any/SonarQube.Analysis.xml
- dotnet tool install dotnet-reportgenerator-globaltool --tool-path tools
- 'ls tools'
- 'dotnet restore'
script:
# https://github.com/SonarSource/sonar-scanner-msbuild/blob/master/sonar-docs/analysis/scan/sonarscanner-for-msbuild.md
- ./tools/dotnet-sonarscanner begin /k:"lastlink_dotnet-ci-pipelines" /o:"lastlink" /d:sonar.login="${SONAR_TOKEN}" /d:sonar.host.url="${SONAR_HOST_URL}" /d:sonar.cs.opencover.reportsPaths="*.Test/TestResults/coverage.opencover.xml"
- dotnet test --logger "junit" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput='./TestResults/'
- ./tools/dotnet-sonarscanner end /d:sonar.login="${SONAR_TOKEN}"
- ./tools/reportgenerator "-reports:${CI_PROJECT_DIR}/**/TestResults/coverage.opencover.xml;" "-targetdir:Reports_Coverage" -reportTypes:TextSummary;
- ./tools/reportgenerator "-reports:${CI_PROJECT_DIR}/**/TestResults/coverage.opencover.xml;" "-targetdir:Reports_Coverage" -reportTypes:Html;
- ./tools/reportgenerator "-reports:${CI_PROJECT_DIR}/**/TestResults/coverage.opencover.xml;" "-targetdir:public" -reportTypes:Badges;
- ls Reports_Coverage
- cat ./Reports_Coverage/Summary.txt | grep 'Line coverage'
allow_failure: true
coverage: /Line coverage[\s\S].+%/
artifacts:
paths:
- Reports_Coverage/
- '*.Test/TestResults/TestResults.xml'
reports:
junit:
- '*.Test/TestResults/TestResults.xml'
debug:
only:
- merge_requests
cache:
paths:
- resharper
before_script:
- ls # check cache
- 'echo | dotnet --version' # must be v 2.2.300 or later for reporter tool to work
- dotnet tool install dotnet-reportgenerator-globaltool --tool-path tools
stage: test
script:
# run sqlite test
- cp MyProject.Repository.Test/Data/appSettings.gitlab.json MyProject.Repository.Test/Data/AppSettings.json
- dotnet test --logger "junit" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput='./TestResults/'
# each reporttype must be a separate line, doesn't work together ; separated
- ls -ld ${CI_PROJECT_DIR}/**/TestResults/*
- mkdir -p public
- ./tools/reportgenerator "-reports:${CI_PROJECT_DIR}/**/TestResults/coverage.opencover.xml;" "-targetdir:Reports_Coverage" -reportTypes:TextSummary;
- ./tools/reportgenerator "-reports:${CI_PROJECT_DIR}/**/TestResults/coverage.opencover.xml;" "-targetdir:Reports_Coverage" -reportTypes:Html;
- ./tools/reportgenerator "-reports:${CI_PROJECT_DIR}/**/TestResults/coverage.opencover.xml;" "-targetdir:public" -reportTypes:Badges;
- ls Reports_Coverage
- cat ./Reports_Coverage/Summary.txt | grep 'Line coverage'
coverage: /Line coverage[\s\S].+%/
artifacts:
paths:
- Reports_Coverage/
- public
reports:
junit:
- '*.Test/TestResults/TestResults.xml'
cache:
key: "${CI_PIPELINE_ID}"
paths:
- MyProject.Test/TestResults
# sonarqube only test that is ok to fail
sonarcloud_check:
only:
- merge_requests
variables:
GIT_SUBMODULE_STRATEGY: recursive
stage: quality
before_script:
- apt-get update && apt-get install -qq -y openjdk-8-jre > /dev/null
- java -version
- dotnet tool install dotnet-sonarscanner --tool-path tools --version 4.10.0
- cp SonarQube.Analysis.xml tools/.store/dotnet-sonarscanner/4.10.0/dotnet-sonarscanner/4.10.0/tools/netcoreapp3.0/any/SonarQube.Analysis.xml
- 'ls tools'
- 'dotnet restore'
script:
# https://github.com/SonarSource/sonar-scanner-msbuild/blob/master/sonar-docs/analysis/scan/sonarscanner-for-msbuild.md
- git fetch origin
- ./tools/dotnet-sonarscanner begin /k:"lastlink_dotnet-ci-pipelines" /o:"lastlink" /d:sonar.login="${SONAR_TOKEN}" /d:sonar.host.url="${SONAR_HOST_URL}" /d:sonar.cs.opencover.reportsPaths="*.Test/TestResults/coverage.opencover.xml"
- dotnet build
- ./tools/dotnet-sonarscanner end /d:sonar.login="${SONAR_TOKEN}"
allow_failure: true
cache:
key: "${CI_PIPELINE_ID}"
policy: pull
paths:
- MyProject.Test/TestResults
# takes upwards of 10 minutes, make manual, working on cache
codeclimate:
only:
- merge_requests
image: docker:latest
variables:
DOCKER_DRIVER: overlay
CONTAINER_IMAGE: codeclimate/codeclimate
CONTAINER_TAG: '0.85.2'
services:
- docker:dind
when: manual
stage: test
script:
- docker pull $CONTAINER_IMAGE
- mkdir -p CodeQuality
- docker run
--env CODECLIMATE_DEBUG=1
--env CODECLIMATE_CODE="$PWD"
--volume "$PWD":/code
--volume /var/run/docker.sock:/var/run/docker.sock
--volume /tmp/cc:/tmp/cc
$CONTAINER_IMAGE:$CONTAINER_TAG analyze -f html > CodeQuality/codeclimateReport.html
- docker run
--env CODECLIMATE_DEBUG=1
--env CODECLIMATE_CODE="$PWD"
--volume "$PWD":/code
--volume /var/run/docker.sock:/var/run/docker.sock
--volume /tmp/cc:/tmp/cc
$CONTAINER_IMAGE:$CONTAINER_TAG analyze -f json > CodeQuality/codeclimateReport.json
artifacts:
paths:
- CodeQuality/
dependencies: []
except:
variables:
- $CODE_QUALITY_DISABLED
code_docs:
only:
- merge_requests
stage: test
image: mono:latest
when: manual
script:
- apt update && apt install -y curl zip unzip
- curl -LO "https://github.com/dotnet/docfx/releases/download/v2.48/docfx.zip"
- unzip -q docfx.zip -d "docfx"
- mono ./docfx/docfx.exe
# - powershell.exe -NoP -NonI -Command "Expand-Archive '.\docfx.zip' '.\docfx\'"
artifacts:
paths:
- _site/
# should take less than 10 minutes if taking longer just cancel rerun, should use DotSettings file to exclude lib files
resharper_inspect:
only:
- merge_requests
when: manual
cache:
paths:
- resharper
stage: test
script:
- dotnet restore --packages="$NUGET_PACKAGES_DIRECTORY"
- >
if [ ! -d "resharper" ]; then
apt update && apt install -y curl zip unzip
curl -LO "https://download.jetbrains.com/resharper/ReSharperUltimate.$RESHARPER_CLI_VERSION/$RESHARPER_CLI_NAME.$RESHARPER_CLI_VERSION.zip"
unzip $RESHARPER_CLI_NAME.$RESHARPER_CLI_VERSION.zip -d "resharper"
fi
- mkdir -p CodeQuality
- files=(*.sln)
- sh resharper/inspectcode.sh "${files[0]}" --output=CodeQuality/inspectcodeReport.html --format=Html
timeout: 5m
retry: 2
artifacts:
paths:
- CodeQuality/
# only takes 1 minute to run
resharper_dup:
only:
- merge_requests
cache:
paths:
- resharper
stage: test
script:
- dotnet restore --packages="$NUGET_PACKAGES_DIRECTORY"
- >
if [ ! -d "resharper" ]; then
apt update && apt install -y curl zip unzip
curl -LO "https://download.jetbrains.com/resharper/ReSharperUltimate.$RESHARPER_CLI_VERSION/$RESHARPER_CLI_NAME.$RESHARPER_CLI_VERSION.zip"
unzip $RESHARPER_CLI_NAME.$RESHARPER_CLI_VERSION.zip -d "resharper"
fi
- mkdir -p CodeQuality
- files=(*.sln)
- sh resharper/dupfinder.sh "${files[0]}" --output=CodeQuality/dupfinderReport.html --format=Html
artifacts:
paths:
- CodeQuality/