-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.gitlab-ci.yml
162 lines (146 loc) · 4.1 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
default:
image: condaforge/linux-anvil-cos7-x86_64:latest
stages:
- custom
- lint
- build
- test
- deploy
# === Variables ===
variables:
PACKAGE_VERSION: "0.2.10"
PYTHON_VERSION: "3.7"
# === Configurations ===
.skip-custom-pipelines:
except:
variables:
- $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 -c .
- python -m flake8 .
- python -m black --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-asyncio pytest-benchmark pytest-cov || true
- source activate test
# Run tests
- export DATA_DIR="$(realpath tests/data_dir/elaspic)"
- PKG_INSTALL_DIR=$(python -c "import web_pipeline; print(web_pipeline.__path__[0])")
- python -m pytest
-c pyproject.toml
--cov="${PKG_INSTALL_DIR}"
--cov-config=pyproject.toml
--color=yes
"tests/"
# Coverage
- mkdir coverage
- mv .coverage coverage/.coverage.all
tags:
- local
artifacts:
paths:
- coverage
# === 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 docker image
- 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 ===
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