Skip to content

Commit

Permalink
Simplify CI by using Ocean orb commands
Browse files Browse the repository at this point in the history
  • Loading branch information
randomir committed Dec 21, 2021
1 parent 4f0bb5a commit 1ece837
Showing 1 changed file with 54 additions and 122 deletions.
176 changes: 54 additions & 122 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
version: 2.1

orbs:
ocean: dwave/[email protected]

environment:
PIP_PROGRESS_BAR: 'off'

jobs:
test-linux:
parameters:
Expand All @@ -8,56 +14,25 @@ jobs:
dimod-version:
type: string

docker:
- image: circleci/python:<< parameters.python-version >>
executor:
name: ocean/python
python-version: << parameters.python-version >>

steps:
- checkout

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

- run: &create-virtualenv
name: Create virtual environment
command: |
python -m venv env
- run: &install-requirements
name: Install requirements
command: |
. env/bin/activate
pip install -U pip
pip install -r requirements.txt -r tests/requirements.txt
pip install wheel twine
- run:
name: Install appropriate dimod version
command: |
. env/bin/activate
if [[ "<< parameters.dimod-version >>" ]]; then
pip install 'dimod<< parameters.dimod-version >>'
else
pip uninstall dimod -y
fi
- save_cache: &save-cache-env
key: v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "tests/requirements.txt" }}-{{ .Environment.CIRCLE_JOB }}
paths:
- env

- run: &build-package
name: Build package
command: env/bin/python setup.py sdist bdist_wheel

- run: &install-package
name: Install package
command: env/bin/pip install .
- ocean/pip-install:
cache: false
packages: . dimod<< parameters.dimod-version >>

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

- run: &upload-python-code-coverage
- run:
name: Upload code coverage
command: |
. env/bin/activate
Expand All @@ -76,83 +51,31 @@ jobs:
steps:
- checkout

# install `python-version` and cache it
- run: &brew-install-pyenv
name: Install pyenv
command: HOMEBREW_NO_AUTO_UPDATE=1 brew install pyenv

- restore_cache: &restore-cache-pyenv
keys:
- v1-pyenv-{{ .Environment.CIRCLE_JOB }}-xcode-<< parameters.xcode >>

- when:
# backport https://github.com/python/cpython/pull/21113 to support macOS 11 when building py36
# see also: https://github.com/pyenv/pyenv/issues/1737.
condition:
matches:
pattern: "^3\\.6.*$"
value: << parameters.python-version >>
steps:
- run:
name: Install Python 3.6 with a patch for macOS 11
command: |
curl -LO https://github.com/python/cpython/commit/8ea6353.patch
pyenv install << parameters.python-version>> -s -p < 8ea6353.patch
- run: &pyenv-install-python
name: Install python
command: pyenv install << parameters.python-version >> -s

- run: &pyenv-set-system-python
name: Set system python
command: |
echo -e '\n\n# Initialize pyenv' >> ~/.bash_profile
echo 'eval "$(pyenv init --path 2>/dev/null || true)"' >> ~/.bash_profile
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
pyenv global << parameters.python-version >>
- save_cache: &save-cache-pyenv
key: v1-pyenv-{{ .Environment.CIRCLE_JOB }}-xcode-<< parameters.xcode >>
paths:
- ~/.pyenv

# install dependencies and cache them
- restore_cache: *restore-cache-env
- ocean/brew-install-pyenv

- run: *create-virtualenv
- ocean/pyenv-install-python:
python-version: << parameters.python-version >>
cache-key-prefix: << parameters.xcode >>

- run: *install-requirements
- ocean/pip-install:
requirements: requirements.txt tests/requirements.txt

- save_cache: *save-cache-env

- run: *install-package
- ocean/pip-install:
cache: false
packages: .

- run: *run-python-tests

test-docs:
docker:
- image: circleci/python:3.7
executor:
name: ocean/python
python-version: "3.7"

steps:
- checkout

- restore_cache:
key: v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "tests/requirements.txt" }}-{{ checksum "docs/requirements.txt" }}-{{ .Environment.CIRCLE_JOB }}

- run: *create-virtualenv

- run: *install-requirements

- run:
name: Install docs requirements
command: env/bin/pip install -r docs/requirements.txt

- save_cache:
key: v1-dependencies-{{ checksum "requirements.txt" }}-{{ checksum "tests/requirements.txt" }}-{{ checksum "docs/requirements.txt" }}-{{ .Environment.CIRCLE_JOB }}
paths:
- env

- run: *install-package
- ocean/pip-install:
requirements: requirements.txt tests/requirements.txt docs/requirements.txt

- run:
name: Build docs
Expand All @@ -175,29 +98,28 @@ jobs:
. env/bin/activate
make -C docs/ linkcheck
pypi-deploy:
docker:
- image: circleci/python:3.9
build-dist:
executor:
name: ocean/python
python-version: "3.9"

steps:
- checkout

- restore_cache: *restore-cache-env

- run: *create-virtualenv

- run: *install-requirements
- ocean/pip-install:
requirements: requirements.txt
packages: wheel
cache: false

- save_cache: *save-cache-env

- run: *build-package
- ocean/build-dist:
dist-type: sdist bdist_wheel

- store_artifacts:
path: ./dist
path: dist

- run:
name: Upload package to PyPI
command: env/bin/twine upload -u "$PYPI_USERNAME" -p "$PYPI_PASSWORD" --skip-existing ./dist/*
- persist_to_workspace:
root: dist
paths: .


workflows:
Expand All @@ -224,10 +146,20 @@ workflows:
xcode: ["13.2.0"]

- test-docs
- build-dist

deploy:
jobs:
- pypi-deploy:
- build-dist:
filters:
tags:
only: /^[0-9]+(\.[0-9]+)*((\.dev|rc)([0-9]+)?)?$/
branches:
ignore: /.*/

- ocean/pypi-deploy:
requires:
- build-dist
filters:
tags:
only: /^[0-9]+(\.[0-9]+)*((\.dev|rc)([0-9]+)?)?$/
Expand Down

0 comments on commit 1ece837

Please sign in to comment.