|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +project_path="/vagrant" |
| 5 | +python_bin="~/snowplow-python-2.7-tracker-environment/bin/python2.7" |
| 6 | + |
| 7 | +# Similar to Perl die |
| 8 | +function die() { |
| 9 | + echo "$@" 1>&2 ; exit 1; |
| 10 | +} |
| 11 | + |
| 12 | +# Check if our Vagrant box is running. Expects `vagrant status` to look like: |
| 13 | +# |
| 14 | +# > Current machine states: |
| 15 | +# > |
| 16 | +# > default poweroff (virtualbox) |
| 17 | +# > |
| 18 | +# > The VM is powered off. To restart the VM, simply run `vagrant up` |
| 19 | +# |
| 20 | +# Parameters: |
| 21 | +# 1. out_running (out parameter) |
| 22 | +function is_running { |
| 23 | + [ "$#" -eq 1 ] || die "1 argument required, $# provided" |
| 24 | + local __out_running=$1 |
| 25 | + |
| 26 | + set +e |
| 27 | + vagrant status | sed -n 3p | grep -q "^default\s*running (virtualbox)$" |
| 28 | + local retval=${?} |
| 29 | + set -e |
| 30 | + if [ ${retval} -eq "0" ] ; then |
| 31 | + eval ${__out_running}=1 |
| 32 | + else |
| 33 | + eval ${__out_running}=0 |
| 34 | + fi |
| 35 | +} |
| 36 | + |
| 37 | +# Get version, checking we are on the latest |
| 38 | +# |
| 39 | +# Parameters: |
| 40 | +# 1. out_version (out parameter) |
| 41 | +# 2. out_error (out parameter) |
| 42 | +function get_version { |
| 43 | + [ "$#" -eq 2 ] || die "2 arguments required, $# provided" |
| 44 | + local __out_version=$1 |
| 45 | + local __out_error=$2 |
| 46 | + |
| 47 | + # Extract the version from package.json using Node and save it in a file named "VERSION" |
| 48 | + vagrant ssh -c "cd ${project_path} && ${python_bin} -c \"v={}; execfile('snowplow_tracker/_version.py', v); print v['__version__']\" > VERSION" |
| 49 | + file_version=`cat VERSION` |
| 50 | + tag_version=`git describe --abbrev=0 --tags` |
| 51 | + if [ ${file_version} != ${tag_version} ] ; then |
| 52 | + eval ${__out_error}="'File version ${file_version} != tag version ${tag_version}'" |
| 53 | + else |
| 54 | + eval ${__out_version}=${file_version} |
| 55 | + fi |
| 56 | +} |
| 57 | + |
| 58 | +# Go to parent-parent dir of this script |
| 59 | +function cd_root() { |
| 60 | + source="${BASH_SOURCE[0]}" |
| 61 | + while [ -h "${source}" ] ; do source="$(readlink "${source}")"; done |
| 62 | + dir="$( cd -P "$( dirname "${source}" )/.." && pwd )" |
| 63 | + cd ${dir} |
| 64 | +} |
| 65 | + |
| 66 | +function upload_to_pypi() { |
| 67 | + |
| 68 | + # Register the new release with PyPI |
| 69 | + echo "Registering the release with PyPI. Choose option 1..." |
| 70 | + vagrant ssh -c "cd ${project_path} && ${python_bin} setup.py register" |
| 71 | + |
| 72 | + # Upload the new release to PyPI |
| 73 | + echo "Uploading the file to PyPI. IMPORTANT: PyPI does not allow a file to be re-uploaded." |
| 74 | + read -p "Do you want to upload the file to PyPI? [Y/N]" -n 1 -r |
| 75 | + if [[ $REPLY =~ ^[Yy]$ ]] |
| 76 | + then |
| 77 | + # We have to upload from a folder which supports hard-linking (which guest folders shared with host don't) |
| 78 | + vagrant ssh -c "cd \$(mktemp -d) && cp -r ${project_path}/* . && ${python_bin} setup.py sdist upload" |
| 79 | + fi |
| 80 | +} |
| 81 | + |
| 82 | +cd_root |
| 83 | + |
| 84 | +# Precondition for running |
| 85 | +running=0 && is_running "running" |
| 86 | +[ ${running} -eq 1 ] || die "Vagrant guest must be running to push" |
| 87 | + |
| 88 | +# Git tag must match version in snowplow_tracker/_version.py |
| 89 | +version="" && error="" && get_version "version" "error" |
| 90 | +[ "${error}" ] && die "Versions don't match: ${error}. Are you trying to publish an old version, or maybe on the wrong branch?" |
| 91 | + |
| 92 | +upload_to_pypi |
0 commit comments