2022-04-27 17:12:00 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-04-27 18:56:03 +02:00
|
|
|
QUIET_ARG=""
|
|
|
|
[ "$1" == "--quiet" ] && QUIET_ARG="--quiet"
|
|
|
|
|
2022-04-27 17:12:00 +02:00
|
|
|
# Enter source directory
|
|
|
|
cd $( dirname $0 )
|
|
|
|
|
2022-04-27 19:42:37 +02:00
|
|
|
echo "Clean previous build..."
|
2022-04-27 17:12:00 +02:00
|
|
|
rm -fr dist deb_dist
|
|
|
|
|
2022-04-27 20:05:53 +02:00
|
|
|
echo "Fetch git tags..."
|
|
|
|
git fetch --tags
|
|
|
|
|
2022-04-27 19:42:37 +02:00
|
|
|
echo "Detect version using git describe..."
|
2022-04-27 20:05:53 +02:00
|
|
|
VERSION="$( git describe --tags )"
|
2022-04-27 19:42:37 +02:00
|
|
|
|
2022-04-27 20:05:53 +02:00
|
|
|
echo "Set version=$VERSION in setup.py using sed..."
|
2022-04-27 17:12:00 +02:00
|
|
|
sed -i "s/^version *=.*$/version = '$VERSION'/" setup.py
|
|
|
|
|
|
|
|
if [ -d venv ]
|
|
|
|
then
|
|
|
|
VENV=$( realpath venv )
|
2022-04-27 19:42:37 +02:00
|
|
|
echo "Use existing virtualenv $VENV to install build dependencies"
|
2022-04-27 17:12:00 +02:00
|
|
|
TEMP_VENV=0
|
|
|
|
else
|
|
|
|
VENV=$(mktemp -d)
|
|
|
|
echo "Create a temporary virtualenv in $VENV to install build dependencies..."
|
|
|
|
TEMP_VENV=1
|
|
|
|
python3 -m venv $VENV
|
|
|
|
fi
|
|
|
|
|
2022-04-27 18:56:03 +02:00
|
|
|
echo "Install dependencies in virtualenv using pip..."
|
|
|
|
$VENV/bin/python3 -m pip install stdeb GitPython wheel $QUIET_ARG
|
|
|
|
|
|
|
|
echo "Build wheel package..."
|
2022-04-27 17:12:00 +02:00
|
|
|
$VENV/bin/python3 setup.py bdist_wheel
|
|
|
|
|
2022-04-27 19:42:37 +02:00
|
|
|
echo "Check gitdch is installed..."
|
2022-04-27 17:12:00 +02:00
|
|
|
GITDCH=$(which gitdch)
|
|
|
|
set -e
|
|
|
|
if [ -z "$GITDCH" ]
|
|
|
|
then
|
|
|
|
TMP_GITDCH=$(mktemp -d)
|
2022-04-27 18:56:03 +02:00
|
|
|
echo "Temporary install gitdch in $TMP_GITDCH..."
|
|
|
|
git clone $QUIET_ARG https://gitea.zionetrix.net/bn8/gitdch.git $TMP_GITDCH/gitdch
|
2022-04-27 17:12:00 +02:00
|
|
|
GITDCH=$TMP_GITDCH/gitdch/gitdch
|
|
|
|
else
|
|
|
|
TMP_GITDCH=""
|
2022-04-27 19:42:37 +02:00
|
|
|
echo "Use existing installation of gitdch ($GITDCH)"
|
2022-04-27 17:12:00 +02:00
|
|
|
fi
|
|
|
|
|
2022-04-27 18:56:03 +02:00
|
|
|
echo "Build debian source package using stdeb sdist_dsc command..."
|
2022-04-27 17:12:00 +02:00
|
|
|
$VENV/bin/python3 setup.py --command-packages=stdeb.command sdist_dsc \
|
|
|
|
--package3 "python3-mylib" \
|
|
|
|
--maintainer "Benjamin Renard <brenard@zionetrix.net>" \
|
|
|
|
--compat 10 \
|
|
|
|
--section net \
|
|
|
|
--forced-upstream-version "$VERSION"
|
|
|
|
|
2022-04-27 18:56:03 +02:00
|
|
|
echo "Keep only debian package directory and orig.tar.gz archive..."
|
2022-04-27 17:12:00 +02:00
|
|
|
find deb_dist/ -maxdepth 1 -type f ! -name '*.orig.tar.gz' -delete
|
|
|
|
|
2022-04-27 18:56:03 +02:00
|
|
|
echo "Enter in debian package directory..."
|
2022-04-27 17:12:00 +02:00
|
|
|
cd deb_dist/mylib-$VERSION
|
|
|
|
|
2022-04-27 19:42:37 +02:00
|
|
|
echo "Retreive debian codename using lsb_release..."
|
2022-04-27 17:12:00 +02:00
|
|
|
DEBIAN_CODENAME=$( lsb_release -c -s )
|
|
|
|
[ $( lsb_release -r -s ) -ge 9 ] && DEBIAN_CODENAME="${DEBIAN_CODENAME}-ee"
|
|
|
|
|
2022-04-27 18:56:03 +02:00
|
|
|
echo "Generate debian changelog using gitdch..."
|
|
|
|
GITDCH_LOG_ARG='--verbose'
|
|
|
|
[ -n "$QUIET_ARG" ] && GITDCH_LOG_ARG='--warning'
|
2022-04-27 17:12:00 +02:00
|
|
|
$VENV/bin/python3 $GITDCH \
|
|
|
|
--package-name mylib \
|
|
|
|
--version "${VERSION}" \
|
|
|
|
--code-name $DEBIAN_CODENAME \
|
|
|
|
--output debian/changelog \
|
|
|
|
--path ../../ \
|
2022-04-27 18:56:03 +02:00
|
|
|
$GITDCH_LOG_ARG
|
2022-04-27 17:12:00 +02:00
|
|
|
|
2022-04-27 18:56:03 +02:00
|
|
|
echo "Add custom package name for dependencies..."
|
2022-04-27 17:12:00 +02:00
|
|
|
cat << EOF > debian/py3dist-overrides
|
|
|
|
cx_oracle python3-cx-oracle
|
|
|
|
EOF
|
|
|
|
|
2022-04-27 18:56:03 +02:00
|
|
|
[ $TEMP_VENV -eq 1 ] && echo "Clean temporary virtualenv..." && rm -fr $VENV
|
2022-04-27 17:12:00 +02:00
|
|
|
|
2022-04-27 18:56:03 +02:00
|
|
|
[ -n "$TMP_GITDCH" ] && echo "Clean temporary gitdch installation..." && rm -fr $TMP_GITDCH
|
2022-04-27 17:12:00 +02:00
|
|
|
|
2022-04-27 18:56:03 +02:00
|
|
|
echo "Build debian package..."
|
2022-04-27 17:12:00 +02:00
|
|
|
dpkg-buildpackage --no-sign
|