forked from wtclarke/fsl_mrs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
195 lines (181 loc) · 6.14 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
###########################################################################
# This file defines the build process for fsl-mrs, as hosted at:
#
# https://git.fmrib.ox.ac.uk/fsl/fsl_mrs
#
# The build pipeline currently comprises the following stages:
#
# 1. style: Check coding style - allowed to fail
#
# 2. test: Unit tests
#
# 3. validate: Fitting validation and upload fo test results
# to https://github.com/wtclarke/lcm_validation/
#
# 4. doc: Building user documentation which appears at:
# https://open.win.ox.ac.uk/pages/fsl/fsl_mrs/
#
# 5. build
# & deploy: Build conda package in three stages fsl-ci-pre,
# fsl-ci-build, fsl-ci-deploy (fsl-ci-test is not
# used in this repository).
#
#
# A custom docker image is used for the test job - images are
# available at:
#
# https://hub.docker.com/u/wtclarke/
#
# Stage run conditions:
# Style is run in all cases, but allowed to fail.
# Test is run in all cases.
# Doc is only run on master branches.
# Build stages are run according to the rules associated
# with https://git.fmrib.ox.ac.uk/fsl/conda/fsl-ci-rules
#
###########################################################################
include:
- project: fsl/conda/fsl-ci-rules
file: .gitlab-ci.yml
stages:
- style
- test
- validate
- doc
- fsl-ci-pre
- fsl-ci-build
- fsl-ci-test
- fsl-ci-deploy
####################################
# These anchors are used to restrict
# when and where jobs are executed.
# Copied from the fsl/fsleyes yaml file.
####################################
.except_releases: &except_releases
except:
- tags
.test_rules: &test_rules
rules:
# Releases are just tags on a release
# branch, so we don't need to test them.
- if: '$CI_COMMIT_TAG != null'
when: never
# Don't test if "[skip-tests]"
# is in the commit message
- if: '$CI_COMMIT_MESSAGE =~ /\[skip-tests\]/'
when: never
- if: '$CI_PIPELINE_SOURCE == "push"'
when: on_success
.validate_rules: &validate_rules
rules:
# Validate on tag / release in upstream (fsl/fsl_mrs) repo
- if: ( $CI_COMMIT_TAG != null ) && ( $CI_PROJECT_PATH == "fsl/fsl_mrs" )
when: on_success
# if "[validate]" is in the commit message
# AND it is to the forked (wclarke/fsl_mrs) repo
# AND the branch isn't master
- if: ($CI_COMMIT_MESSAGE =~ /\[validate\]/ ) && ( $CI_PROJECT_PATH == "wclarke/fsl_mrs" ) && ($CI_COMMIT_BRANCH != "master")
when: on_success
# ############
# # 1. style
# ############
flake8:
<<: *except_releases
image: python:3.12
stage: style
before_script:
- python --version
- pip install flake8
script:
- flake8 fsl_mrs
- flake8 fsl_mrs/scripts/*
allow_failure: true
############
# 2. test
############
pytest:
<<: *test_rules
image: wtclarke/fsl_mrs_tests:latest
stage: test
variables:
GIT_SUBMODULE_STRATEGY: normal
before_script:
- micromamba create -n fsl_mrs -c conda-forge -y python=3.12
- eval "$(micromamba shell hook --shell bash)"
- micromamba activate fsl_mrs
- micromamba install -y -c conda-forge -c https://fsl.fmrib.ox.ac.uk/fsldownloads/fslconda/public/ --file requirements.txt fsl-flirt fsl-flameo fsl-avwutils fsl-fugue pytest
- export FSLOUTPUTTYPE="NIFTI_GZ"
- export FSLDIR="/opt/conda/envs/fsl_mrs"
- pip install --no-deps .
script:
- pytest fsl_mrs/tests
- pytest fsl_mrs/denmatsim/tests
############
# 3. Validate
############
fit-validate:
<<: *validate_rules
image: wtclarke/fsl_mrs_tests:latest
stage: validate
variables:
GIT_STRATEGY: clone
GIT_SUBMODULE_STRATEGY: normal
DEPLOY_CURL_COMMAND_BODY: "'{\"title\":\"New FSL-MRS version\",\"body\":\"Version '$$FSL_MRS_VERSION' \",\"head\":\"fsl_mrs_updates_'$$FSL_MRS_VERSION'\",\"base\":\"main\"}'"
DEPLOY_CURL_COMMAND: 'curl -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GITHUB_PAT" https://api.github.com/repos/wtclarke/lcm_validation/pulls -d $DEPLOY_CURL_COMMAND_BODY'
before_script:
# Create an environment to work in
- micromamba create -n fsl_mrs -c conda-forge -y python=3.12
- eval "$(micromamba shell hook --shell bash)"
- micromamba activate fsl_mrs
# Install all the FSL tools needed
- micromamba install -c https://fsl.fmrib.ox.ac.uk/fsldownloads/fslconda/public/ -c conda-forge fsl-flirt fsl-flameo fsl-avwutils fsl-fugue
- export FSLOUTPUTTYPE="NIFTI_GZ"
- export FSLDIR="/opt/conda/envs/fsl_mrs"
# Get the git tags.
- git config --global --add safe.directory /builds/wclarke/fsl_mrs
- git config --global --add safe.directory /builds/fsl/fsl_mrs
- micromamba install -y -c conda-forge -c https://fsl.fmrib.ox.ac.uk/fsldownloads/fslconda/public/ --file requirements.txt
- pip install --no-deps .
# Setup ssh communication with the github instance
# https://docs.gitlab.com/ee/ci/ssh_keys/#ssh-keys-when-using-the-docker-executor
- eval $(ssh-agent -s)
- echo "$LCM_VALIDATION_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan -H github.com >> ~/.ssh/known_hosts
script:
- FSL_MRS_VERSION=${CI_COMMIT_TAG:-"$CI_COMMIT_SHORT_SHA"} && export FSL_MRS_VERSION
- echo $FSL_MRS_VERSION
- git clone git@github.com:wtclarke/lcm_validation.git
- cd lcm_validation
- git config --global user.name "wtclarke"
- git config --global user.email "william.clarke@ndcn.ox.ac.uk"
- git checkout -b "fsl_mrs_updates_${FSL_MRS_VERSION}" main
- python ../validation/mrs_challenge.py --mh_samples 20 results $FSL_MRS_VERSION
- ls results/fsl_mrs_newton
- git add *
- git commit -m "Results for FSL-MRS ${FSL_MRS_VERSION}"
- git push origin "fsl_mrs_updates_${FSL_MRS_VERSION}"
- echo $DEPLOY_CURL_COMMAND
- 'eval "$DEPLOY_CURL_COMMAND"'
allow_failure: true
############
# 4. doc
############
pages:
variables:
GIT_LFS_SKIP_SMUDGE: "1"
GIT_STRATEGY: clone
only:
- branches@wclarke/fsl_mrs
- tags@fsl/fsl_mrs
image: python:3.12
stage: doc
script:
- git describe --tag --dirty
- pip install -U sphinx sphinx_rtd_theme
- pip install --no-deps .
- sphinx-build -b html ./docs/user_docs public
artifacts:
paths:
- public