Skip to content

Commit e859b08

Browse files
committed
BNCASB-2204: Split the update the script into two separate helper scripts.
update-version script to update the package version publish-pypi script to update the publish the package to PyPI
1 parent 1759c1f commit e859b08

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed

publish-pypi.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
function log()
6+
{
7+
echo "$(date): $1"
8+
}
9+
10+
function usage()
11+
{
12+
echo "Helper to publish the package to PyPI.
13+
Usage: $0 -p <GITHUB_TAG>
14+
-p <GITHUB_TAG> : Github Tag value, semantic realease format eg: v1.36 or v2.0.7
15+
-h : help
16+
"
17+
exit
18+
}
19+
20+
function publish()
21+
{
22+
23+
log "Installing required dependencies"
24+
pip install -r requirements-pypi.txt
25+
26+
# checkout specific tag version
27+
git checkout tags/"$TAG_PARAM"
28+
29+
# creating the distribution package
30+
rm -rf dist/
31+
python setup.py sdist
32+
python setup.py bdist_wheel
33+
34+
log "Publishing package version/tag: $TAG_PARAM"
35+
twine upload dist/* # add --repository-url https://test.pypi.org/legacy/ to push to TestPyPI
36+
37+
exit
38+
}
39+
40+
# Parse and handle command line options
41+
while getopts ":p:h" OPTION; do
42+
case $OPTION in
43+
p)
44+
TAG_PARAM=$OPTARG
45+
publish
46+
;;
47+
*)
48+
usage
49+
;;
50+
esac
51+
done
52+
53+
# if no args specified
54+
if [ "$#" -ne 1 ]
55+
then
56+
usage
57+
fi

requirements-pypi.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
setuptools>=44.0.0
2+
wheel>=0.33.6
3+
twine>=3.1.1

update-version.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
VERSION_PARAM=${1:-AUTO}
6+
7+
function log()
8+
{
9+
echo "$(date): $1"
10+
}
11+
12+
function usage()
13+
{
14+
echo "Helper to update the package version and commit to GitHub.
15+
Usage: $0 <VERSION_NUMBER>
16+
<VERSION_NUMBER> : Version is usually a semantic release eg 1.20, 1.1.7.
17+
VERSION value is optional, if not passed then an auto version update occurs.
18+
-h : help
19+
"
20+
exit
21+
}
22+
23+
function update()
24+
{
25+
# update codebase
26+
git checkout master
27+
git pull
28+
29+
if [ "$VERSION_PARAM" = "AUTO" ]
30+
then
31+
OLD_VER=$(cat VERSION)
32+
NEW_VER=$(echo "$OLD_VER" + .01 | bc)
33+
else
34+
NEW_VER=$VERSION_PARAM
35+
fi
36+
37+
# bump the version
38+
echo "$NEW_VER" > VERSION
39+
log "Version bumped to $NEW_VER"
40+
41+
# push VERSION file and new TAG to git
42+
log "Pushing to GitHub..."
43+
git add VERSION
44+
git commit -a -m "Bump the version to $NEW_VER"
45+
git push
46+
47+
# adding tag
48+
log "Adding Tag..."
49+
TAG="v$NEW_VER"
50+
log "New tag : $TAG"
51+
git tag -a "$TAG" -m "Bumped the version to $NEW_VER"
52+
git push origin "$TAG"
53+
54+
exit
55+
}
56+
57+
# Parse and handle command line options
58+
while getopts ":h" OPTION; do
59+
case $OPTION in
60+
h)
61+
usage
62+
;;
63+
*)
64+
usage
65+
;;
66+
esac
67+
done
68+
69+
update

0 commit comments

Comments
 (0)