-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
298 lines (269 loc) · 8.18 KB
/
.gitlab-ci.yml
File metadata and controls
298 lines (269 loc) · 8.18 KB
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# SPDX-FileCopyrightText: 2019–2026 Pynguin Contributors
#
# SPDX-License-Identifier: MIT
image: python:${PYTHON_VERSION}
workflow:
rules:
- if: $CI_MERGE_REQUEST_ID # Execute jobs in merge request context
- if: $CI_COMMIT_BRANCH == 'main' # Execute jobs when a new commit is pushed to main branch
cache:
key: virtualenv
paths:
- .venv/
- .cache/pip
- .cache/pypoetry
stages:
- build
- lint
- test
- security
- deploy
include:
- template: Jobs/Secret-Detection.gitlab-ci.yml
secret_detection:
before_script: []
variables:
# secret detection only runs for branch pipelines by default but we run jobs
# in merge request context
AST_ENABLE_MR_PIPELINES: "true"
before_script:
- python --version
- pip install poetry
- poetry config virtualenvs.in-project true
- poetry install --extras "openai numpy fandango-faker"
.unit-tests: &unit-tests
stage: test
script:
- >
poetry run pytest -q --cov=pynguin --cov=tests --cov-branch
--cov-report=term-missing
--junitxml=report.xml tests/
- mv .coverage ".coverage.${PYTHON_VERSION}"
artifacts:
reports:
junit: report.xml
paths:
- .coverage.*
needs: ["pre-commit", "reuse"]
unit-tests:
<<: *unit-tests
parallel:
matrix:
- PYTHON_VERSION: "3.10-bookworm"
- PYTHON_VERSION: "3.11-bookworm"
- PYTHON_VERSION: "3.12-bookworm"
- PYTHON_VERSION: "3.13-bookworm"
- PYTHON_VERSION: "3.14-bookworm"
combine-coverage:
stage: test
image: python:3.10-bookworm
needs:
- job: unit-tests
artifacts: true
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
script:
- pip install coverage
- ls -la .coverage.*
- coverage combine .coverage.*
- coverage report
- coverage xml -o merged-coverage.xml
- coverage html -d cov_html
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: merged-coverage.xml
paths:
- cov_html
.nightly-tests: &nightly-tests
only:
- schedules
stage: test
before_script:
- python --version
- pip install poetry
- poetry config virtualenvs.in-project true
- poetry install --extras "openai numpy fandango-faker"
- poetry add --group dev pytest-random-order
script: |
for ((i=1; i<=10; i++)); do
SECONDS=0
echo "test run ${i}\n"
poetry run pytest -q --cov=pynguin --cov=tests --cov-branch \
--random-order --random-order-bucket=global \
--cov-report=term-missing
mv .coverage ".coverage.${PYTHON_VERSION}.${i}"
elapsed=$SECONDS
echo "=== required ${elapsed} seconds for run ${i} ===\n\n"
done
artifacts:
paths:
- .coverage.*
needs: ["unit-tests"]
nightly-tests:
<<: *nightly-tests
parallel:
matrix:
- PYTHON_VERSION: "3.10-bookworm"
- PYTHON_VERSION: "3.11-bookworm"
- PYTHON_VERSION: "3.12-bookworm"
- PYTHON_VERSION: "3.13-bookworm"
- PYTHON_VERSION: "3.14-bookworm"
combine-nightly-coverage:
only:
- schedules
stage: test
image: python:3.10-bookworm
needs:
- job: nightly-tests
artifacts: true
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
script:
- pip install coverage
- ls -la .coverage.*
- coverage combine .coverage.*
- coverage report
- coverage xml -o merged-nightly-coverage.xml
- coverage html -d cov_html_nightly
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: merged-nightly-coverage.xml
paths:
- cov_html_nightly
memory-profile:
only:
- schedules
stage: lint
image: python:3.10-bookworm
before_script:
- pip install poetry
- poetry config virtualenvs.in-project true
- poetry install --extras "openai numpy fandango-faker"
- poetry add --group dev memray pytest-memray
script:
- poetry run pytest --memray tests/
needs: ["pre-commit", "reuse"]
pre-commit:
stage: lint
image: python:3.10-bookworm
script:
- poetry run pre-commit run --all-files
needs: []
mypy:
stage: lint
image: python:3.10-bookworm
script:
- poetry run mypy --version
- poetry run mypy
needs: ["pre-commit"]
sphinx:
stage: build
image: python:3.10-bookworm
before_script: # overwrite to not install extras to be consistent with readthedocs from GitHub CI
- pip install poetry
- poetry config virtualenvs.in-project true
- poetry install
script:
- make documentation
artifacts:
expire_in: 1 week
paths:
- docs/_build
# Deploy the documentation to GitLab Pages
pages:
stage: deploy
image: python:3.10-bookworm
script:
- poetry install
- poetry run sphinx-build docs public
artifacts:
paths:
- public
only:
- main
# check license declarations etc.
reuse:
stage: lint
image:
name: fsfe/reuse:latest
entrypoint: [""]
before_script:
- python --version
script:
- reuse lint
needs: []
cluster-experiment:
stage: deploy
when: manual
image: python:3.10-bookworm
timeout: 2h
variables:
USER: "pynguin-tool"
HOST: "defender.fim.uni-passau.de"
SCRATCH: "/scratch/${USER}"
before_script:
- apt-get update && apt-get install -y sshpass openssh-client
- mkdir -p ~/.ssh
- ssh-keyscan $HOST >> ~/.ssh/known_hosts
script:
- export GIT_TAG=$(git rev-parse --short HEAD)
- |
sshpass -p "$DEFENDER_PYNGUIN_TOOL_PASSWORD" ssh -o StrictHostKeyChecking=no ${USER}@${HOST} "
echo '✅ Logged into $HOST';
bash $SCRATCH/pynguin-experiments/src/pynguin_experiments/execution/run-remote-experiment.sh \"$GIT_TAG\"
" | tee experiment.log
echo "✅ Experiment executed on $HOST."
export EXPERIMENT_DIR=$(grep '=== Parsed experiment folder:' experiment.log | awk -F': ' '{gsub(/ ===$/, "", $2); print $2}')
echo "Parsed experiment directory: $EXPERIMENT_DIR"
sshpass -p "$DEFENDER_PYNGUIN_TOOL_PASSWORD" scp -o StrictHostKeyChecking=no ${USER}@${HOST}:"$EXPERIMENT_DIR/results.csv" ./results.csv
sshpass -p "$DEFENDER_PYNGUIN_TOOL_PASSWORD" scp -o StrictHostKeyChecking=no ${USER}@${HOST}:"$EXPERIMENT_DIR/analyze-errors.csv" ./analyze-errors.csv
sshpass -p "$DEFENDER_PYNGUIN_TOOL_PASSWORD" scp -o StrictHostKeyChecking=no ${USER}@${HOST}:"$EXPERIMENT_DIR/ci-summary.md" ./ci-summary.md
sshpass -p "$DEFENDER_PYNGUIN_TOOL_PASSWORD" scp -o StrictHostKeyChecking=no ${USER}@${HOST}:"$EXPERIMENT_DIR/ci-summary.env" ./ci-summary.env
echo "✅ Results and logs copied to local directory."
if [ "${CLEANUP:-true}" = "true" ]; then
IMAGE_TAR="$SCRATCH/images/pynguin-$GIT_TAG.tar"
sshpass -p "$DEFENDER_PYNGUIN_TOOL_PASSWORD" ssh -o StrictHostKeyChecking=no ${USER}@${HOST} "
if [ -d '$EXPERIMENT_DIR' ]; then
rm -rf '$EXPERIMENT_DIR'
echo '✅ Experiment directory removed from remote (cleanup).'
else
echo '⚠️ Experiment directory not found, skipping cleanup.'
fi
if [ -f \"$IMAGE_TAR\" ]; then
rm \"$IMAGE_TAR\"
echo '✅ pynguin-image-tar file removed: $IMAGE_TAR'
else
echo '⚠️ Image not found: $IMAGE_TAR'
fi
"
else
echo "⚠️ Skipping remote cleanup."
fi
echo -e "\nSummary:\n"
cat ci-summary.md
# Load env vars and generate metrics.txt for GitLab Metrics Report
set -a
source ci-summary.env
set +a
echo "pynguin_project_count $PYNGUIN_PROJECT_COUNT" > metrics.txt
echo "pynguin_module_count $PYNGUIN_MODULE_COUNT" >> metrics.txt
echo "pynguin_total_errors $PYNGUIN_TOTAL_ERRORS" >> metrics.txt
echo "pynguin_mean_coverage $PYNGUIN_MEAN_COVERAGE" >> metrics.txt
echo "pynguin_mean_algorithm_iterations $PYNGUIN_MEAN_ALGORITHM_ITERATIONS" >> metrics.txt
echo "pynguin_mean_total_time_s $PYNGUIN_MEAN_TOTAL_TIME_S" >> metrics.txt
echo "✅ metrics.txt generated for GitLab Metrics Report."
artifacts:
when: always
reports:
dotenv: ci-summary.env
metrics: metrics.txt
paths:
- experiment.log
- results.csv
- analyze-errors.csv
- ci-summary.md
- ci-summary.env
- metrics.txt
expire_in: 1 year