Skip to content

Commit

Permalink
Enable PyPI Publishing with CircleCI (#49)
Browse files Browse the repository at this point in the history
* test publishing to pypi on tag

* update readme

* dependent job needs to run on tags as well
  • Loading branch information
dralgorhythm authored Sep 13, 2019
1 parent 626932b commit 9dce9b0
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 6 deletions.
39 changes: 36 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@ workflows:
version: 2
test:
jobs:
- py27
- py27:
filters:
tags:
only: /^v.*/
- publish:
requires:
- py27
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/
# TODO: - py37

jobs:
Expand All @@ -30,12 +41,34 @@ jobs:
- save_cache:
paths:
./venv/
key: v1-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "requirements.txt" }}
key: v1-{{ arch }}-{{ .Environment.CIRCLE_PROJECT }}-{{ checksum "setup.py" }}-{{ checksum "requirements.txt" }}
- run:
name: Pytest
command: |
./venv/bin/pytest -v tests/
publish:
docker:
- image: circleci/python:2.7
steps:
- checkout
- restore_cache:
keys:
- v1-{{ arch }}-{{ .Environment.CIRCLE_PROJECT }}-{{ checksum "setup.py" }}-{{ checksum "requirements.txt" }}
- run:
name: verify git tag vs. version
command: |
python -m venv venv || virtualenv venv
. venv/bin/activate
python setup.py verify
- run:
name: create packages
command: |
python setup.py sdist
python setup.py bdist_wheel
- run:
name: upload to pypi
command: |
./venv/bin/twine upload --config .pypirc -r pypi dist/* --password $PYPI_PASSWORD_PROD
# TODO:
# py37:
# <<: *template
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ src/indy/specs/build/vendored/*
# build directories
/build/
/docs/_build/

/dist/
/venv/
# compiled files
*.o
*.a
Expand Down
11 changes: 11 additions & 0 deletions .pypirc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[distutils]
index-servers=
pypi
testpypi

[pypi]
username: nerdwallet

[testpypi]
repository: https://test.pypi.org/legacy/
username: nerdwallet
8 changes: 8 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,11 @@ When creating ``aws_security_group_rule`` ``Resource`` objects you cannot pass `
vpc_id=vpc.id,
...
)
Release Steps
=================
1. Create an issue, check out a branch, and make your code changes.
2. Push to run CircleCI tests.
3. Create Pull Request to Master including VERSION bump.
4. Merge PR after Approval.
5. Add tag like v1.0.0 that matches new version and push.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.0
1.1.1
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
schematics==2.1.0
six==1.12.0
twine==1.13.0
25 changes: 24 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
import os
import sys

from setuptools import find_packages, setup
from setuptools.command.install import install

with open('VERSION') as version_fd:
VERSION = version_fd.read().strip()

with open('README.rst') as readme_fd:
long_description = readme_fd.read()

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):
if os.getenv('CIRCLE_TAG') == None:
sys.exit("FAILED: Your CIRCLE_TAG variable appears to be unset. Are you running on CircleCI triggered by tag?")
else:
tag = os.getenv('CIRCLE_TAG')

if tag != "v" + VERSION:
info = "Git tag: {0} does not match the version of this app: {1}".format(
tag, VERSION
)
sys.exit(info)

setup(
name='terraformpy',
version=VERSION,
Expand Down Expand Up @@ -45,5 +65,8 @@
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Pre-processors",
"Topic :: System :: Systems Administration",
]
],
cmdclass={
'verify': VerifyVersionCommand,
}
)

0 comments on commit 9dce9b0

Please sign in to comment.