Skip to content

Commit 93a940f

Browse files
committed
Added Vagrant push to publish tracker to PyPI (closes snowplow#128)
1 parent 42b5e5f commit 93a940f

5 files changed

Lines changed: 106 additions & 1 deletion

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ nosetests.xml
3939

4040
# Vagrant
4141
.vagrant
42+
VERSION

CHANGES.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Version 0.6.0 (2015-xx-xx)
1+
Version 0.6.0 (2015-02-14)
22
--------------------------
33
Improved logging (#109)
44
Removed unnecessary whitespace from POST requests (#110)
@@ -13,6 +13,7 @@ Started preserving unicode characters in JSONs (#123)
1313
Used Travis CI image for master branch in README (#125)
1414
Added license button to README (#126)
1515
Added dedicated Vagrant setup (#127)
16+
Added Vagrant push to publish tracker to PyPI (#128)
1617

1718
Version 0.5.0 (2014-08-13)
1819
--------------------------

README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ Assuming Git, Vagrant_ and VirtualBox_ are installed:
6060
.. _Vagrant: http://docs.vagrantup.com/v2/installation/index.html
6161
.. _VirtualBox: https://www.virtualbox.org/wiki/Downloads
6262

63+
Publishing
64+
##########
65+
66+
::
67+
host$ vagrant push
68+
6369
Copyright and license
6470
#####################
6571

Vagrantfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,9 @@ Vagrant.configure("2") do |config|
1515
sh.path = "vagrant/up.bash"
1616
end
1717

18+
# Requires Vagrant 1.7.0+
19+
config.push.define "publish", strategy: "local-exec" do |push|
20+
push.script = "vagrant/push.bash"
21+
end
22+
1823
end

vagrant/push.bash

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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

Comments
 (0)