-
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathmain.yml
More file actions
320 lines (317 loc) · 10.6 KB
/
Copy pathmain.yml
File metadata and controls
320 lines (317 loc) · 10.6 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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
---
version: 2.1
# Singularity started failing to set up on Circle circa May 2023, so those tests are currently disabled
parameters:
branch:
type: string
default: unknown
owner:
type: string
default: unknown
run_tests:
type: boolean
default: false
commands:
push-to-docker-hub:
parameters:
tag:
type: string
steps:
- run:
name: "Log in to Docker Hub"
command: docker login -u ${DOCKER_HUB_USERNAME} -p ${DOCKER_HUB_PUSH}
- run:
name: "Tag image for Docker Hub"
command: |
docker pull ${DOCKER_TAG}
docker tag ${DOCKER_TAG} fcpindi/c-pac:<< parameters.tag >>${VARIANT}
- run:
name: "Push to Docker Hub"
command: "docker push fcpindi/c-pac:<< parameters.tag >>${VARIANT}"
combine-coverage:
steps:
- run:
name: "Combining and reporting coverage"
command: |
coverage combine
coverage html --ignore-errors
configure-git-user:
steps:
- add_ssh_keys:
fingerprints:
- "e0:d6:95:7b:bf:44:ff:9c:3f:91:d5:30:57:37:3c:1f"
- run:
name: "Configuring git user"
command: |
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 78BD65473CB3BD13
curl -L https://packagecloud.io/circleci/trusty/gpgkey | sudo apt-key add -
sudo apt-get update
sudo apt-get install git -y
git config --global user.email "CMI_CPAC_Support@childmind.org"
git config --global user.name "Theodore (machine user) @ CircleCI"
create-docker-test-container:
parameters:
coverage-file:
default: .coverage.docker
description: "Filename for coverage file"
type: string
steps:
- run:
name: "Creating Docker container"
command: |
mkdir -p ~/project/test-results
docker pull ${DOCKER_TAG}
docker run -v /etc/passwd:/etc/passwd --user=$(id -u):c-pac -dit -P -e COVERAGE_FILE=<< parameters.coverage-file >> -v /home/circleci/project/test-results:/code/test-results -v /home/circleci:/home/circleci -v /home/circleci/project/CPAC/resources/configs/test_configs:/test_configs -v $PWD:/code -v $PWD/dev/circleci_data:$PWD/dev/circleci_data --workdir=/home/circleci/project --entrypoint=/bin/bash --name docker_test ${DOCKER_TAG}
get-sample-bids-data:
steps:
- run:
name: Getting Sample BIDS Data
command: |
mkdir -p /home/circleci/project/dev/circleci_data/.pytest_cache/d/bids-examples
git clone https://github.com/bids-standard/bids-examples.git /home/circleci/project/dev/circleci_data/.pytest_cache/d/bids-examples
get-singularity:
parameters:
version:
description: "Version of Singularity to clone"
type: string
default: v3.8.7
steps:
- install-singularity-requirements
- restore_cache:
keys:
- singularity-<< parameters.version >>
- run:
name: "Cloning Singularity << parameters.version >>"
command: |
if [[ ! -d singularity-<< parameters.version >> ]]
then
git clone -b << parameters.version >> https://github.com/apptainer/singularity singularity-<< parameters.version >>
fi
- save_cache:
key: singularity-<< parameters.version >>
paths:
- singularity-<< parameters.version >>
- run:
name: "Setting up Singularity"
command: |
cd singularity-<< parameters.version >>
./mconfig -p /usr/local
make -C builddir
sudo make -C builddir install
cd ..
install-singularity-requirements:
steps:
- run:
name: "Installing Singularity requirements"
# https://github.com/apptainer/apptainer/blob/release-1.1/INSTALL.md
command: |
sudo apt-get update -y && \
sudo apt-get install -y \
build-essential \
libseccomp-dev \
pkg-config \
uidmap \
squashfs-tools \
squashfuse \
fuse2fs \
fuse-overlayfs \
fakeroot \
cryptsetup \
curl wget git
run-pytest-docker:
steps:
- create-docker-test-container:
coverage-file: .coverage.docker${VARIANT}
- run:
name: Running pytest in Docker image
command: docker exec --user $(id -u) docker_test /bin/bash /code/dev/circleci_data/test_in_image.sh
set-python-version:
steps:
- restore_cache:
keys:
- pip-ci-requirements-{{ checksum "dev/circleci_data/requirements.txt" }}-3.10.10
- run:
name: "Installing CI dependencies"
command: |
yes n | pyenv install 3.10.10 || true
pyenv global 3.10.10
pip install --upgrade pip
pip install -r dev/circleci_data/requirements.txt
- save_cache:
key: pip-ci-requirements-{{ checksum "dev/circleci_data/requirements.txt" }}-3.10.10
paths:
- /opt/circleci/.pyenv/versions/3.10.10
set-up-variant:
parameters:
variant:
type: string
steps:
- run:
name: "Setting up variant"
command: |
if [[ ${CIRCLE_BRANCH} == 'main' ]]
then
TAG=latest
elif [[ ${CIRCLE_BRANCH} == 'develop' ]]
then
TAG=nightly
else
TAG=`echo ${CIRCLE_BRANCH} | sed 's/[^a-zA-Z0-9._]/-/g'`
fi
DOCKER_TAG="ghcr.io/${CIRCLE_PROJECT_USERNAME,,}/${CIRCLE_PROJECT_REPONAME,,}:${TAG,,}"
if [[ -n "<< parameters.variant >>" ]]
then
VARIANT="-<< parameters.variant >>"
fi
echo "export VARIANT=${VARIANT}" >> $BASH_ENV
DOCKER_TAG="${DOCKER_TAG}${VARIANT}"
echo "export DOCKER_TAG=${DOCKER_TAG}" >> $BASH_ENV
test-singularity-installation:
steps:
- run:
name: Testing Singularity installation
command: |
pip install -r dev/circleci_data/requirements.txt
coverage run -m pytest --capture=no --junitxml=test-results/junit.xml --continue-on-collection-errors dev/circleci_data/test_install.py
jobs:
combine-coverage:
machine:
image: ubuntu-2004:2023.04.2
steps:
- checkout
- restore_cache:
key: coverage-docker--{{ .Revision }}
# - restore_cache:
# key: coverage-singularity--{{ .Revision }}
# - restore_cache:
# key: coverage-docker-ABCD-HCP-{{ .Revision }}
# - restore_cache:
# key: coverage-singularity-ABCD-HCP-{{ .Revision }}
- restore_cache:
key: coverage-docker-lite-{{ .Revision }}
# - restore_cache:
# key: coverage-singularity-lite-{{ .Revision }}
- set-python-version
- combine-coverage
- store_artifacts:
path: htmlcov
push-branch-to-docker-hub:
parameters:
variant:
type: string
default: ""
machine:
image: ubuntu-2004:2023.04.2
resource_class: medium
steps:
- checkout
- when:
condition:
equal: [ << pipeline.parameters.owner >>, "FCP-INDI" ]
steps:
- set-up-variant:
variant: "<< parameters.variant >>"
- when:
condition:
equal: [ << pipeline.parameters.branch >>, "develop" ]
steps:
- push-to-docker-hub:
tag: nightly
pytest-docker:
parameters:
variant:
type: string
default: ""
machine:
image: ubuntu-2004:2023.04.2
resource_class: large
steps:
- checkout
- set-up-variant:
variant: "<< parameters.variant >>"
- set-python-version
- get-sample-bids-data
- run-pytest-docker
- store_test_results:
path: test-results
- save_cache:
key: coverage-docker-<< parameters.variant >>-{{ .Revision }}
paths:
- .coverage.docker
- .coverage.docker-<< parameters.variant >>
pytest-singularity:
parameters:
variant:
type: string
default: ""
machine:
image: ubuntu-2004:2023.04.2
resource_class: large
steps:
- checkout
- set-up-variant:
variant: "<< parameters.variant >>"
- set-python-version
- get-singularity
- run:
command: singularity pull cpac-singularity-image${VARIANT}.sif docker://${DOCKER_TAG}
name: "Pull Singularity image"
no_output_timeout: 1h
- test-singularity-installation
- run:
command: "SINGULARITYENV_COVERAGE_FILE=.coverage.singularity${VARIANT} singularity exec -B $PWD:/code cpac-singularity-image${VARIANT}.sif /code/dev/circleci_data/test_in_image.sh"
name: "Running unit tests in Singularity image"
- store_test_results:
path: test-results
- save_cache:
key: coverage-singularity-<< parameters.variant >>-{{ .Revision }}
paths:
- .coverage.singularity
- .coverage.singularity-<<parameters.variant >>
workflows:
version: 2
test:
jobs:
- combine-coverage:
name: "Combine coverage"
requires:
- "Test in Docker"
# - "Test in Singularity"
- "Test lite variant in Docker"
# - "Test lite variant in Singularity"
# - "Test ABCD-HCP variant in Docker"
# - "Test ABCD-HCP variant in Singularity"
# - "Test fMRIPrep-LTS variant in Docker"
- push-branch-to-docker-hub:
filters:
branches:
only:
- develop
matrix:
parameters:
variant:
- ""
- lite
# - ABCD-HCP
# - fMRIPrep-LTS
requires:
- "Combine coverage"
- pytest-docker:
name: "Test in Docker"
# - pytest-docker:
# name: "Test ABCD-HCP variant in Docker"
# variant: ABCD-HCP
# - pytest-docker:
# name: "Test fMRIPrep-LTS variant in Docker"
# variant: fMRIPrep-LTS
- pytest-docker:
name: "Test lite variant in Docker"
variant: lite
# - pytest-singularity:
# name: "Test in Singularity"
# - pytest-singularity:
# name: "Test ABCD-HCP variant in Singularity"
# variant: ABCD-HCP
# - pytest-singularity:
# name: "Test lite variant in Singularity"
# variant: lite