Skip to content

Commit 8a3b8a0

Browse files
author
Agus Makmun
committed
feat: added command to automatic upgrade package
1 parent 2bd99fa commit 8a3b8a0

File tree

2 files changed

+61
-15
lines changed

2 files changed

+61
-15
lines changed

martor/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22

33
__VERSION__ = "1.6.14"
4+
__RELEASE_DATE__ = "04-Sep-2022"
45
__AUTHOR__ = "Agus Makmun (Summon Agus)"
56
__AUTHOR_EMAIL__ = "[email protected]"

push.sh

Lines changed: 60 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,69 @@ echo '';
44
echo " a. development";
55
echo " b. master";
66
echo -n "[+] branch [a/B] ➜ ";
7-
read branch;
7+
read -r branch;
88

99
echo -n "[+] commit ➜ ";
10-
read commit;
10+
read -r commit;
11+
12+
# package folder & name
13+
package=martor
1114

1215
if [ "$commit" ] && [ "$branch" ]; then
13-
git add .;
14-
git commit -m "$commit";
15-
16-
if [ "$branch" == 'b' ] || [ "$branch" == 'B' ]; then
17-
git checkout master;
18-
git push origin master;
19-
else
20-
git checkout development;
21-
git push origin development;
22-
fi
23-
24-
echo "[i] successfully pushed at" $(date);
16+
if [ "$branch" == 'b' ] || [ "$branch" == 'B' ]; then
17+
echo -n "[+] upgrade version? [y/N] ➜ ";
18+
read -r upgrade_version;
19+
20+
if [ "$upgrade_version" == 'y' ] || [ "$upgrade_version" == 'Y' ]; then
21+
# https://stackoverflow.com/a/3250387/6396981
22+
old_version=$(grep '__VERSION__ = ".*"' $package/__init__.py | cut -d '"' -f 2);
23+
old_release_date=$(grep '__RELEASE_DATE__ = ".*"' $package/__init__.py | cut -d '"' -f 2);
24+
echo "[i] current version is $old_version, released at $old_release_date";
25+
26+
last_numb_old_version=$(echo "$old_version" | grep -o .$);
27+
last_numb_new_version=$(( last_numb_old_version + 1 ))
28+
29+
suggested_version="${old_version%?}${last_numb_new_version}"
30+
echo -n "[+] type new version [default:$suggested_version] ➜ ";
31+
read -r input_new_version;
32+
33+
if [ ! "$input_new_version" ]; then
34+
input_new_version=$suggested_version;
35+
fi
36+
37+
# 04-Sep-2022
38+
new_release_date=$(date +%d-%b-%Y);
39+
40+
# https://stackoverflow.com/a/525612/6396981
41+
# sed -i -e => for linux user
42+
# sed -i "" => for mac user
43+
echo "[i] updating new version..."
44+
find $package/ -type f \( -name "*.py" -or -name "*.css" -or -name "*.js" \) -exec sed -i "" "s/$old_version/$input_new_version/g" {} \;
45+
find $package/ -type f \( -name "*.py" -or -name "*.css" -or -name "*.js" \) -exec sed -i "" "s/$old_release_date/$new_release_date/g" {} \;
46+
fi
47+
48+
git add .;
49+
git commit -m "$commit";
50+
git checkout master;
51+
git push origin master;
52+
53+
if [ "$upgrade_version" == 'y' ] || [ "$upgrade_version" == 'Y' ]; then
54+
echo "[i] preparing upload to pypi..."
55+
if ! [ -x "$(command -v twine)" ]; then
56+
pip install twine
57+
fi
58+
59+
python setup.py sdist
60+
twine upload dist/"$package-$input_new_version".tar.gz
61+
fi
62+
else
63+
git add .;
64+
git commit -m "$commit";
65+
git checkout development;
66+
git push origin development;
67+
fi
68+
69+
echo "[i] successfully pushed at $(date)";
2570
else
26-
echo "[!] not pushed!";
71+
echo "[!] not pushed!";
2772
fi

0 commit comments

Comments
 (0)