--- a +++ b/.circleci/config.yml @@ -0,0 +1,100 @@ +version: 2.1 + +executors: + python-3-9-6: + docker: + - image: cimg/python:3.9.6 + node-docker: + docker: + - image: cimg/node:17.6.0 + +orbs: + python: circleci/python@1.5.0 + +jobs: + generate-version: + executor: node-docker + steps: + - checkout + - run: + name: install semantic release dependencies in root + command: | + npm --prefix .semantic-release run installInRoot + - run: + name: run semantic release + command: npx semantic-release + + build-and-test: + executor: python-3-9-6 + steps: + - checkout + - restore_cache: + keys: + - python-cache-{{ checksum "requirements.txt" }} + + - python/install-packages: + pkg-manager: pip + # app-dir: ~/project/package-directory/ # If you're requirements.txt isn't in the root directory. + # pip-dependency-file: test-requirements.txt # if you have a different name for your requirements file, maybe one that combines your runtime and test requirements. + + - save_cache: + paths: + - ~/.cache/pip + key: python-cache-{{ checksum "requirements.txt" }} + when: always + + - run: + name: run unit tests + command: python -m pytest -v tests --cov=${CIRCLE_PROJECT_REPONAME/-/_} + + release: + executor: python-3-9-6 + steps: + - checkout + - restore_cache: + keys: + - python-cache-{{ checksum "requirements.txt" }} + - run: + name: install dependencies + command: | + pip install -r requirements.txt + pip install twine + - run: + name: create the distribution + command: | + python setup.py sdist + + CHECKS=$(twine check dist/* | grep -c "PASSED") + N_FILES=$(( $(ls -l dist | wc -l) -1 )) + + if [[ $CHECKS -ne $N_FILES ]] + then + echo "twine checks failed" + exit 1 + fi + - run: + name: push to pypi + command: | + twine upload -u ${PYPI_USERNAME} -p ${PYPI_PASSWORD} dist/* +workflows: + version: 2 + build-release: + jobs: + - generate-version: + filters: + branches: + only: "main" + - build-and-test + # filters: + # tags: + # only: /.*/ + # branches: + # ignore: "main" + - release: + requires: + - build-and-test + # filters: + # branches: + # ignore: /.*/ + # tags: + # only: /^deploy-.*/ \ No newline at end of file