-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
178 lines (161 loc) · 4.44 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
image: python:3.8.5
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
PRE_COMMIT_HOME: ${CI_PROJECT_DIR}/.cache/pre-commit
# Configure postgres service (https://hub.docker.com/_/postgres/)
POSTGRES_DB: soam_db
POSTGRES_USER: soam_usr
POSTGRES_PASSWORD: soam_pass
TEST_DB_CONNSTR: "postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}"
services:
- postgres
cache:
key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
paths:
- .nox/
- .cache/pip
- apt-cache/
- ${PRE_COMMIT_HOME}
policy: pull
before_script:
- export APT_CACHE_DIR=`pwd`/apt-cache && mkdir -pv $APT_CACHE_DIR
- apt-get update -yq && apt-get -o dir::cache::archives="$APT_CACHE_DIR" upgrade -y
- apt-get install texlive-xetex texlive-fonts-recommended libpoppler-cpp-dev -y
- pip install nox
stages:
- validate
- test_stage
- version_stage
- release_stage
- deploy_stage
tests:
stage: test_stage
script:
- nox --sessions tests
only:
refs:
- merge_requests
- master
lint:
stage: test_stage
script:
- nox --sessions lint
only:
refs:
- merge_requests
- master
docstr-cov:
stage: test_stage
script:
- pip install interrogate
- interrogate soam -c pyproject.toml -vv
only:
refs:
- merge_requests
- master
bandit:
stage: test_stage
script:
- nox --sessions bandit
only:
refs:
- merge_requests
- master
pyreverse:
stage: test_stage
script:
- apt-get -qq update
- apt-get -qq install -y graphviz
- nox --sessions pyreverse
only:
refs:
- merge_requests
- master
pages:
stage: deploy_stage
script:
- pip install .[dev]
- cd documentation
- sphinx-apidoc -f -o source ../soam
- make html
- cd ..
- mv documentation/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:
- pip install twine
- python setup.py sdist bdist_wheel
- export TWINE_USERNAME=${PYPI_USERNAME:=gitlab-ci-token}
- export TWINE_PASSWORD=${PYPI_PASSWORD:=$CI_JOB_TOKEN}
- export PYPI_REPO=${PYPI_URL:=https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/packages/pypi}
- python -m twine upload --verbose --repository-url ${PYPI_REPO} dist/*
only:
refs:
- master
tag_release_version:
stage: version_stage
script:
- echo "TAG=v$(grep __version__ ./soam/__init__.py | cut -d "'" -f 2)" >> 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 -- soam/__init__.py | grep __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"