1- #! /usr/ bin/env bash
1+ #! /bin/bash
22
3- echo " Usage: $0 [option] ...
4- -u or --update : update the version and commit to Github
5- -p or --publish : publish the package to PyPI
6- -h or --help : help
7- "
3+ function log()
4+ {
5+ echo " $( date) : $1 "
6+ }
87
9- for arg in " $@ "
8+ function usage()
9+ {
10+ echo " Usage: $0 [option] ...
11+ -u <VERSION> : Update the package version and commit to Github. Version is usually a semantic release eg 1.20, 1.1.7
12+ If you want to do an auto update use '-u AUTO'.
13+ -p <TAG> : Publish the package to PyPI. Specify the Github repo tag we want to use to create the distribution
14+ package. eg: '-p v1.36'
15+ -h : help
16+ "
17+ exit
18+ }
1019
11- do
12- if [ " $arg " == " --update" ] || [ " $arg " == " -u" ]
20+ function update()
21+ {
22+ # update codebase
23+ git checkout master
24+ git pull
25+
26+ if [ " $VERSION_PARAM " = " AUTO" ]
1327 then
14- # bump the version
15- echo " Updating the package version..."
1628 OLD_VER=$( cat VERSION)
1729 NEW_VER=$( echo " $OLD_VER " + .01 | bc)
18- echo " $NEW_VER " > VERSION
19- echo " Version bumped to $NEW_VER "
20-
21- # push to git
22- echo " Pushing to GitHub..."
23- git commit -m " Bump the version to $NEW_VER "
24- git add VERSION
25- git commit -a -m " Bump the version to $NEW_VER "
26- git push
27-
28- # adding tag
29- echo " Adding Tag..."
30- TAG=" v$NEW_VER "
31- echo " $TAG "
32- git tag -a " $TAG " -m " Bumped the version to $NEW_VER "
33- git push origin " $TAG "
34-
30+ else
31+ NEW_VER=$VERSION_PARAM
3532 fi
3633
37- # publish to PyPI
38- if [ " $arg " == " --publish" ] || [ " $arg " == " -p" ]
39- then
40- echo " Pushing the package to PyPI...
41- Note: Please have setuptools, wheel and twine packages installed."
34+ # bump the version
35+ echo " $NEW_VER " > VERSION
36+ log " Version bumped to $NEW_VER "
4237
43- # creating the distribution package
44- rm -rf dist/
45- python setup.py sdist
46- python setup.py bdist_wheel
47- twine upload dist/ *
38+ # push VERSION file and new TAG to git
39+ log " Pushing to GitHub... "
40+ git add VERSION
41+ git commit -a -m " Bump the version to $NEW_VER "
42+ git push
4843
49- fi
44+ # adding tag
45+ log " Adding Tag..."
46+ TAG=" v$NEW_VER "
47+ log " New tag : $TAG "
48+ git tag -a " $TAG " -m " Bumped the version to $NEW_VER "
49+ git push origin " $TAG "
5050
51+ exit
52+ }
5153
52- # help
53- if [ " $arg " == " --help" ] || [ " $arg " == " -h" ]
54- then
55- echo " Usage: $0 [option] ...
56- -u or --update : update the version and commit to Github
57- -p or --publish : publish the package to PyPI
58- -h or --help : help"
59- fi
54+ function publish()
55+ {
56+ log " Pushing the package to PyPI. (Note: Please have setuptools, wheel and twine packages installed.)"
57+ log " Publishing package version/tag: $TAG_PARAM "
58+
59+ # checkout specific tag version
60+ git checkout tags/" $TAG_PARAM "
61+
62+ # creating the distribution package
63+ rm -rf dist/
64+ python setup.py sdist
65+ python setup.py bdist_wheel
66+ twine upload dist/*
67+
68+ exit
69+ }
70+
71+ # Parse and handle command line options
72+ while getopts " :u:p:" OPTION; do
73+ case $OPTION in
74+ u)
75+ VERSION_PARAM=$OPTARG
76+ update
77+ ;;
78+ p)
79+ TAG_PARAM=$OPTARG
80+ publish
81+ ;;
82+ * )
83+ usage
84+ ;;
85+ esac
6086done
6187
88+ # if no args specified
89+ if [ " $# " -ne 1 ]
90+ then
91+ usage
92+ fi
0 commit comments