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.
 
 
 
 

134 lines
3.8 KiB

#!/bin/sh
set -x
set -e
set -u
export LC_ALL=C
export LANG=C
[ -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
if [ -z "${SVN_REVISION:-}" ] ; then
echo "No SVN_REVISION defined, please run it with a subversion repository." >&2
exit 1
fi
if ! [ -x "$(which svn2cl)" ] ; then
echo "Error: svn2cl not available, please install subversion-tools." >&2
exit 1
fi
if ! [ -x "$(which svn)" ] ; then
echo "Error: svn not available, please install subversion." >&2
exit 1
fi
if ! [ -x "$(which dpkg-parsechangelog)" ] ; then
echo "Error: dpkg-parsechangelog not available, please install dpkg-dev." >&2
exit 1
fi
echo "*** source package build phase ***"
rm -f ./* || true
ORIG_DIR=$(pwd)
cd source/${branch:-}
if ! [ -r debian/changelog ] ; then
echo "Error: could not find debian/changelog (not a Debian package or wrong tag/branch?)" >&2
exit 1
fi
SINCE_REVISION=$(svn info debian/changelog 2>/dev/null | awk '/Last Changed Rev:/ {print $4}')
if [ -z "${SINCE_REVISION:-}" ] ; then
echo "Error: could not detect svn revision which modified debian/changelog." >&2
exit 1
fi
# package name
PACKAGE=$(dpkg-parsechangelog --count 1 | awk '/^Source: / {print $2}')
# get newest version number from changelog
PREVIOUS_VERSION=$(dpkg-parsechangelog --count 1 | awk '/^Version: / {print $2}')
build_snapshot() {
DISTRIBUTION=$(dpkg-parsechangelog --count 1 | awk '/^Distribution/ {print $2}')
if [ "$DISTRIBUTION" = "UNRELEASED" ] ; then
# we do NOT raise the version number, if we detect an unreleased version
SNAPSHOT_VERSION="${PREVIOUS_VERSION}~${BUILD_NUMBER}.svn${SVN_REVISION}"
else
# calculate new snapshot version
SNAPSHOT_VERSION="$(increase-version-number "$PREVIOUS_VERSION")~${BUILD_NUMBER}.svn${SVN_REVISION}"
fi
# generate changelog
SVN_CHANGELOG=$(mktemp)
# build GNU like changelog with svn2cl as helper tool
# timeout after 15 seconds without progress, we might be running into e.g.
# "xsltApplyXSLTTemplate: A potential infinite template recursion was detected."
if ! timeout -k 16 16 svn2cl --reparagraph --stdout --include-rev -r HEAD:$SINCE_REVISION > "$SVN_CHANGELOG" ; then
echo ' * Sorry, generating changelog using svn2cl failed. :(
Make sure the svn2cl command works on the jenkins host.
For example validating server certificates is a common error.
' > "$SVN_CHANGELOG"
fi
# reduce changelog to just the first line of the commit message
sed -in '/^\t*\s*\* \[r/,/^\t*\s*$/p' "$SVN_CHANGELOG"
# shorten tabs at beginning of lines
sed -i 's/\t/ /' "$SVN_CHANGELOG"
cat > debian/changelog.new << EOF
$PACKAGE ($SNAPSHOT_VERSION) unstable; urgency=low
** SNAPSHOT build **
EOF
cat "$SVN_CHANGELOG" >> debian/changelog.new
cat >> debian/changelog.new << EOF
-- $DEBEMAIL $(date -u -R)
EOF
# append original changelog
cat debian/changelog >> debian/changelog.new
# finally install new changelog
mv debian/changelog.new debian/changelog
rm -f "$SVN_CHANGELOG"
}
case "${branch:-}" in
tags/*) echo "Building a tag version, not modifying the package" ;;
*) build_snapshot;;
esac
cd $ORIG_DIR
dpkg-source --tar-ignore=\.svn -b source/${branch:-}
# revert to original debian/changelog to avoid highly increasing version numbers with each build
( cd source/${branch:-} ; svn revert debian/changelog )
# 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}/"*