version: 2.1

jobs:
  build-test:
    docker:
      - image: circleci/python:3.5.5
    steps:
      - checkout
      - restore_cache:
          keys:
            - deps-{{ checksum "poetry.lock" }}
      - run:
          name: Install Dependencies
          command: |
            poetry install
      - save_cache:
          key: deps-{{ checksum "poetry.lock" }}
          paths: 
            - /home/circleci/.cache/pypoetry/virtualenvs

      - run:
          name: Run Tests
          command: |
            poetry run ./runtests

  deploy:
    docker:
      - image: circleci/python:3.5.5
    steps:
      - checkout
      - run:
          name: Push to PyPI
          command: |
            poetry publish \
              --build \
              --username "${PYPI_USERNAME}" \
              --password "${PYPI_PASSWORD}" \
              --no-interaction

workflows:
  version: 2.1

  build-test:
    jobs:
      - build-test
  
  build-test-deploy:
    jobs:
      - build-test:
          filters:
            tags:
              only: /v[0-9]+(\.[0-9]+)*/
            branches:
              ignore: /.*/

      - deploy:
          requires:
            - build-test
          filters:
              tags:
                only: /v[0-9]+(\.[0-9]+)*/
              branches:
                ignore: /.*/

version: 2.1

jobs:
  build-test:
    docker:
      - image: circleci/python:3.5.5
    steps:
      - checkout
      - restore_cache:
          keys:
            - deps-{{ checksum "poetry.lock" }}
      - run:
          name: Install Dependencies
          command: |
            poetry install
      - save_cache:
          key: deps-{{ checksum "poetry.lock" }}
          paths: 
            - /home/circleci/.cache/pypoetry/virtualenvs

      - run:
          name: Run Tests
          command: |
            poetry run ./runtests

  deploy:
    docker:
      - image: circleci/python:3.5.5
    steps:
      - checkout
      - run:
          name: Push to PyPI
          command: |
            poetry publish \
              --build \
              --username "${PYPI_USERNAME}" \
              --password "${PYPI_PASSWORD}" \
              --no-interaction

workflows:
  version: 2.1

  build-test:
    jobs:
      - build-test
  
  build-test-deploy:
    jobs:
      - build-test:
          filters:
            tags:
              only: /v[0-9]+(\.[0-9]+)*/
            branches:
              ignore: /.*/

      - deploy:
          context: thread-pypi
          requires:
            - build-test
          filters:
              tags:
                only: /v[0-9]+(\.[0-9]+)*/
              branches:
                ignore: /.*/

Add security context for publishing
Add security context for publishing
