-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig.yml
201 lines (190 loc) · 7.16 KB
/
config.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
version: 2.1
parameters:
primary-python-version:
type: string
default: "3.11.0"
commands:
setup_pip:
description: "Set Up Dependencies"
parameters:
python-version:
type: string
install-docs:
description: Install docs dependencies
type: boolean
default: false
steps:
- restore_cache:
keys:
- cache-v3-{{ arch }}-python<< parameters.python-version >>-{{ checksum "requirements.txt" }}-{{ checksum "requirements-server.txt" }}-{{ checksum "requirements-dev.txt" }}-{{ checksum "requirements-experimental.txt" }}-{{ checksum "requirements-docs.txt" }}
- cache-v3-{{ arch }}-python<< parameters.python-version >>-{{ checksum "requirements.txt" }}-{{ checksum "requirements-server.txt" }}-{{ checksum "requirements-dev.txt" }}-{{ checksum "requirements-experimental.txt" }}-
- cache-v3-{{ arch }}-python<< parameters.python-version >>-{{ checksum "requirements.txt" }}-{{ checksum "requirements-server.txt" }}-{{ checksum "requirements-dev.txt" }}-
- cache-v3-{{ arch }}-python<< parameters.python-version >>-{{ checksum "requirements.txt" }}-{{ checksum "requirements-server.txt" }}-
- cache-v3-{{ arch }}-python<< parameters.python-version >>-{{ checksum "requirements.txt" }}-
- cache-v3-{{ arch }}-python<< parameters.python-version >>-
- run:
name: Install Dependencies
command: |
python -m venv ~/venv
. ~/venv/bin/activate
# Ensure pip is up-to-date
pip install --upgrade pip
pip install .[server,dev] --no-binary lxml
pip install -r requirements-experimental.txt
# Docs dependencies are only compatible on Python 3.10+, so only install
# them on demand.
- when:
condition: << parameters.install-docs >>
steps:
- run:
command: |
. ~/venv/bin/activate
pip install -r requirements-docs.txt
- save_cache:
key: cache-v3-{{ arch }}-python<< parameters.python-version >>-{{ checksum "requirements.txt" }}-{{ checksum "requirements-server.txt" }}-{{ checksum "requirements-dev.txt" }}-{{ checksum "requirements-experimental.txt" }}-{{ checksum "requirements-docs.txt" }}
paths:
- ~/venv
jobs:
test:
parameters:
python-version:
type: string
working_directory: ~/web-monitoring-diff
docker:
- image: cimg/python:<< parameters.python-version >>
steps:
- checkout
- setup_pip:
python-version: << parameters.python-version >>
- run:
name: Tests
command: |
. ~/venv/bin/activate
coverage run -m pytest -vv
- run:
name: Coverage
command: |
. ~/venv/bin/activate
coverage report -m
lint:
working_directory: ~/web-monitoring-diff
docker:
- image: cimg/python:<< pipeline.parameters.primary-python-version >>
steps:
- checkout
- setup_pip:
python-version: << pipeline.parameters.primary-python-version >>
- run:
name: Code linting
command: |
. ~/venv/bin/activate
flake8 .
build_docker:
machine:
image: ubuntu-2004:202111-02
steps:
- checkout
- run: |
docker build -t envirodgi/web-monitoring-diff:${CIRCLE_SHA1} .
- run:
name: Save Image
command: |
mkdir /tmp/workspace
docker save --output /tmp/workspace/docker-image envirodgi/web-monitoring-diff:${CIRCLE_SHA1}
- persist_to_workspace:
root: /tmp/workspace
paths:
- docker-image
publish_docker:
machine:
image: ubuntu-2004:202111-02
steps:
- attach_workspace:
at: /tmp/workspace
- run:
name: Load Built Docker Image
command: docker load --input /tmp/workspace/docker-image
- run:
name: Docker Login
command: docker login -u $DOCKER_USER -p $DOCKER_PASS
# TODO: Drop these SHA-tagged builds in favor of just release numbers.
# We maintain them for now for compatibility w/ a previous release style.
- run:
name: Publish Commit-SHA-Tagged Image
command: docker push envirodgi/web-monitoring-diff:${CIRCLE_SHA1}
- run:
name: Publish Version-Tagged Image
command: |
# Sanity-check that we are dealing with an actual release tag.
if [ -z "${CIRCLE_TAG}" ]; then
echo 'There is no git tag to use!'
else
# Re-tag the Docker image with the current version number, which
# is based on the current git tag ($CIRCLE_TAG).
docker image tag \
envirodgi/web-monitoring-diff:${CIRCLE_SHA1} \
envirodgi/web-monitoring-diff:${CIRCLE_TAG:1}
docker push envirodgi/web-monitoring-diff:${CIRCLE_TAG:1}
fi
- run:
name: Publish :latest Tag If Final Release
command: |
# Skip tags with additional info after "v0.0.0", e.g. "v1.0.0a1"
# NOTE: the version of grep on Circle needs -P (perl-style regex)
# instead of -E (extended regex) to support `\d`.
FINAL_VERSION="$(
echo "${CIRCLE_TAG}" |
grep -P '^v\d+(\.\d+)+$' ||
true
)"
if [ -z "${FINAL_VERSION}" ]; then
echo 'The current tag does not represent a final release!'
echo 'Not publishing a ":latest" tag.'
else
docker image tag \
envirodgi/web-monitoring-diff:${CIRCLE_SHA1} \
envirodgi/web-monitoring-diff:latest
docker push envirodgi/web-monitoring-diff:latest
fi
# TODO: Publish to PyPI from CircleCI for version tags, similar to Docker.
# publish_pypi:
workflows:
build:
jobs:
# NOTE: because publishing runs on tags, we have to make sure all jobs
# it depends on also run on tags (by default, jobs do not run on tags,
# only branches).
#
# Also: {filters: {tags: {only: ...}}} may look deceiving, like it's only
# running for the tags. But what's actually happening here is that
# branches aren't being filtered (only tags are), so it's running for
# *all* branches and also for tags that start with "v".
#
# See more in:
# https://circleci.com/docs/2.0/workflows/#executing-workflows-for-a-git-tag
- test:
filters:
tags:
only: /^v.*/
matrix:
parameters:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
- lint:
filters:
tags:
only: /^v.*/
- build_docker:
filters:
tags:
only: /^v.*/
# Publishing only happens for tags starting with "v", and no branches.
- publish_docker:
requires:
- test
- lint
- build_docker
filters:
branches:
ignore: /.*/
tags:
only: /^v.*/