modified version of jenkins debian glue (https://github.com/mika/jenkins-debian-glue) for devuan
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

130 lines
3.8 KiB

#!/bin/sh
set -x
set -e
set -u
[ -n "${DEBEMAIL:-}" ] || DEBEMAIL="jenkins.grml.org Autobuilder <jenkins@grml.org>"
export DEBEMAIL
if [ ! -d source ] ; then
echo "Please run the script in the jenkins workspace." >&2
exit 1
fi
if [ -z "${BUILD_NUMBER:-}" ] ; then
echo "No BUILD_NUMBER defined, please run it in jenkins." >&2
exit 1
fi
echo "*** source package build phase ***"
rm -f ./* || true
cd source
# support overriding git-dch options
if [ -n "${DCH_OPTS:-}" ] ; then
echo "Found environment variable DCH_OPTS, set to ${DCH_OPTS}"
else
DCH_OPTS="-S --multimaint-merge --ignore-branch"
echo "Using default git-dch options (${DCH_OPTS})"
fi
# support overriding extra options for git-dch
if [ -n "${DCH_EXTRA_OPTS:-}" ] ; then
echo "Found environment variable DCH_EXTRA_OPTS, set to ${DCH_EXTRA_OPTS}"
else
# support customizing the version number from outside
if [ -n "${distribution:-}" ] ; then
echo "Found environment variable distribution, set to $distribution"
DCH_EXTRA_OPTS="-N $(increase-version-number $(parsechangelog -c 1 | awk '/Version/ {print $2}'))~${BUILD_NUMBER}+${distribution}"
else
DCH_EXTRA_OPTS="--snapshot-number=${BUILD_NUMBER}"
fi
echo "Using extra git-dch options (${DCH_EXTRA_OPTS})"
fi
branch_checkout() {
[ -n "${1:-}" ] || return 1
local BRANCH="$1"
if git branch -a | egrep -q "\s+remotes/origin/${BRANCH}$" ; then
if ! git branch | egrep -q "\s+${BRANCH}$" ; then
echo "Branch $BRANCH found, checking out:"
git branch "${BRANCH}" "remotes/origin/${BRANCH}"
fi
fi
}
identify_latest_change() {
# debian/changelog might be a symlink (e.g. because debian points to
# pkg/debian), so make sure we don't access a non-existing file
git checkout -- $(readlink -f debian/changelog)
OLD_VERSION=$(dpkg-parsechangelog | awk '/^Version: / {print $2}')
tag=$(git describe $(git rev-list --tags='[^ju]*' --max-count=1 HEAD))
last_merge=$(git describe $(git rev-list --all --merges --max-count=1 HEAD))
since=${tag}
if [ -n "$last_merge" ] ; then
m_date=$(git log ${last_merge} --pretty="format:%at" -1)
t_date=$(git log ${tag} --pretty="format:%at" -1)
if [ ${m_date} -gt ${t_date} ] ; then
since=${last_merge}
fi
fi
echo "Last tag / merge seems to be $since"
git-dch -s "${since}" $DCH_OPTS $DCH_EXTRA_OPTS
NEW_VERSION=$(dpkg-parsechangelog | awk '/^Version: / {print $2}')
if dpkg --compare-versions "$NEW_VERSION" lt "$OLD_VERSION" ; then
echo "Calculated version is older than last release, falling back to auto mode."
# debian/changelog might be a symlink (e.g. because debian points to
# pkg/debian), so make sure we don't access a non-existing file
git checkout -- $(readlink -f debian/changelog)
git-dch --auto $DCH_OPTS $DCH_EXTRA_OPTS
fi
}
git_dch_auto() {
git-dch --auto $DCH_OPTS $DCH_EXTRA_OPTS
}
branch_checkout debian
branch_checkout upstream
git checkout master
rm -rf .pc
if [ "${1:-}" = "auto" ] ; then
echo "Using git-dch with auto mode."
git_dch_auto
elif [ -r debian/gbp.conf ] ; then
echo "Found debian/gbp.conf, using git-dch with auto mode."
git_dch_auto
else
echo "Trying to identify latest tag / merge..."
if ! git describe $(git rev-list --tags='[^ju]*' --max-count=1 HEAD) >/dev/null ; then
echo "Failed to identify latest change, falling back to auto mode."
git_dch_auto
else
identify_latest_change
fi
fi
debchange --release ""
if ! git-buildpackage -tc --git-ignore-new -S -us -uc ; then
echo "git-buildpackage did not work, trying dpkg-source"
cd ..
dpkg-source -b source
fi
# needed for deploying artifacts
mkdir -p ${JENKINS_HOME}/userContent/${JOB_NAME}/
echo "Cleaning up ${JENKINS_HOME}/userContent/${JOB_NAME} to get rid of possibly outdated data"
rm -f "${JENKINS_HOME}/userContent/${JOB_NAME}/"*