diff --git a/.circleci/config.yml b/.circleci/config.yml index 98e2ab6..d4f7726 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -37,6 +37,70 @@ jobs: - store_artifacts: path: coverage + test_deploy: + working_directory: ~/project + docker: + - image: circleci/python:3.6.6 + steps: + - checkout + - run: + name: Setup environment + command: | + sudo chown -R circleci:circleci /usr/local/ + python -m pip install --upgrade pip + python -m pip install twine + + - run: + name: Verify git tag vs version + command: | + python setup.py verify + + - run: + name: Init .pypirc + command: | + echo -e "[testpypi]" >> ~/.pypirc + echo -e "repository: https://test.pypi.org/legacy/" >> ~/.pypirc + echo -e "username = ashnair1" >> ~/.pypirc + echo -e "password = $TEST_PYPI_PASSWORD" >> ~/.pypirc + + - run: + name: Build and upload to Test PyPI + command: | + python setup.py sdist bdist_wheel + twine upload --repository testpypi dist/* + + deploy: + working_directory: ~/project + docker: + - image: circleci/python:3.6.6 + steps: + - checkout + - run: + name: Setup environment + command: | + sudo chown -R circleci:circleci /usr/local/ + python -m pip install --upgrade pip + python -m pip install twine + + - run: + name: Verify git tag vs version + command: | + python setup.py verify + + - run: + name: Init .pypirc + command: | + echo -e "[pypi]" >> ~/.pypirc + echo -e "username = ashnair1" >> ~/.pypirc + echo -e "password = $PYPI_PASSWORD" >> ~/.pypirc + + - run: + name: Build and upload to PyPI + command: | + python setup.py sdist bdist_wheel + twine upload dist/* + + workflows: version: 2.1 @@ -48,4 +112,28 @@ workflows: only: - master - dev + build_deploy: + jobs: + - test_coco_assistant: + filters: + tags: + only: /[0-9]+(\.[0-9]+)*/ + branches: + ignore: /.*/ + - test_deploy: + filters: + tags: + only: /[0-9]+(\.[0-9]+)*/ + branches: + ignore: /.*/ + - deploy: + requires: + - test_coco_assistant + - test_deploy + filters: + tags: + only: /[0-9]+(\.[0-9]+)*/ + branches: + ignore: /.*/ + diff --git a/coco_assistant/VERSION b/coco_assistant/VERSION index 9e11b32..1c09c74 100644 --- a/coco_assistant/VERSION +++ b/coco_assistant/VERSION @@ -1 +1 @@ -0.3.1 +0.3.3 diff --git a/setup.py b/setup.py index 93613ef..0e2c775 100644 --- a/setup.py +++ b/setup.py @@ -3,10 +3,11 @@ import io import os +import sys from pathlib import Path from setuptools import find_packages, setup - +from setuptools.command.install import install # Package meta-data. NAME = "coco_assistant" @@ -49,17 +50,31 @@ def list_reqs(fname="requirements.txt"): return required, dependency_links -here = os.path.abspath(os.path.dirname(__file__)) +here = Path(__file__).cwd() # Import the README and use it as the long-description. # Note: this will only work if 'README.md' is present in your MANIFEST.in file! try: - with io.open(os.path.join(here, "README.md"), encoding="utf-8") as f: + with io.open(here / Path("README.md"), encoding="utf-8") as f: long_description = "\n" + f.read() except OSError: long_description = DESCRIPTION +class VerifyVersionCommand(install): + """Custom command to verify that the git tag matches our version""" + + description = "verify that the git tag matches our version" + + def run(self): + tag = os.getenv("CIRCLE_TAG") + VERSION = about["__version__"] + + if tag != VERSION: + info = "Git tag: {0} does not match the version of this app: {1}".format(tag, VERSION) + sys.exit(info) + + # Load the package's __version__.py module as a dictionary. ROOT_DIR = Path(__file__).resolve().parent PACKAGE_DIR = ROOT_DIR / NAME @@ -99,4 +114,7 @@ def list_reqs(fname="requirements.txt"): "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", ], + cmdclass={ + "verify": VerifyVersionCommand, + }, )