#!/bin/bash QUIET_ARG="" [ "$1" == "--quiet" ] && QUIET_ARG="--quiet" # Enter source directory cd $( dirname $0 ) echo "Clean previous build..." rm -fr dist deb_dist if [ -n "$CI" -a $UID -eq 0 ] then echo "CI environment detected, set current directory as git safe for root" git config --global --add safe.directory $(pwd) fi echo "Detect version using git describe..." VERSION="$( git describe --tags|sed 's/^[^0-9]*//' )" echo "Computing python version..." if [ $( echo "$VERSION"|grep -c "-" ) -gt 0 ] then echo "Development version detected ($VERSION), compute custom python dev version" PY_VERSION="$( echo "$VERSION"|sed 's/-\([0-9]\)\+-.*$/.dev\1/' )" else echo "Clean tagged version detected, use it" PY_VERSION="$VERSION" fi echo "Set version=$PY_VERSION in setup.py using sed..." sed -i "s/^version *=.*$/version = '$PY_VERSION'/" setup.py if [ -d venv ] then VENV=$( realpath venv ) echo "Use existing virtualenv $VENV to install build dependencies" 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 echo "Install dependencies in virtualenv using pip..." $VENV/bin/python3 -m pip install stdeb wheel $QUIET_ARG echo "Build wheel package..." $VENV/bin/python3 setup.py bdist_wheel echo "Check gitdch is installed..." GITDCH=$(which gitdch) set -e if [ -z "$GITDCH" ] then TMP_GITDCH=$(mktemp -d) echo "Temporary install gitdch in $TMP_GITDCH..." git clone $QUIET_ARG https://gitea.zionetrix.net/bn8/gitdch.git $TMP_GITDCH/gitdch GITDCH="$VENV/bin/python3 $TMP_GITDCH/gitdch/gitdch" echo "Install gitdch dependencies in $VENV..." $VENV/bin/python3 -m pip install GitPython $QUIET_ARG else TMP_GITDCH="" echo "Use existing installation of gitdch ($GITDCH)" fi echo "Build debian source package using stdeb sdist_dsc command..." $VENV/bin/python3 setup.py --command-packages=stdeb.command sdist_dsc \ --package3 "python3-mylib" \ --maintainer "Benjamin Renard " \ --compat 10 \ --section net \ --forced-upstream-version "$VERSION" echo "Keep only debian package directory and orig.tar.gz archive..." find deb_dist/ -maxdepth 1 -type f ! -name '*.orig.tar.gz' -delete echo "Enter in debian package directory..." cd deb_dist/mylib-$VERSION if [ -z "$DEBIAN_CODENAME" ] then echo "Retreive debian codename using lsb_release..." DEBIAN_CODENAME=$( lsb_release -c -s ) [ $( lsb_release -r -s ) -ge 9 ] && DEBIAN_CODENAME="${DEBIAN_CODENAME}-ee" else echo "Use debian codename from environment ($DEBIAN_CODENAME)" fi # Compute debian package version DEB_VERSION_SUFFIX="-1" DEB_VERSION="$VERSION$DEB_VERSION_SUFFIX" echo "Generate debian changelog using gitdch..." GITDCH_ARGS=('--verbose') [ -n "$QUIET_ARG" ] && GITDCH_ARGS=('--warning') if [ -n "$MAINTAINER_NAME" ] then echo "Use maintainer name from environment ($MAINTAINER_NAME)" GITDCH_ARGS+=("--maintainer-name" "${MAINTAINER_NAME}") fi if [ -n "$MAINTAINER_EMAIL" ] then echo "Use maintainer email from environment ($MAINTAINER_EMAIL)" GITDCH_ARGS+=("--maintainer-email" "$MAINTAINER_EMAIL") fi $GITDCH \ --package-name mylib \ --version "${DEB_VERSION}" \ --version-suffix "${DEB_VERSION_SUFFIX}" \ --code-name $DEBIAN_CODENAME \ --output debian/changelog \ --release-notes ../../dist/release_notes.md \ --path ../../ \ --exclude "^CI: " \ --exclude "\.?woodpecker(\.yml)?" \ --exclude "build(\.sh)?" \ --exclude "tests(\.sh)?" \ --exclude "README(\.md)?" \ --exclude "^Merge branch " \ "${GITDCH_ARGS[@]}" echo "Add custom package name for dependencies..." cat << EOF > debian/py3dist-overrides cx_oracle python3-cx-oracle EOF [ $TEMP_VENV -eq 1 ] && echo "Clean temporary virtualenv..." && rm -fr $VENV [ -n "$TMP_GITDCH" ] && echo "Clean temporary gitdch installation..." && rm -fr $TMP_GITDCH echo "Build debian package..." dpkg-buildpackage