-
Notifications
You must be signed in to change notification settings - Fork 1
/
mkbld
executable file
·82 lines (73 loc) · 2.2 KB
/
mkbld
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
PACKAGE_NAME="bluepy3"
HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)
CMD="${1}"
BRANCH="$(git branch --show-current)"
echo "$HERE is on branch: $BRANCH"
echo
pushd "${HERE}" >/dev/null || exit 1
build_app(){
LOCATION=$1
echo "Building distribution package in $LOCATION"
### install build-system
echo
echo "Checking build-system installation..."
python3 -m pip install --upgrade build | grep -v "already satisfied"
python3 -m pip install --upgrade twine | grep -v "already satisfied"
### build package
echo
echo "Building..."
rm -r dist/*
rm -r ./*.egg-info
python3 -m build --outdir ./dist --sdist
}
test_app() {
LOCATION=$1
echo "Upload package to TestPyPi from $LOCATION"
python3 -m twine upload --repository testpypi dist/*
echo ""
echo "To test installing this package use:"
echo "python3 -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ --no-deps --upgrade ${PACKAGE_NAME}"
}
dist_app() {
LOCATION=$1
echo "Upload distribution package to PyPi from $LOCATION"
python3 -m twine upload --repository pypi dist/*
echo ""
echo "To install this package use:"
echo "python3 -m pip install --upgrade ${PACKAGE_NAME}"
}
update_local_repo() {
branch_name=$1
git fetch origin "${branch_name}" || { sleep 60; git fetch origin "${branch_name}" || exit 1; }
git reset --hard "origin/${branch_name}" || exit 1
git clean -f -d || exit 1
git pull || exit 1
}
# check commandline parameters
case $CMD in
-b | --build)
# build
build_app "${HERE}" || exit 1
;;
-d | --dist)
# distribute for production
dist_app "${HERE}" || exit 1
;;
-t | --test)
# distribute for testing
test_app "${HERE}" || exit 1
;;
--discard)
# reset local repo discarding local changes
update_local_repo "${BRANCH}" || exit 1
;;
*)
echo "Syntax:"
echo "mkbld [-b|--build] | [-d|--dist] | [-t|--test] | [--discard]"
echo "Only the first option past is executed!"
echo
exit 1
;;
esac
popd >/dev/null || exit 1