This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
build.sh
executable file
·89 lines (68 loc) · 1.64 KB
/
build.sh
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
83
84
85
86
87
88
#!/usr/bin/env bash
# Build script of python package
set -e
name="oval-graph"
module="oval_graph"
unit_test() {
python3 -m pytest
}
commit_version() {
version=$1
module=$2
git add "${module}/__init__.py"
git add oval-graph.spec
git commit -m "${version}"
}
install_build_requirements() {
python3 -m pip install --user --upgrade setuptools wheel twine
}
build_backage() {
rm -rf dist
python3 setup.py sdist bdist_wheel
}
update_version_package() {
module=$1
old_version=$2
new_version=$3
sed -i "s/$old_version/$new_version/g" "${module}/__init__.py"
}
update_version_rpm() {
version=$1
name=$2
rpmdev-bumpspec "${name}".spec --comment="release ${version}" -n "${version}" --userstring="Jan Rodak <[email protected]>"
}
load_upstream() {
git checkout master
git pull upstream master
}
if [ "$1" = "" ]; then
echo "Missing version parameter!"
exit 1
fi
new_version=$1
if ! echo "$new_version" | grep -q -E '^[0-9]{1,}.[0-9]{1,}.[0-9]{1,}$'; then
echo "Bad version format!"
exit 1
fi
if git status --porcelain=v1 | grep -q '^\(.M\|M.\)'; then
echo "Not commited changes!"
exit 1
fi
load_upstream
# Update version in file
old_version=$(python3 setup.py --version)
update_version_package "$module" "$old_version" "$new_version"
version=$(python3 setup.py --version)
update_version_rpm "$version" "$name"
# Prepare build tools
install_build_requirements
# Test before build
unit_test
# Build
build_backage
# Upload to PyPi
twine upload dist/*
# Commit version
commit_version "$version" "$module"
# Tag version and upload to git repo
./tag_version.sh "${version}"