-
Notifications
You must be signed in to change notification settings - Fork 17
/
.gitlab-ci.yml
128 lines (120 loc) · 4.76 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
image: docker:latest
.check-for-changes: &check-for-changes |
DOCUMENTATION_ERROR_MESSAGE="Failing pipeline build because changes were made to the API Client without generating new documentation"
DOCUMENTATION_SUCCESS_MESSAGE="Documentation properly generated"
lines=$(git status --untracked-files no -s | wc -l) #ignoring changes to these files
if [ $lines -gt 0 ]; then
echo $DOCUMENTATION_ERROR_MESSAGE && echo "git status output:" && git status && exit 1;
else
echo $DOCUMENTATION_SUCCESS_MESSAGE;
fi
services:
- docker:dind
stages:
- build-test-push-image
- generate-docs
- deploy
variables:
# GIT_SUBMODULE_STRATEGY: recursive
PYPI_PASSWORD: $PYPI_PASSWORD
PYPI_USERNAME: $PYPI_USERNAME
build-test-push-image:
stage: build-test-push-image
script:
- apk add git
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME || true
- docker build --cache-from $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME -t $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA --build-arg CM_API_KEY=$CM_API_KEY .
- docker run $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA python -m mypy -p coinmetrics -p test --install-types --non-interactive
- docker run $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA python -m flake8 coinmetrics
- docker run $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA python -m pytest -n auto --timeout=60 test --ignore test/test_data_exporter.py --ignore test/test_rate_limits.py --ignore test/test_catalog.py --ignore test/test_catalog_benchmarks.py
- docker run $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA python -m pytest test/test_rate_limits.py
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
tags:
- linux
- docker
- coinmetrics-build-runner
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
build-nix:
stage: build-test-push-image
script:
- nix -L build .#coinmetrics-api-client-py311
- nix -L build .#coinmetrics-api-client-py310
- nix -L build .#coinmetrics-api-client-py39
allow_failure: true
tags:
- kube-hel1-nix
generate-docs:
image: python:3.9-alpine
stage: generate-docs
tags:
- linux
- docker
- coinmetrics-build-runner
before_script:
# Git set up
- 'command -v ssh-agent >/dev/null || (apk add openssh-client)'
- apk add git
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- git config --global user.email "[email protected]"
- git config --global user.name "Release Bot"
- git fetch
# Python build
- apk add build-base
- python -m venv .venv
- source .venv/bin/activate
- python -m pip install --upgrade pip
- python -m pip install --upgrade regex pydoc-markdown
- python -m pip install wheel dulwich pyrsistent
- python -m pip install poetry jinja2==3.0.3 regex
- poetry lock --no-update
- poetry install
- apk add py3-dbus
- apk add bash
script:
- git checkout -b $CI_COMMIT_REF_NAME-$RANDOM origin/$CI_COMMIT_REF_NAME
- url_host=$(echo "${CI_REPOSITORY_URL}" | sed -e 's|https\?://gitlab-ci-token:.*@|ssh://git@|g')
- echo "${url_host}"
- git remote set-url --push origin "${url_host}"
- git remote show origin
- cd $CI_PROJECT_DIR
- python -m pip install pytz
- export UPDATE_VERSION=`python get_utc_update_time.py`
- echo "update version:"
- echo $UPDATE_VERSION
- bash update_version.sh $UPDATE_VERSION
- export PYTHONPATH=/ && pydoc-markdown -m coinmetrics.api_client > docs/docs/api_client.md
- cp -f README.md docs/docs/index.md
- cp -f FlatFilesExport.md docs/docs/FlatFilesExport.md
- cd docs && mkdocs build
- git add --all -- :!api-client-python/
- git status
- git commit -m "Release version $UPDATE_VERSION" || echo "No changes, nothing to commit!"
- git push --follow-tags origin HEAD:$CI_COMMIT_REF_NAME
when: manual
# rules:
# - if: $CI_COMMIT_BRANCH == "master"
deploy:
stage: deploy
dependencies:
- generate-docs
- build-test-push-image
script:
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME || true
- docker build --cache-from $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME -t $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA . --build-arg PYPI_USERNAME=$PYPI_USERNAME --build-arg PYPI_PASSWORD=$PYPI_PASSWORD
- docker run $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA python -m poetry publish --build --username $PYPI_USERNAME --password $PYPI_PASSWORD
tags:
- linux
- docker
- coinmetrics-build-runner
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
when: manual
rules:
- if: $CI_COMMIT_BRANCH == "master"