|
| 1 | +# with thanks to https://dev.to/jonatasbaldin/a-recipe-for-poetry-and-circleci-1bj6 |
1 | 2 | version: 2.1 |
2 | 3 | jobs: |
3 | | - build: |
| 4 | + # Building and testing the project |
| 5 | + # Useful when a PR is open, for example |
| 6 | + build-and-test: |
4 | 7 | docker: |
5 | | - - image: themattrix/tox |
| 8 | + - image: circleci/python:3.7.3 # includes `poetry`! |
| 9 | + # The steps for our build-and-test |
6 | 10 | steps: |
7 | 11 | - checkout |
8 | | - - run: tox |
| 12 | + |
| 13 | + # Cache can be tricky at first, but this means restore the cache if the text key |
| 14 | + # `deps-{{ checksum "poetry.lock" }}` changes (and it WILL change every time poetry.lock |
| 15 | + # is updated since we rely on its checksum) and poetry.lock is updated every time we add |
| 16 | + # a new dependency to our project |
| 17 | + - restore_cache: |
| 18 | + keys: |
| 19 | + - deps-{{ checksum "poetry.lock" }} |
| 20 | + |
| 21 | + - run: |
| 22 | + name: install dependencies |
| 23 | + command: | |
| 24 | + poetry install |
| 25 | +
|
| 26 | + # Save the specified path as a cache. This is the path Poetry uses to install the dependencies |
| 27 | + # So if you don't install anything new, this folder won't change and the cache will be effective |
| 28 | + - save_cache: |
| 29 | + key: deps-{{ checksum "poetry.lock" }} |
| 30 | + paths: |
| 31 | + - /home/circleci/.cache/pypoetry/virtualenvs |
| 32 | + |
| 33 | + - run: |
| 34 | + name: Run all the testing steps |
| 35 | + command: | |
| 36 | + poetry run tox |
| 37 | +
|
| 38 | + deployment: |
| 39 | + docker: |
| 40 | + - image: circleci/python:3.7.3 |
| 41 | + steps: |
| 42 | + - checkout |
| 43 | + - run: |
| 44 | + name: publish to PyPI |
| 45 | + command: | |
| 46 | + poetry publish --build --username "${PYPI_USERNAME}" --password "${PYPI_PASSWORD}" --no-interaction |
| 47 | +
|
| 48 | +# When to run which job |
| 49 | +workflows: |
| 50 | + version: 2.1 |
| 51 | + |
| 52 | + build-and-test-workflow: |
| 53 | + jobs: |
| 54 | + - build-and-test |
| 55 | + |
| 56 | + # The deployment workflow publishes the package, and is only run on a Git tag matching a |
| 57 | + # version regex |
| 58 | + deployment-workflow: |
| 59 | + jobs: |
| 60 | + - build-and-test: |
| 61 | + filters: |
| 62 | + tags: |
| 63 | + only: /v[0-9]+(\.[0-9]+)*/ |
| 64 | + branches: |
| 65 | + ignore: /.*/ |
| 66 | + |
| 67 | + - deployment: |
| 68 | + requires: |
| 69 | + - build-and-test |
| 70 | + filters: |
| 71 | + tags: |
| 72 | + only: /v[0-9]+(\.[0-9]+)*/ |
| 73 | + branches: |
| 74 | + ignore: /.*/ |
0 commit comments