Skip to content

Commit 1ece837

Browse files
committed
Simplify CI by using Ocean orb commands
1 parent 4f0bb5a commit 1ece837

File tree

1 file changed

+54
-122
lines changed

1 file changed

+54
-122
lines changed

.circleci/config.yml

Lines changed: 54 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
version: 2.1
22

3+
orbs:
4+
ocean: dwave/[email protected]
5+
6+
environment:
7+
PIP_PROGRESS_BAR: 'off'
8+
39
jobs:
410
test-linux:
511
parameters:
@@ -8,56 +14,25 @@ jobs:
814
dimod-version:
915
type: string
1016

11-
docker:
12-
- image: circleci/python:<< parameters.python-version >>
17+
executor:
18+
name: ocean/python
19+
python-version: << parameters.python-version >>
1320

1421
steps:
1522
- checkout
1623

17-
- restore_cache: &restore-cache-env
18-
key: v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "tests/requirements.txt" }}-{{ .Environment.CIRCLE_JOB }}
24+
- ocean/pip-install:
25+
requirements: requirements.txt tests/requirements.txt
1926

20-
- run: &create-virtualenv
21-
name: Create virtual environment
22-
command: |
23-
python -m venv env
24-
25-
- run: &install-requirements
26-
name: Install requirements
27-
command: |
28-
. env/bin/activate
29-
pip install -U pip
30-
pip install -r requirements.txt -r tests/requirements.txt
31-
pip install wheel twine
32-
33-
- run:
34-
name: Install appropriate dimod version
35-
command: |
36-
. env/bin/activate
37-
if [[ "<< parameters.dimod-version >>" ]]; then
38-
pip install 'dimod<< parameters.dimod-version >>'
39-
else
40-
pip uninstall dimod -y
41-
fi
42-
43-
- save_cache: &save-cache-env
44-
key: v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "tests/requirements.txt" }}-{{ .Environment.CIRCLE_JOB }}
45-
paths:
46-
- env
47-
48-
- run: &build-package
49-
name: Build package
50-
command: env/bin/python setup.py sdist bdist_wheel
51-
52-
- run: &install-package
53-
name: Install package
54-
command: env/bin/pip install .
27+
- ocean/pip-install:
28+
cache: false
29+
packages: . dimod<< parameters.dimod-version >>
5530

5631
- run: &run-python-tests
5732
name: Run Python tests
5833
command: env/bin/coverage run -m unittest discover
5934

60-
- run: &upload-python-code-coverage
35+
- run:
6136
name: Upload code coverage
6237
command: |
6338
. env/bin/activate
@@ -76,83 +51,31 @@ jobs:
7651
steps:
7752
- checkout
7853

79-
# install `python-version` and cache it
80-
- run: &brew-install-pyenv
81-
name: Install pyenv
82-
command: HOMEBREW_NO_AUTO_UPDATE=1 brew install pyenv
83-
84-
- restore_cache: &restore-cache-pyenv
85-
keys:
86-
- v1-pyenv-{{ .Environment.CIRCLE_JOB }}-xcode-<< parameters.xcode >>
87-
88-
- when:
89-
# backport https://github.com/python/cpython/pull/21113 to support macOS 11 when building py36
90-
# see also: https://github.com/pyenv/pyenv/issues/1737.
91-
condition:
92-
matches:
93-
pattern: "^3\\.6.*$"
94-
value: << parameters.python-version >>
95-
steps:
96-
- run:
97-
name: Install Python 3.6 with a patch for macOS 11
98-
command: |
99-
curl -LO https://github.com/python/cpython/commit/8ea6353.patch
100-
pyenv install << parameters.python-version>> -s -p < 8ea6353.patch
101-
102-
- run: &pyenv-install-python
103-
name: Install python
104-
command: pyenv install << parameters.python-version >> -s
105-
106-
- run: &pyenv-set-system-python
107-
name: Set system python
108-
command: |
109-
echo -e '\n\n# Initialize pyenv' >> ~/.bash_profile
110-
echo 'eval "$(pyenv init --path 2>/dev/null || true)"' >> ~/.bash_profile
111-
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
112-
pyenv global << parameters.python-version >>
113-
114-
- save_cache: &save-cache-pyenv
115-
key: v1-pyenv-{{ .Environment.CIRCLE_JOB }}-xcode-<< parameters.xcode >>
116-
paths:
117-
- ~/.pyenv
118-
119-
# install dependencies and cache them
120-
- restore_cache: *restore-cache-env
54+
- ocean/brew-install-pyenv
12155

122-
- run: *create-virtualenv
56+
- ocean/pyenv-install-python:
57+
python-version: << parameters.python-version >>
58+
cache-key-prefix: << parameters.xcode >>
12359

124-
- run: *install-requirements
60+
- ocean/pip-install:
61+
requirements: requirements.txt tests/requirements.txt
12562

126-
- save_cache: *save-cache-env
127-
128-
- run: *install-package
63+
- ocean/pip-install:
64+
cache: false
65+
packages: .
12966

13067
- run: *run-python-tests
13168

13269
test-docs:
133-
docker:
134-
- image: circleci/python:3.7
70+
executor:
71+
name: ocean/python
72+
python-version: "3.7"
13573

13674
steps:
13775
- checkout
13876

139-
- restore_cache:
140-
key: v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "tests/requirements.txt" }}-{{ checksum "docs/requirements.txt" }}-{{ .Environment.CIRCLE_JOB }}
141-
142-
- run: *create-virtualenv
143-
144-
- run: *install-requirements
145-
146-
- run:
147-
name: Install docs requirements
148-
command: env/bin/pip install -r docs/requirements.txt
149-
150-
- save_cache:
151-
key: v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "tests/requirements.txt" }}-{{ checksum "docs/requirements.txt" }}-{{ .Environment.CIRCLE_JOB }}
152-
paths:
153-
- env
154-
155-
- run: *install-package
77+
- ocean/pip-install:
78+
requirements: requirements.txt tests/requirements.txt docs/requirements.txt
15679

15780
- run:
15881
name: Build docs
@@ -175,29 +98,28 @@ jobs:
17598
. env/bin/activate
17699
make -C docs/ linkcheck
177100
178-
pypi-deploy:
179-
docker:
180-
- image: circleci/python:3.9
101+
build-dist:
102+
executor:
103+
name: ocean/python
104+
python-version: "3.9"
181105

182106
steps:
183107
- checkout
184108

185-
- restore_cache: *restore-cache-env
186-
187-
- run: *create-virtualenv
188-
189-
- run: *install-requirements
109+
- ocean/pip-install:
110+
requirements: requirements.txt
111+
packages: wheel
112+
cache: false
190113

191-
- save_cache: *save-cache-env
192-
193-
- run: *build-package
114+
- ocean/build-dist:
115+
dist-type: sdist bdist_wheel
194116

195117
- store_artifacts:
196-
path: ./dist
118+
path: dist
197119

198-
- run:
199-
name: Upload package to PyPI
200-
command: env/bin/twine upload -u "$PYPI_USERNAME" -p "$PYPI_PASSWORD" --skip-existing ./dist/*
120+
- persist_to_workspace:
121+
root: dist
122+
paths: .
201123

202124

203125
workflows:
@@ -224,10 +146,20 @@ workflows:
224146
xcode: ["13.2.0"]
225147

226148
- test-docs
149+
- build-dist
227150

228151
deploy:
229152
jobs:
230-
- pypi-deploy:
153+
- build-dist:
154+
filters:
155+
tags:
156+
only: /^[0-9]+(\.[0-9]+)*((\.dev|rc)([0-9]+)?)?$/
157+
branches:
158+
ignore: /.*/
159+
160+
- ocean/pypi-deploy:
161+
requires:
162+
- build-dist
231163
filters:
232164
tags:
233165
only: /^[0-9]+(\.[0-9]+)*((\.dev|rc)([0-9]+)?)?$/

0 commit comments

Comments
 (0)