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.
210 lines
6.9 KiB
210 lines
6.9 KiB
#!/bin/bash
|
|
|
|
set -x
|
|
set -e
|
|
set -u
|
|
|
|
[ -n "${DEBEMAIL:-}" ] || DEBEMAIL="jenkins-debian-glue Autobuilder <jenkins@example.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 "${GIT_COMMIT:-}" ] ; then
|
|
echo "No GIT_COMMIT defined, please run it with git-plugin in jenkins. ">&2
|
|
exit 1
|
|
fi
|
|
|
|
JENKINS_DEBIAN_GLUE_VERSION=$(dpkg --list jenkins-debian-glue 2>/dev/null | awk '/^ii/ {print $3}')
|
|
if [ -n "${JENKINS_DEBIAN_GLUE_VERSION:-}" ] ; then
|
|
echo "*** Running jenkins-debian-glue version $JENKINS_DEBIAN_GLUE_VERSION ***"
|
|
fi
|
|
|
|
echo "*** source package build phase ***"
|
|
rm -f ./* || true
|
|
|
|
cd source
|
|
|
|
# retrieve and adjust information
|
|
ORIG_VERSION=$(dpkg-parsechangelog --count 1 | awk '/Version/ {print $2}')
|
|
INCREASED_VERSION=$(increase-version-number $ORIG_VERSION)
|
|
DISTRIBUTION=$(dpkg-parsechangelog --count 1 | awk '/^Distribution/ {print $2}')
|
|
|
|
# we want to get a version string like
|
|
# $ORIG_VERSION+0~$TIMESTAMP.$BUILD_NUMBER~1.$GIT_ID
|
|
# so the version is always increasing over time, no matter what
|
|
TIMESTAMP="$(date +%s)" # seconds since 1970-01-01 00:00:00 UTC, reversible via `date -d @$TIMESTAMP`
|
|
BUILD_VERSION="${TIMESTAMP}.${BUILD_NUMBER}" # git-dch appends something like ~1.gbp5f433e then
|
|
|
|
# we do NOT raise the version number, if we detect an unreleased version,
|
|
# otherwise the released version would be older than our snapshot builds
|
|
APPLY_VERSION_WORKAROUND=false
|
|
if [ "$DISTRIBUTION" = "UNRELEASED" ] && dpkg --compare-versions "$ORIG_VERSION" lt "$INCREASED_VERSION" ; then
|
|
echo "*** Not increasing version number as distribution is set to UNRELEASED ***"
|
|
INCREASED_VERSION="$ORIG_VERSION"
|
|
APPLY_VERSION_WORKAROUND=true
|
|
fi
|
|
|
|
VERSION_STRING="${INCREASED_VERSION}~${BUILD_VERSION}"
|
|
|
|
if [ -n "${distribution:-}" ] ; then
|
|
echo "Distribution variable found. Adding distribution specific version."
|
|
VERSION_STRING="${VERSION_STRING}+${distribution}"
|
|
fi
|
|
|
|
echo "*** Version string set to $VERSION_STRING ***"
|
|
|
|
# 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
|
|
DCH_EXTRA_OPTS="--new-version=${VERSION_STRING}"
|
|
echo "Using extra git-dch options (${DCH_EXTRA_OPTS})"
|
|
fi
|
|
|
|
create_local_branch() {
|
|
[ -n "${1:-}" ] || return 1
|
|
|
|
local BRANCH="$1"
|
|
|
|
if git branch -a | grep -q "remotes/origin/${BRANCH}"'$' ; then
|
|
git branch -D "${BRANCH}" || true
|
|
git branch "${BRANCH}" "remotes/origin/${BRANCH}"
|
|
else
|
|
echo "NOTE: branch $BRANCH does not exist, ignoring request to checkout therefore."
|
|
fi
|
|
}
|
|
|
|
git_dch_auto() {
|
|
if $APPLY_VERSION_WORKAROUND ; then
|
|
echo "Applying version workaround workaround"
|
|
dch -b --distribution=UNRELEASED --newversion=$VERSION_STRING -- \
|
|
"SNAPSHOT autobuild for unreleased $ORIG_VERSION via jenkins-debian-glue."
|
|
else
|
|
git-dch --auto $DCH_OPTS $DCH_EXTRA_OPTS
|
|
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
|
|
# by calling readlink
|
|
git checkout -- $(readlink -f debian/changelog)
|
|
|
|
local OLD_VERSION=$(dpkg-parsechangelog | awk '/^Version: / {print $2}')
|
|
|
|
local last_tag=$(git describe $(git rev-list --tags='[^u]*' --max-count=1 HEAD))
|
|
local last_merge=$(git describe $(git rev-list --all --merges --max-count=1 HEAD))
|
|
local since=${last_tag}
|
|
|
|
if [ -n "$last_merge" ] ; then
|
|
local merge_date=$(git log ${last_merge} --pretty="format:%at" -1)
|
|
local tag_date=$(git log ${last_tag} --pretty="format:%at" -1)
|
|
if [ ${merge_date} -gt ${tag_date} ] ; then
|
|
local since=${last_merge}
|
|
fi
|
|
fi
|
|
|
|
echo "Latest tag [${last_tag:-}] / merge [${last_merge:-}] seems to be $since"
|
|
git-dch -s "${since}" $DCH_OPTS $DCH_EXTRA_OPTS
|
|
|
|
local 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
|
|
# by calling readlink
|
|
git checkout -- $(readlink -f debian/changelog)
|
|
|
|
git_dch_auto
|
|
fi
|
|
}
|
|
|
|
git_tag_build() {
|
|
git checkout "${tag}"
|
|
|
|
if [ -n "${distribution:-}" ] ; then
|
|
echo "Distribution found. Adding distribution specific version (${distribution})."
|
|
dch -b -v "${VERSION_STRING}+${distribution:-}" \
|
|
"Tagged autobuild for ${distribution} via jenkins-debian-glue."
|
|
else
|
|
dch -v "${VERSION_STRING}" \
|
|
"Tagged autobuild via jenkins-debian-glue."
|
|
fi
|
|
}
|
|
|
|
# Clean up any unexpected local changes
|
|
#git reset --hard HEAD
|
|
|
|
# make sure common branches are available for git-buildpackage
|
|
create_local_branch upstream
|
|
create_local_branch debian
|
|
create_local_branch pristine-tar
|
|
|
|
# Drop residual files
|
|
#git clean -xfd
|
|
|
|
# git-dch and git-buildpackage refuse to operate on a single git
|
|
# commit, so instead create a temporary branch to work on
|
|
random_branch="jenkins-debian-glue-buildbranch$RANDOM"
|
|
echo "Checking out branch $random_branch based on $GIT_COMMIT"
|
|
git branch -D "$random_branch" || true
|
|
git checkout -b "$random_branch" "$GIT_COMMIT"
|
|
|
|
if [ -n "${tag:-}" ] ; then
|
|
echo "Tag parameter found, using dch for changelog generation."
|
|
git_tag_build
|
|
elif [ "${1:-}" = "identify" ] ; then
|
|
echo "Trying to identify latest tag / merge..."
|
|
|
|
if ! git describe $(git rev-list --tags='[^u]*' --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
|
|
elif [ -r debian/gbp.conf ] ; then
|
|
echo "Found debian/gbp.conf, using git-dch with auto mode."
|
|
git_dch_auto
|
|
else
|
|
echo "Using git-dch with auto mode."
|
|
git_dch_auto
|
|
fi
|
|
|
|
# get rid of "UNRELEASED" distribution header
|
|
debchange --release ""
|
|
|
|
# prepare orig.tar.gz using pristine-tar, but without actually building the source package
|
|
if [ "${IGNORE_GIT_BUILDPACKAGE:-}" = "true" ] ; then
|
|
echo "Skipping git-buildpackage execution as requested via IGNORE_GIT_BUILDPACKAGE ***"
|
|
else
|
|
git-buildpackage -nc --git-force-create --git-ignore-new -S -us -uc --git-verbose --git-builder=/bin/true --git-cleaner=/bin/true
|
|
fi
|
|
|
|
git checkout - # switch back to previous "branch" before removing the tmp branch
|
|
git branch -D "$random_branch"
|
|
|
|
# build source package
|
|
( cd .. ; dpkg-source -i\.git -b source )
|
|
|
|
# revert to original debian/changelog to avoid merge conflicts
|
|
git checkout -- debian/changelog
|
|
|
|
# vim:foldmethod=marker ts=2 ft=sh ai expandtab sw=2
|