-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.gitlab-ci.yml
143 lines (131 loc) · 4.76 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
#include:
# - remote: "https://raw.githubusercontent.com/rabbids-incubator/gitlab-pipeline-definitions/feature/dotnet-templates/dotnet/ci.yml"
image: mcr.microsoft.com/dotnet/sdk:6.0
variables:
ROOT_FOLDER: .
BUILD_SOURCEBRANCHNAME: $CI_COMMIT_BRANCH
BUILD_BUILDID: $CI_PIPELINE_ID
ACCEPT_EULA: "Y"
SA_PASSWORD: s0m3Str0ng!P@ssw0rd
stages:
- build
- pack
- test
services:
# see: https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker
- name: mcr.microsoft.com/mssql/server:2019-latest
alias: mssql
# avoid duplicate runs
# CI_PIPELINE_SOURCE=push|external_pull_request_event|schedule
workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "external_pull_request_event"'
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
- if: '$CI_PIPELINE_SOURCE == "web"'
#.dotnet_build:
build:
stage: build
script:
- env
- cd $ROOT_FOLDER
- dotnet restore
- dotnet build --no-restore --configuration Debug
# for investigation only
# see: https://hub.docker.com/_/microsoft-mssql-tools
#db_init:
# stage: build
# image: mcr.microsoft.com/mssql-tools:latest
# script:
# - /opt/mssql-tools/bin/sqlcmd -S mssql -U SA -P $SA_PASSWORD -i $PWD/scripts/mssql/db-init.sql 2>&1
#.dotnet_test_sonar:
test:
stage: test
variables:
COBERTURA_REPORT_FILEPATH: ./test/*/TestResults/*/coverage.cobertura.xml
REPORTGENERATOR_OPTIONS: -targetdir:sonarqubecoverage -reporttypes:SonarQube
SONAR_EXTRA_PARAMETERS: /d:sonar.cpd.exclusions=**/*Generated*.cs /d:sonar.coverageReportPaths=./sonarqubecoverage/SonarQube.xml
Application__IsSecuredByAzureAd: "false"
Application__IsOpenTelemetryEnabled: "true"
OpenTelemetry__Service: SampleServiceNowRestClient
OpenTelemetry__Metrics__Meter: SampleServiceNowRestClientMetrics
OpenTelemetry__Tracing__Source: SampleServiceNowRestClientTracing
OpenTelemetry__OtlpExporter__Endpoint: "http://localhost:4317"
ServiceNow__RestApi__BaseUrl: "http://localhost:3000/api/now"
ServiceNow__RestApi__Password: dummy
ServiceNow__RestApi__Username: dummy
ServiceNow__SqlServer__DataSource: mssql
ServiceNow__SqlServer__InitialCatalog: TestDB
ServiceNow__SqlServer__Password: $SA_PASSWORD
ServiceNow__SqlServer__UserId: SA
before_script:
# updates system
- apt-get update
- apt-get install -y gnupg
# installs sql server tools
- curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
- curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | tee /etc/apt/sources.list.d/msprod.list
- apt-get update
- apt-get install -y mssql-tools unixodbc-dev
# initializes a sql server database (schema + data)
- /opt/mssql-tools/bin/sqlcmd -S mssql -U SA -P $SA_PASSWORD -i $PWD/scripts/mssql/db-init.sql
# installs npm and mockoon-cli
- apt-get install -y npm
- npm install -g @mockoon/cli
# starts api mocks
- mockoon-cli start --data "$(pwd)/mocks/servicenow.json" --port 3000
- mockoon-cli list
# installs java runtime, sonar scanner and report generator tool
- apt install -y default-jre
- dotnet tool install --global dotnet-sonarscanner
- dotnet tool install --global dotnet-reportgenerator-globaltool
# adds dotnet global tool in the path
- export PATH="$PATH:/root/.dotnet/tools"
script:
- cd $ROOT_FOLDER
# runs all tests with sonar analysis
- dotnet restore
- dotnet sonarscanner begin /o:$SONAR_ORGANIZATION /k:$SONAR_PROJECTKEY /d:sonar.host.url=$SONAR_HOSTURL $SONAR_EXTRA_PARAMETERS
- dotnet test --configuration Debug --logger:"junit;LogFilePath=..\..\artifacts\{assembly}-test-result.xml;MethodFormat=Class;FailureBodyFormat=Verbose" --collect:"XPlat Code Coverage"
- reportgenerator "-reports:$COBERTURA_REPORT_FILEPATH" $REPORTGENERATOR_OPTIONS
- dotnet sonarscanner end
after_script:
- mockoon-cli stop "all"
#dependencies:
# - build
artifacts:
when: always
paths:
- ./**/*test-result.xml
- $COBERTURA_REPORT_FILEPATH
reports:
junit:
- ./**/*test-result.xml
cobertura: $COBERTURA_REPORT_FILEPATH
only:
- external_pull_requests
- main
- web
# ref. https://docs.microsoft.com/en-us/nuget/nuget-org/publish-a-package
#.dotnet_pack:
pack:
stage: build
script:
- cd $ROOT_FOLDER
- dotnet restore
- dotnet build --no-restore --configuration Release
- dotnet pack --no-build --configuration Release -o output
- ls -alrt output
- for f in output/*.nupkg; do dotnet nuget push "$f" --api-key $NUGET_APIKEY --source https://api.nuget.org/v3/index.json ; done
only:
refs:
- main
changes:
- Directory.Build.props
variables:
- $CI_PIPELINE_SOURCE == "push"
#build:
# extends: .dotnet_build
#pack:
# extends: .dotnet_pack
#test:
# extends: .dotnet_test