Skip to content

Instantly share code, notes, and snippets.

@bboe
Last active Dec 14, 2015
Embed
What would you like to do?
PyPi package deployment script. Depends on having an available pgp key to sign packages and the tag.
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: $(basename $0) package_name"
exit 1
fi
package=$1
status=$(git status | head -n 1)
if [[ "$status" != "# On branch master" ]]; then
read -p "Are you sure you want to deploy from a non-master branch? " input
case $input in
[Yy]* ) ;;
* ) echo "Not on master branch. Goodbye"; exit 1;;
esac
fi
status=$(git status | tail -n -1)
if [[ "$status" != "nothing to commit (working directory clean)" ]]; then
echo "There are pending changes. Goodbye"
exit 1
fi
version=$(python -c "import $package; print($package.__version__)")
read -p "Do you want to deploy $package $version? [y/n] " input
case $input in
[Yy]* ) ;;
* ) echo "Goodbye"; exit 1;;
esac
python setup.py sdist upload -s -r pypi
if [ $? -ne 0 ]; then
echo "Pushing source distribution failed. Aborting."
exit 1
fi
python setup.py bdist_wheel upload -s -r pypi
if [ $? -ne 0 ]; then
echo "Pushing wheel distribution failed. Aborting."
exit 1
fi
git tag -s "v$version" -m "v$version"
if [ $? -ne 0 ]; then
echo "Tagging version failed. Aborting."
exit 1
fi
git push
git push --tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment