forked from MuttData/muttlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
171 lines (157 loc) · 4.45 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
image: python:3.7
variables:
POETRY_CACHE_DIR: "$CI_PROJECT_DIR/.cache/poetry"
NOX_ENV_DIR: "$CI_PROJECT_DIR/.nox"
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
cache:
paths:
- .cache/poetry
- .nox
- .cache/pip
key:
files:
- poetry.lock
- .gitlab-ci.yml
prefix: ${CI_PROJECT_ID}
before_script:
- apt-get update
- apt-get install -y libkrb5-dev libsasl2-dev
- pip install poetry
stages:
- validate
- test_stage
- version_stage
- release_stage
- deploy_stage
test:
stage: test_stage
script:
- poetry install -vvv
- poetry run python -c 'from muttlib import dbconn, utils'
- poetry install -E forecast -vvv
- poetry run python -c 'from muttlib import forecast'
- poetry install -E gsheets -vvv
- poetry run python -c 'from muttlib import gsheetsconn'
- poetry install -E gdrive -vvv
- poetry run python -c 'from muttlib import gdrive'
- poetry run nox --envdir $NOX_ENV_DIR --sessions tests -- -n 2
only:
refs:
- merge_requests
- master
lint:
stage: test_stage
script:
- poetry install -vvv
- poetry run nox --envdir $NOX_ENV_DIR --sessions precommit_hooks
only:
refs:
- merge_requests
- master
docstr-cov:
stage: test_stage
script:
- poetry install
- poetry run interrogate muttlib -c pyproject.toml -vv --generate-badge docs_coverage.svg --badge-style flat
artifacts:
paths:
- docs_coverage.svg
expire_in: 365 days
only:
refs:
- merge_requests
- master
bandit:
stage: test_stage
script:
- poetry install
- poetry run nox --envdir $NOX_ENV_DIR --sessions bandit
only:
refs:
- merge_requests
- master
pages:
stage: deploy_stage
script:
- poetry install -E all
- cd docs
- poetry run make html -e SPHINXOPTS=-W
- cd ..
- mv docs/build/html/ public/
artifacts:
paths:
- public
only:
refs:
- master
# Deploy from master to package registry
# If PYPI_USERNAME/PYPI_PASSWORD are not set, defaults to gitlab
# package registry, thus using the required variables to do so
# The package will be uploaded to PYPI_URL, which can be overrided
# not to upload to gitlab's PYPI
deploy:
stage: deploy_stage
script:
- export PYPI_USERNAME=${PYPI_USERNAME:=gitlab-ci-token}
- export PYPI_PASSWORD=${PYPI_PASSWORD:=$CI_JOB_TOKEN}
- poetry config repositories.deploy-repo ${PYPI_URL:=https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/packages/pypi}
- poetry publish --build -r deploy-repo -u ${PYPI_USERNAME} -p ${PYPI_PASSWORD}
only:
refs:
- master
tag_release_version:
stage: version_stage
script:
- echo "TAG=v$(grep current_version .bumpversion.cfg | cut -d= -f2 | xargs)" >> variables.env
artifacts:
reports:
dotenv: variables.env
before_script:
- ''
only:
refs:
- master
release:
stage: release_stage
image: registry.gitlab.com/gitlab-org/release-cli:latest
needs:
- job: tag_release_version
artifacts: true
release:
tag_name: '$TAG'
description: './CHANGELOG.md'
script:
- echo 'running release job for $TAG'
before_script:
- ''
only:
refs:
- master
check_version:
stage: validate
script:
- pip install packaging
- git fetch origin $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
- git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
- lib_ver=$(git diff origin/$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME -- .bumpversion.cfg | grep "current_version" | cut -d = -f 2 | xargs)
- python -c "import sys; from packaging import version; exit(not version.parse(sys.argv[1]) > version.parse(sys.argv[2]))" $lib_ver
- exit_status=$?
- if [ $exit_status -eq 1 ]; then echo "Error comparing versions"; fi;
- exit $exit_status
only:
refs:
- merge_requests
variables:
- $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"
check_changelog:
stage: validate
script:
- git fetch origin $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
- git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
- added_lines=$(git diff --numstat origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME origin/$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME -- CHANGELOG.md | awk '{print $1}')
- if [ -z $added_lines ] || [ $added_lines -eq 0 ]; then echo "Changelog has not been modified" && exit 1; else echo "Changelog has been modified" && exit 0; fi;
only:
refs:
- merge_requests
variables:
- $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"