Skip to content

Commit

Permalink
[INDY-1992] add bump_version.sh script and fix check_version func
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Nikitin <andrew.nikitin@dsr-corporation.com>
  • Loading branch information
Andrew Nikitin committed Mar 1, 2019
1 parent 3f76a6b commit 3f4b4ed
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
28 changes: 28 additions & 0 deletions bump_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

usage_str="Usage: $0 <release-version-dotted>"

if [ -z "$1" ] ; then
echo $usage_str
exit 0
fi

if [ "$1" = "--help" ] ; then
echo $usage_str
exit 0
fi

dotted_version=$1

import_metadata_str="indy_node.__metadata__"

# call python set_version function

python3 -c "from $import_metadata_str import set_version, split_version_from_str
set_version(split_version_from_str(\"$dotted_version\"))"

ret=$?
if [ $ret -ne 0 ] ; then
echo "FAILED ret: $ret"
exit $ret
fi
13 changes: 12 additions & 1 deletion indy_node/__metadata__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,23 @@
VERSION_FILE = os.path.join(module_path(indy_node), VERSION_FILENAME)


def split_version_from_str(vers: str)->list:
splitted = vers.split('.')
result = []
for ver in splitted:
try:
result.append(int(ver))
except ValueError:
result.append(ver)
return result


def check_version(version):
# TODO better errors (e.g. some are TypeError)
if not (
(type(version) in (tuple, list)) and
(len(version) == 5) and
all([type(version[i]) == int] for i in (0, 1, 2, 4)) and
all([type(version[i]) == int for i in (0, 1, 2, 4)]) and
(version[3] in ('dev', 'rc', 'stable'))
):
raise ValueError("Incorrect version: {}".format(version))
Expand Down
20 changes: 20 additions & 0 deletions indy_node/test/test_metadata_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest

from indy_node.__metadata__ import split_version_from_str, check_version


def test_split_version_from_str_only_int():
assert split_version_from_str("1.2.3.4.5") == [1, 2, 3, 4, 5]


def test_split_version_from_str_with_str():
assert split_version_from_str("1.2.3.rc.5") == [1, 2, 3, 'rc', 5]


def test_check_version_right_case():
check_version(split_version_from_str("1.2.3.rc.5"))


def test_check_version_wrong_case():
with pytest.raises(ValueError):
check_version(split_version_from_str("1.2.3.4.5"))

0 comments on commit 3f4b4ed

Please sign in to comment.