forked from Inria-Empenn/narps_open_pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
154 lines (127 loc) · 3.91 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
## Disclaimer - This GitLab CI script allow contributors to perform CI on
# We assume the runner uses Docker as executor
# We assume that the following images are available on the system :
# - elodiegermani/open_pipeline
default:
# Run all scripts in a docker container based on this image
image: elodiegermani/open_pipeline
before_script:
# Activate conda virtual environment
- source activate neuro
# Install the narps_open python package from the source code
- pip install .
stages:
- code_quality
- testing
# Static analysis of the project's code
pylint_job:
stage: code_quality
script:
# Install pylint
- pip install pylint
# Run pylint
- pylint --exit-zero narps_open > pylint_report_narps_open.txt
- pylint --exit-zero tests > pylint_report_tests.txt
artifacts:
when: always
paths:
- pylint_report_narps_open.txt
- pylint_report_tests.txt
- todos_narps_open.txt
- todos_tests.txt
# Running tests for narps_open (except pipelines)
unit_tests-job:
stage: testing
script:
# Install pytest & coverage
- pip install pytest pytest-cov
# Run tests and produce reports
- coverage run -m pytest --junit-xml=pytest_report.xml --ignore=tests/pipelines/ tests/
- coverage report
- coverage xml
artifacts:
when: on_success
reports:
junit: pytest_report.xml
coverage_report:
coverage_format: cobertura
path: coverage.xml
rules:
# If something changed in narps_open (except in narps_open/pipelines)
- if: $CI_COMMIT_BRANCH
changes:
compare_to: 'refs/heads/main'
paths:
- 'narps_open/(?!pipelines)*'
# Running tests for pipelines
pipeline_tests-job:
stage: testing
variables:
PIPELINES_TEST_FILES : ""
#GIT_STRATEGY: clone # So that we can access the main branch for git diff purpose
script:
# Install pytest & coverage
- pip install pytest pytest-cov
- git switch main
- git switch $CI_COMMIT_BRANCH
# List test files corresponding to modified files
- |
for file in $(git diff --name-only origin/main...$CI_COMMIT_BRANCH)
do
if [[ "$file" =~ .*"pipeline".* ]]; then
echo "Modified pipeline = $file"
tmp=${file#*"team_"} # remove prefix ending in "team_"
team_id=${tmp%".py"*} # remove suffix starting with ".py"
PIPELINES_TEST_FILES="$PIPELINES_TEST_FILES tests/pipelines/test_team_$team_id.py"
fi
done
- echo "$PIPELINES_TEST_FILES"
# Run tests and produce reports
- coverage run -m pytest --junit-xml=pytest_report.xml "$PIPELINES_TEST_FILES"
- coverage report
- coverage xml
artifacts:
when: on_success
reports:
junit: pytest_report.xml
coverage_report:
coverage_format: cobertura
path: coverage.xml
rules:
# If something changed in narps_open/pipelines
- if: $CI_COMMIT_BRANCH
changes:
compare_to: 'refs/heads/main'
paths:
- 'narps_open/pipelines*'
# Running tests that changed
test_changes-job:
stage: testing
variables:
TEST_FILES : ""
#GIT_STRATEGY: clone # So that we can access the main branch for git diff purpose
script:
# Install pytest & coverage
- pip install pytest pytest-cov
- git switch main
- git switch $CI_COMMIT_BRANCH
# List test files corresponding to modified files
- TEST_FILES=$(git diff --name-only origin/main...$CI_COMMIT_BRANCH)
# Run tests and produce reports
- coverage run -m pytest --junit-xml=pytest_report.xml "$TEST_FILES"
- coverage report
- coverage xml
artifacts:
when: on_success
reports:
junit: pytest_report.xml
coverage_report:
coverage_format: cobertura
path: coverage.xml
rules:
# If something changed in narps_open/pipelines
- if: $CI_COMMIT_BRANCH
changes:
compare_to: 'refs/heads/main'
paths:
- 'tests/*'