forked from qarnot/qarnot-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
175 lines (151 loc) · 4.58 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
stages:
- lint
- test
- trigger
- package
variables:
MAKEFILE_PATH: $CI_PROJECT_DIR/build/Makefile
PYTHON_IMAGE: python:3.10-alpine3.15
SAMPLES_BRANCH: "master"
# Other possible variables:
# * for samples:
# - TRIGGER_SAMPLES should be set to "true" when triggering the pipeline from the web UI when you want to trigger the samples
# - PYTHON_SAMPLES_WHITELIST to specify only a set of python samples to run
# - PYTHON_SAMPLES_BLACKLIST to specify set of python samples that should not be run run
# - API_ENDPOINT for the compute api endpoint
# - API_TOKEN for the compute api user token
# - STORAGE_ENDPOINT for the storage api endpoint
default:
image: $PYTHON_IMAGE
workflow:
rules:
# Run pipelines triggered from the web UI
- if: $CI_PIPELINE_SOURCE == "web"
# Run pipelines when triggered by webhooks or by API calls (for Draft: workaround)
- if: $CI_PIPELINE_SOURCE == "trigger" || $CI_PIPELINE_SOURCE == "api"
# Do not run pipelines on *-nocheck branches, even in a MR
- if: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ /-nocheck$/
when: never
# Run pipelines on MR
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
# Run pipelines only on master branch
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
# Run pipelines on tags
- if: $CI_COMMIT_TAG
cache:
key: python-env
untracked: true
paths:
- venv
.samples_rules:
rules:
# Run pipelines triggered from the web UI
- if: $CI_PIPELINE_SOURCE == "web" && $TRIGGER_SAMPLES == "true"
# Run pipelines on tags
- if: $CI_COMMIT_TAG
# If files changed in commit or MR
- if: $CI_PIPELINE_SOURCE == "merge_request_event" || ($CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH)
changes:
paths:
- qarnot/**/*
- setup.py
.prepare-python-env:
before_script:
- if ! [[ -d venv ]]; then python3 -m venv venv; fi;
- source venv/bin/activate
- pip3 install -r requirements.txt
- pip3 install -r $EXTRA_REQUIREMENTS_FILE
.install_make_command:
before_script:
- apk add g++ && apk add make
# --- Building & Linting --- #
# There's no building for a python app
lint_python_sdk:
stage: lint
# rules:
# - !reference [.default_rules, rules]
variables:
EXTRA_REQUIREMENTS_FILE: requirements-lint.txt
before_script:
- !reference [.prepare-python-env, before_script]
- !reference [.install_make_command, before_script]
script:
- make -f $MAKEFILE_PATH lint
allow_failure: true # to have only a warning and still the tests run even if there is an unfortunate missing whitespace
# --- Testing & Coverage --- #
unit_tests_python_sdk:
stage: test
needs:
- job: lint_python_sdk
variables:
EXTRA_REQUIREMENTS_FILE: requirements-test.txt
before_script:
- !reference [.prepare-python-env, before_script]
script:
- coverage run --omit="test/*" --source=qarnot -m pytest -v --junitxml=report.xml test
- coverage xml -o coverage.xml
artifacts:
when: always
expire_in: 1hour
paths:
- report.xml
- coverage.xml
reports:
junit: report.xml
coverage_report:
coverage_format: cobertura
path: 'coverage.xml'
# Trigger samples if sdk changed
trigger_samples:
stage: trigger
needs:
- job: lint_python_sdk
rules:
- !reference [.samples_rules, rules]
variables:
PYTHON_IMAGE: python:3.10
TRIGGER_SOURCE: "sdk-python"
PYTHON_SDK_BRANCH_OR_COMMIT: "$CI_COMMIT_SHA"
SAMPLES_CONF_API_URL: $API_ENDPOINT
SAMPLES_CONF_TOKEN: $API_TOKEN
SAMPLES_CONF_STORAGE_URL: $STORAGE_ENDPOINT
trigger:
project: sdk/sdks-samples
branch: $SAMPLES_BRANCH
strategy: depend
# --- Packaging --- #
package-python-sdk:
stage: package
rules:
# Run pipelines on tags
- if: $CI_COMMIT_TAG
needs:
- unit_tests_python_sdk
- trigger_samples
variables:
EXTRA_REQUIREMENTS_FILE: requirements-doc.txt
before_script:
- !reference [.prepare-python-env, before_script]
script:
- python setup.py sdist
- echo "Sdk version:" && python -c "import qarnot; print(qarnot.__version__)"
artifacts:
paths:
- dist
expire_in: 1hour
# --- SDK Documentation generation --- #
generate-doc-python-sdk:
stage: package
needs:
- job: lint_python_sdk
variables:
EXTRA_REQUIREMENTS_FILE: requirements-doc.txt
before_script:
- !reference [.prepare-python-env, before_script]
- !reference [.install_make_command, before_script]
script:
- make -f $MAKEFILE_PATH doc
artifacts:
paths:
- doc/_build
expire_in: 1hour