-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.gitlab-ci.yml
221 lines (202 loc) · 5.67 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
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
default:
image: condaforge/linux-anvil-cos7-x86_64:latest
stages:
- custom
- lint
- build
- test
- doc
- deploy
# === Variables ===
variables:
PACKAGE_VERSION: "0.1.12"
PYTHON_VERSION: "3.8"
# === Configurations ===
.skip-custom-pipelines:
except:
variables:
- $UPDATE_PAGES
- $BUILD_IMAGE
.configure:
extends:
- .skip-custom-pipelines
before_script:
# Set conda envs and pkgs dirs
- |
cat <<EOF > ~/.condarc
channel_priority: true
channels:
- pytorch
- conda-forge
- defaults
- kimlab
- ostrokach-forge
- bioconda
- salilab
- omnia
EOF
- conda install -yq mamba
# === Lint ===
lint:
stage: lint
extends:
- .configure
script:
- mamba create -n lint -q "python=${PYTHON_VERSION}" isort toml flake8 mypy black
- source activate lint
- python -m isort -p ${CI_PROJECT_NAME} -c .
- python -m flake8 src
- python -m black --config pyproject.toml --check .
# MyPy does not support namespace packages until this issue gets resolved:
# https://github.com/python/mypy/issues/1645
- python -m mypy src/${CI_PROJECT_NAME} || true
# === Build ===
build:
stage: build
extends:
- .configure
script:
- mamba install -yq conda conda-build conda-verify conda-forge-pinning
- cd "${CI_PROJECT_DIR}/.gitlab/conda"
- >
mamba build .
--variant-config-files /opt/conda/conda_build_config.yaml
--variants "{python: [$PYTHON_VERSION], numpy: [1.16], python_impl: [cpython]}"
--output-folder "$CI_PROJECT_DIR/conda-bld"
artifacts:
paths:
- conda-bld
# === Test ===
test:
stage: test
extends:
- .configure
script:
# Create conda environment for testing
- mamba create -n test -q -c file://${CI_PROJECT_DIR}/conda-bld --strict-channel-priority
"python=${PYTHON_VERSION}" ${CI_PROJECT_NAME} pyyaml
pytest pytest-cov python-dotenv pytest-asyncio
- source activate test
# Run tests
- PKG_INSTALL_DIR=$(python -c "import elaspic2_rest_api; print(elaspic2_rest_api.__path__[0])")
- python -m pytest
-c setup.cfg
--cov="${PKG_INSTALL_DIR}"
--cov-config=setup.cfg
--color=yes
"tests/"
# Coverage
- mkdir coverage
- mv .coverage coverage/.coverage.all
artifacts:
paths:
- coverage
# === Document ===
# NB: Has to be called "docs" for the pages script to work.
docs:
stage: doc
extends:
- .configure
script:
# Create conda environment for testing
- mamba create -n test -q -c file://${CI_PROJECT_DIR}/conda-bld --strict-channel-priority
"python=${PYTHON_VERSION}" ${CI_PROJECT_NAME} nbconvert ipython ipykernel pandoc || true
- source activate test
- pip install -q sphinx sphinx_rtd_theme msmb_theme recommonmark sphinx-markdown-tables
nbsphinx coverage
# Build docs
- sphinx-build ${CI_PROJECT_DIR}/docs public
- ln -s . public/docs
# Coverage
- coverage combine coverage/
- coverage report
- coverage html
- mv htmlcov public/
coverage: /^TOTAL.* (\d+\%)/
dependencies:
- build
- test
artifacts:
paths:
- public
when: always
# === Deploy ===
trigger-custom-pipelines:
stage: deploy
extends:
- .skip-custom-pipelines
image:
name: ubuntu:18.04
before_script:
- apt-get -y -qq update
- apt-get -y -qq install curl jq
script:
- >
BUILD_JOB_ID=$( \
curl --globoff -sS --header "PRIVATE-TOKEN: ${GITLAB_CI_TOKEN}" \
"https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/pipelines/${CI_PIPELINE_ID}/jobs?scope[]=success" \
| jq '.[] | select(.name == "build") | .id' \
)
# Update pages
- curl --request POST
--form token="${CI_JOB_TOKEN}"
--form ref=${CI_COMMIT_TAG}
--form "variables[UPDATE_PAGES]=true"
https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/trigger/pipeline
# Update images
- curl --request POST
--form token="${CI_JOB_TOKEN}"
--form ref=${CI_COMMIT_TAG}
--form "variables[BUILD_IMAGE]=true"
--form "variables[BUILD_JOB_ID]=${BUILD_JOB_ID}"
https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/trigger/pipeline
only:
- tags
# === Custom pipelines ===
pages:
stage: custom
before_script:
- sudo yum update -y -q
- sudo yum install -y -q unzip
- pip install jinja2 python-gitlab
script:
# Set environment variables
- export OUTPUT_DIR="./public"
- mkdir -p ${OUTPUT_DIR}
# Download all previous docs
- python .gitlab/pages/download_docs.py
--project-id ${CI_PROJECT_ID}
--job-name docs
--private-token ${CI_DOCS_TOKEN}
--output-dir ${OUTPUT_DIR}
artifacts:
paths:
- public
only:
variables:
- $UPDATE_PAGES
docker-images:
stage: custom
image:
name: docker:latest
services:
- docker:dind
script:
- if [[ ! -z ${CI_COMMIT_TAG} ]] ; then
IMAGE_TAG=${CI_COMMIT_TAG} ;
else
IMAGE_TAG="latest" ;
fi
- echo "${CI_REGISTRY_IMAGE}:${IMAGE_TAG}"
- if [[ ! -z ${BUILD_JOB_ID} ]] ; then
export CONDA_BLD_ARCHIVE_URL="https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/jobs/${BUILD_JOB_ID}/artifacts" ;
else
export CONDA_BLD_ARCHIVE_URL="https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/jobs/artifacts/master/download?job=build" ;
fi
- echo ${CONDA_BLD_ARCHIVE_URL}
- docker login registry.gitlab.com -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD"
- docker build --build-arg CONDA_BLD_ARCHIVE_URL -t "${CI_REGISTRY_IMAGE}:${IMAGE_TAG}" .gitlab/docker/
- docker push "${CI_REGISTRY_IMAGE}:${IMAGE_TAG}"
only:
variables:
- $BUILD_IMAGE