This repository has been archived by the owner on Sep 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
.gitlab-ci.yml
263 lines (245 loc) · 7.2 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
image: $CEMENT_CLI_BASE_IMAGE
stages:
- prepare
- build
- test
- publish
- release
variables:
GIT_SUBMODULE_STRATEGY: recursive
NUGET_PACKAGES_DIRECTORY: '.nuget'
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_PIPELINE_SOURCE == 'push' && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_PIPELINE_SOURCE == 'web'
.tags:
tags: ['docker', $CEMENT_CLI_DOCKER_TAG]
.version:
variables:
VERSION: ${GitVersion_SemVer}
VERSION_TAG: 'v$VERSION'
.no_git:
variables:
GIT_STRATEGY: none
prepare_version:
variables:
GIT_STRATEGY: clone
GIT_DEPTH: 0 # forces gitlab CI to perform full (non-shallow) clone
stage: prepare
extends: .tags
before_script:
- dotnet tool install --tool-path /tools GitVersion.Tool --version 5.10.3
script:
- |
/tools/dotnet-gitversion /output buildserver
grep 'GitVersion_SemVer=' gitversion.properties >> version.env
artifacts:
reports:
dotenv: version.env
build:
stage: build
extends: ['.tags', '.version']
needs:
- 'prepare_version'
script:
- echo -e "${TXT_GREEN}Version = $VERSION"
- dotnet restore --packages $NUGET_PACKAGES_DIRECTORY
- dotnet build --configuration Release --no-restore
artifacts:
untracked: true
expire_in: 7 days
code_quality:
stage: test
extends: ['.tags']
needs:
- 'build'
# temporary allowing code quality check to fail because of abyssmal code quality at the moment of writing
allow_failure: true
before_script:
- |
dotnet tool install --tool-path /tools JetBrains.ReSharper.GlobalTools --version 2022.2.3
dotnet tool install --tool-path /tools resharper-to-codeclimate --version 1.0.7
script:
- /tools/jb inspectcode Cement.Cli.sln --no-build --severity=WARNING --swea --output=$CI_PROJECT_DIR/inspectcode/code-inspection.xml
- |
if [[ ! -f $CI_PROJECT_DIR/inspectcode/code-inspection.xml ]]; then
echo -e "${TXT_RED}Inspection results not found"
exit 1
fi
- /tools/resharper-to-codeclimate $CI_PROJECT_DIR/inspectcode/code-inspection.xml $CI_PROJECT_DIR/inspectcode/gl-code-quality-report.json
- |
if [[ $(grep -sc 'Issue ' $CI_PROJECT_DIR/inspectcode/code-inspection.xml) -gt 0 ]]; then
echo -e "${TXT_RED}There are code quality issues"
exit 1
else
echo -e "${TXT_GREEN}Everything is ok"
fi
artifacts:
expire_in: 7 days
paths:
- $CI_PROJECT_DIR/inspectcode/code-inspection.xml
- $CI_PROJECT_DIR/inspectcode/gl-code-quality-report.json
reports:
codequality:
- $CI_PROJECT_DIR/inspectcode/gl-code-quality-report.json
run_tests:
stage: test
extends: ['.tags', '.version']
needs:
- 'prepare_version'
- 'build'
variables:
TEST_PROJ: 'tests/Cement.Cli.Tests/Cement.Cli.Tests.csproj'
before_script:
- |
git config --global user.email "johndoe@foo.bar"
git config --global user.name "John Doe"
script:
- echo -e "${TXT_GREEN}Version = $VERSION"
- dotnet test --no-build --no-restore --configuration Release
--logger:"junit;LogFilePath=$CI_PROJECT_DIR/junit/{assembly}.xml;MethodFormat=Class;FailureBodyFormat=Verbose"
--collect:"XPlat Code Coverage" -r $CI_PROJECT_DIR/cobertura
artifacts:
expire_in: 7 days
paths:
- $CI_PROJECT_DIR/junit/*.xml
- $CI_PROJECT_DIR/cobertura/*/coverage.cobertura.xml
reports:
coverage_report:
coverage_format: cobertura
path: $CI_PROJECT_DIR/cobertura/*/coverage.cobertura.xml
junit:
- $CI_PROJECT_DIR/junit/*.xml
generate_coverage_report:
stage: test
extends: ['.tags']
needs:
- 'run_tests'
before_script:
- dotnet tool install --tool-path /tools dotnet-reportgenerator-globaltool --version 5.1.12
script:
- /tools/reportgenerator
-reports:$CI_PROJECT_DIR/cobertura/**/coverage.cobertura.xml
-targetdir:coverage
"-reporttypes:Html;Badges;TextSummary"
coverage: '/Branch coverage: (\d+(?:\.\d+)?%)/'
artifacts:
expire_in: 7 days
expose_as: 'Coverage report'
paths:
- coverage/
.package:
stage: publish
extends: .tags
needs:
- 'build'
- 'run_tests'
variables:
OUT_DIR: $CI_PROJECT_DIR/out/$TARGET_RUNTIME
TARGET_RUNTIME: $TARGET_OS-$TARGET_ARCH
script: |
cd $CI_PROJECT_DIR/src/Cement.Cli
dotnet publish -r $TARGET_RUNTIME -o $OUT_DIR /p:PublishSingleFile=true /p:DebugType=None --self-contained true
artifacts:
expire_in: 7 days
paths:
- $OUT_DIR
create_binaries:
parallel:
matrix:
- TARGET_OS: [linux, win10, osx, osx.11.0, osx.12]
TARGET_ARCH: [x64, arm64]
extends: .package
.meta_package_info:
variables:
OUTPUT_FILE: ${CI_COMMIT_SHA}.zip
PACKAGE_NAME: Cement.Cli.Meta
PACKAGE_URL: ${CEMENT_CLI_GITLAB_URL}/api/v4/projects/${CI_PROJECT_ID}/packages/generic/$PACKAGE_NAME/$VERSION/$OUTPUT_FILE
publish_meta_package:
stage: publish
extends: ['.tags', '.version', '.meta_package_info']
image: alpine:3.16
needs:
- 'prepare_version'
- 'create_binaries: [win10, x64]'
- 'create_binaries: [osx, x64]'
- 'create_binaries: [linux, x64]'
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: on_success
- when: manual
allow_failure: true
before_script:
- |
apk add --update --no-cache p7zip curl
script:
- echo -e "${TXT_GREEN}Version = $VERSION"
- cp -r ./files-common ./dotnet
- cp -r ./out/* ./dotnet
- cp ./externals/NuGet.exe ./dotnet/win10-x64/NuGet.exe
- 7z a $OUTPUT_FILE dotnet
- |
curl --header "PRIVATE-TOKEN: $CEMENT_CLI_CI_TOKEN" \
--upload-file $OUTPUT_FILE \
$PACKAGE_URL
create_release:
stage: release
extends: ['.tags', '.version', '.meta_package_info', '.no_git']
image: registry.gitlab.com/gitlab-org/release-cli:v0.14.0
needs:
- 'prepare_version'
- 'publish_meta_package'
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: on_success
- when: manual
allow_failure: true
script:
- echo -e "${TXT_GREEN}Version = $VERSION"
release:
tag_name: $VERSION_TAG
description: 'Cement CLI release $VERSION'
assets:
links:
- name: $OUTPUT_FILE
url: $PACKAGE_URL
filepath: /bin/meta
create_github_release:
stage: release
extends: ['.tags', '.version', '.meta_package_info', '.no_git']
variables:
GH_TOKEN: ${CEMENT_CLI_GH_TOKEN}
image: alpine:3.16
needs:
- 'prepare_version'
- 'publish_meta_package'
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: on_success
- when: manual
allow_failure: true
before_script:
- |
apk add --update --no-cache curl github-cli
script:
- echo -e "${TXT_GREEN}Version = $VERSION"
- |
curl --header "PRIVATE-TOKEN: $CEMENT_CLI_CI_TOKEN" -O $PACKAGE_URL
- gh release create --notes "automatic release" -R https://github.com/skbkontur/cement $VERSION_TAG $OUTPUT_FILE
pages:
stage: release
extends: ['.tags']
image: busybox:1.34
needs:
- 'generate_coverage_report'
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: on_success
- when: manual
allow_failure: true
script:
- mv coverage/ public/
artifacts:
paths:
- public