-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path.gitlab-ci.yml
242 lines (226 loc) · 6.59 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
# Merge-Request Pipeline
workflow:
rules:
- if: $CI_MERGE_REQUEST_IID
- if: $FORK_PIPELINE_RUN == "true"
- if: $CI_PROJECT_URL != "https://gitlab.com/nitk-nest/nest"
when: never
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
default:
tags:
- nest
image: docker:25.0.1
stages:
- validate
- build
- test
- release
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
CONTAINER_TEST_CI_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG # Image to used for running tests on CI
CONTAINER_TEST_DEFAULT_IMAGE: $CI_REGISTRY_IMAGE:$CI_DEFAULT_BRANCH # Image used for running tests on default branch
CONTAINER_DEV_IMAGE: $CI_REGISTRY_IMAGE:dev # Image to be uploaded to docker hub
DOCKERHUB_REPO: nestnitk/nest-docker
DOCKER_TLS_CERTDIR: "/certs"
FORK_PIPELINE_RUN: "false" # If pipeline runs should be allowed in fork repos
validate mr:
stage: validate
script:
- echo "Source branch -> $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME"
- echo "Target branch -> $CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
- if [[ $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME = $CI_DEFAULT_BRANCH_NAME ]]; then
echo "The source branch for the MR should not be master! Please create a new branch for your changes and create a new MR from it.";
exit 1;
fi
rules:
- if: $CI_MERGE_REQUEST_IID
# https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#making-docker-in-docker-builds-faster-with-docker-layer-caching
build docker image:
rules:
- if: $CI_MERGE_REQUEST_IID || $FORK_PIPELINE_RUN == "true"
variables:
DOCKER_SERVICES: "test"
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_TAG
variables:
DOCKER_SERVICES: "test dev"
tags:
- dind-runner
services:
- docker:25.0.1-dind
stage: build
script:
- apk add --no-cache docker-compose
- docker login -u $CI_DEPLOY_USERNAME -p $CI_DEPLOY_PASSWORD $CI_REGISTRY
- docker pull $CONTAINER_TEST_DEFAULT_IMAGE || true
- docker-compose build --no-cache $DOCKER_SERVICES
- docker images
- docker push $CONTAINER_TEST_CI_IMAGE
- if [ "$DOCKER_SERVICES" == "test dev" ]; then docker push $CONTAINER_DEV_IMAGE; fi
run style checks:
image: $CONTAINER_TEST_CI_IMAGE
stage: test
script:
- pre-commit --version
- pre-commit run --all-files
- gitlint --version
- git fetch
- gitlint --commits origin/$CI_DEFAULT_BRANCH..HEAD
run unit tests:
image: $CONTAINER_TEST_CI_IMAGE
stage: test
script:
- pip install -e .
- coverage --version
- pytest --version
- coverage run
- tar -cvf coverage_dump_${CI_JOB_NAME// /_}.tar .coverage_dump* > /dev/null
- junit2html junit_report.xml test_output.html
artifacts:
reports:
junit: junit_report.xml
paths:
- test-experiment*/
- quagga-logs*/
- frr-logs*/
- junit_report.xml
- test_output.html
- coverage_dump_*.tar
when: always
run examples:
image: $CONTAINER_TEST_CI_IMAGE
stage: test
script:
- pip install -e .
- coverage --version
- pytest --version
- >
pytest -v -o python_files="utils/run_examples.py"
-o junit_logging=all
--junitxml=junit_report.xml || exit_code=$?
- mv examples_dump/.coverage_dump* .
- tar -cvf coverage_dump_${CI_JOB_NAME// /_}.tar .coverage_dump* > /dev/null
- junit2html junit_report.xml test_output.html
- >
if [ $exit_code -ne 0 ];
then echo "Some example runs failed. Please check pytest logs";
exit 1;
fi;
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
artifacts:
reports:
junit: junit_report.xml
paths:
- examples_dump/
- junit_report.xml
- test_output.html
- coverage_dump_*.tar
when: always
run examples (manual):
extends: run examples
rules:
- if: $CI_MERGE_REQUEST_IID
when: manual
allow_failure: true
generate coverage report:
image: $CONTAINER_TEST_CI_IMAGE
stage: test
script:
- pip install -e .
- coverage --version
- cat coverage_dump_*.tar | tar xvf - -i
- coverage combine
- coverage report
- coverage xml
- coverage html
- coverage json
coverage: '/^TOTAL.+?(\d+.\d+\%)$/'
needs:
- job: run unit tests
artifacts: true
- job: run examples
optional: true
artifacts: true
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
paths:
- coverage.json
- coverage.xml
- htmlcov/
- .coverage
when: always
test docs:
image: $CONTAINER_TEST_CI_IMAGE
stage: test
script:
- git fetch --tags --force
- sh ./docs/source/_version/version.sh
- pip install .
- pip install -r docs/doc_requirements.txt
- make -C docs multiversion
- make -C docs html BUILDDIR=build/mr-docs # to get the latest docs (in MRs)
- git fetch --tags --force # Undo tag changes made in previous commands
# Create index.html file pointing to latest release docs
- TAG=$(git tag | tail -1)
- echo "<meta http-equiv=\"refresh\" content=\"0; URL=./$TAG/index.html\">" > docs/build/html/index.html
artifacts:
paths:
- docs/build
release docs:
stage: release
tags:
- nest-website
script:
- cp -rv docs/build/html/* /var/www/html/nest-docs/docs
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_COMMIT_TAG
upload to PyPI:
image: $CONTAINER_TEST_CI_IMAGE
stage: release
script:
- pip install -U build twine
- python -m build
- twine upload dist/* --verbose
rules:
- if: $CI_COMMIT_TAG
push to gitlab registry:
tags:
- dind-runner
services:
- docker:dind
stage: release
script:
- docker login -u $CI_DEPLOY_USERNAME -p $CI_DEPLOY_PASSWORD $CI_REGISTRY
- docker pull $CONTAINER_TEST_CI_IMAGE
- docker tag $CONTAINER_TEST_CI_IMAGE $CONTAINER_TEST_DEFAULT_IMAGE
- docker push $CONTAINER_TEST_DEFAULT_IMAGE
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
changes:
- "Dockerfile"
- if: $CI_COMMIT_TAG
push to docker hub:
rules:
- if: $CI_COMMIT_TAG
variables:
TAG: $DOCKERHUB_REPO:$CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
variables:
TAG: $DOCKERHUB_REPO:latest
tags:
- dind-runner
services:
- docker:dind
stage: release
script:
- docker login -u $CI_DEPLOY_USERNAME -p $CI_DEPLOY_PASSWORD $CI_REGISTRY
- docker pull $CONTAINER_DEV_IMAGE
- docker logout $CI_REGISTRY
- docker login -u $CI_DOCKERHUB_USER -p $CI_DOCKERHUB_PASS # Login to dockerhub
- docker tag $CONTAINER_DEV_IMAGE $TAG
- docker push $TAG