forked from lmm713281/etlbox
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path.gitlab-ci.yml
198 lines (189 loc) · 6.61 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
include:
# Release version in current branch
- .version.yml
variables:
# Opt out of telemetry (turbo and others), see https://consoledonottrack.com/
DO_NOT_TRACK: 1
# Enable debug services
CI_DEBUG_SERVICES: "true"
# Enable service network
FF_NETWORK_PER_BUILD: "true"
# Nupkg folder
NUPKG_FOLDER: ".packages"
NUGET_SOURCE: https://nuget.rapidsoft.ru/nuget/Rapidsoft-Nuget/v3/index.json
NUGETORG_SOURCE: https://api.nuget.org/v3/index.json
# All console out of dotnet should be in English
LANG: C
LCID: 1033
# Disable dotnet first time experience
DOTNET_NOLOGO: true
# Disable Husky in dotnet tools restore
HUSKY: 0
workflow:
rules:
# Avoid duplicate pipelines in merges
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9].*/
when: never
- if: $CI_COMMIT_MESSAGE =~ /^chore\(version bump\).*/
when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
variables:
PACKAGE_VERSION: "${PACKAGE_RELEASE}-merge.${CI_MERGE_REQUEST_IID}.${CI_PIPELINE_IID}"
- if: $CI_PIPELINE_SOURCE == "push" && ($CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "develop")
variables:
PACKAGE_VERSION: "${PACKAGE_RELEASE}"
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH =~ /^release\/[a-zA-Z0-9]+.*/
variables:
PACKAGE_VERSION: "${PACKAGE_RELEASE}-rc.${CI_PIPELINE_IID}"
- if: $CI_PIPELINE_SOURCE == "web" || ($CI_PIPELINE_SOURCE == "push" && $PACKAGE_VERSION == null)
variables:
# Package version "by default", from .version.yml and added current pipeline no
# (when pipeline is started on a tag, the tag name provides version number)
PACKAGE_VERSION: "${PACKAGE_RELEASE}${PACKAGE_POSTFIX}.${CI_PIPELINE_IID}"
default:
image: mcr.microsoft.com/dotnet/sdk:6.0
stages:
- build
- test
- deploy
build_job:
stage: build
script:
- echo "Building version $PACKAGE_VERSION"
- dotnet build --packages .nuget/packages/ -c Release -p:Version=$PACKAGE_VERSION
- dotnet pack --no-build -c Release -p:Version=$PACKAGE_VERSION -o $NUPKG_FOLDER --include-symbols --include-source
cache:
key: dotnet-packages-cache
paths:
- .nuget/packages/
- .tools/
unprotect: true
artifacts:
expire_in: 1 week # save gitlab server space, we copy the files we need to deploy folder later on
paths:
- "$NUPKG_FOLDER/"
test_job:
stage: test
services:
- name: mysql/mysql-server
alias: localmysql
variables:
MYSQL_ROOT_HOST: '%'
MYSQL_ROOT_PASSWORD: 'etlboxpassword'
- name: postgres
alias: localpostgres
variables:
POSTGRES_PASSWORD: 'etlboxpassword'
LANG: en_US.utf8
- name: mcr.microsoft.com/azure-sql-edge
alias: localmssql
variables:
ACCEPT_EULA: 'Y'
SA_PASSWORD: 'YourStrong@Passw0rd'
MSSQL_PID: 'Developer'
- name: clickhouse/clickhouse-server
alias: localclickhouse
variables:
CLICKHOUSE_USER: clickhouse
CLICKHOUSE_PASSWORD: Qwe123456
CLICKHOUSE_MAX_CONNECTIONS: 100
- name: krisgeus/docker-kafka
alias: kafka
variables:
ADVERTISED_LISTENERS: 'PLAINTEXT://kafka:9092,INTERNAL://localhost:9093'
LISTENERS: 'PLAINTEXT://0.0.0.0:9092,INTERNAL://0.0.0.0:9093'
SECURITY_PROTOCOL_MAP: 'PLAINTEXT:PLAINTEXT,INTERNAL:PLAINTEXT'
INTER_BROKER: 'INTERNAL'
KAFKA_CREATE_TOPICS: 'cc-event:36:1'
- name: docker:24.0.5-dind
alias: docker
command: [ "dockerd", "--tls=false", "--host=tcp://0.0.0.0:2375", "--host=unix:///var/run/docker.sock" ]
variables:
DOCKER_HOST: tcp://docker:2375
before_script:
- pushd test
- pwsh ./Set-Configuration.ps1 gitlab-ci
- popd
- dotnet tool install dotnet-reportgenerator-globaltool --tool-path .tools || true
- dotnet build --packages .nuget/packages/ -c Release -p:Version=$PACKAGE_VERSION
script:
- >
dotnet test --no-build --configuration=Release --filter="Category!=Performance" --logger="console;verbosity=detailed"
--logger="junit;LogFilePath=../artifacts/{assembly}-test-result.xml;MethodFormat=Class;FailureBodyFormat=Verbose"
--collect="XPlat Code Coverage"
after_script:
- .tools/reportgenerator "-reports:./**/*.cobertura.xml" "-targetdir:.coverage" -reportTypes:TextSummary
- cat .coverage/Summary.txt
- echo 'End Summary'
coverage: /Line coverage:[\s\S].+%/
cache:
key: dotnet-packages-cache
paths:
- .nuget/packages/
- .tools/
unprotect: true
artifacts:
when: always
paths:
- ./**/*test-result.xml
reports:
junit:
- ./**/*test-result.xml
coverage_report:
coverage_format: cobertura
path: ./**/coverage.cobertura.xml
bump_version:
stage: deploy
rules:
- if: $CI_PIPELINE_SOURCE == "push" && ($CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "develop")
script:
- git config user.email "noreply@rapidsoft.ru"
- git config user.name "Gitlab Runner"
- echo "Source branch ${CI_COMMIT_BRANCH}"
- git remote set-url origin "https://$CI_PROJECT_NAME:$CI_PROJECT_ACCESS_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git"
- git fetch --prune origin $CI_COMMIT_BRANCH
- git switch $CI_COMMIT_BRANCH
- echo "Tagging current version $PACKAGE_RELEASE"
- git tag -a "v${PACKAGE_RELEASE}" -m "Release version ${PACKAGE_RELEASE}"
- pwsh ./bump-version.ps1 $CI_COMMIT_BRANCH
- |
# Source the environment variables
if [ -f /tmp/env-vars.sh ]; then
source /tmp/env-vars.sh
fi
- echo "Pushing version changes to GIT"
- git add .version.yml
- |
if git diff-index --quiet HEAD --; then
echo "No changes to commit"
else
git commit --no-verify -m "chore(version bump): bump version to $PACKAGE_RELEASE"
fi
- git push --follow-tags origin $CI_COMMIT_BRANCH
needs:
- build_job
- test_job
publish:internal:
stage: deploy
script:
- echo "Publishing version $PACKAGE_VERSION internally to $NUGET_SOURCE"
- dotnet nuget push "$NUPKG_FOLDER/*.nupkg" --source $NUGET_SOURCE --api-key $NUGET_API_KEY
needs:
- build_job
- test_job
publish:nuget-org:
interruptible: true
stage: deploy
script:
- echo "Publishing version $PACKAGE_VERSION to nuget.org..."
- dotnet nuget push "$NUPKG_FOLDER/*.nupkg" --source $NUGETORG_SOURCE --api-key $NUGET_ORG_API_KEY
rules:
- if: $SOURCE_BRANCH == "master"
when: manual
needs:
- build_job
- test_job