
In case if we are not using gerrit we need to re-define path to source code. There are a number of variables that must be defined explicitly, otherwise custom build will fail. Example: 1) rpm REMOTE_REPO_HOST=perestroika-repo-tst.infra.mirantis.net \ RPM_OS_REPO_PATH=mos-repos/centos/mos8.0-centos7-fuel/os/ \ PROJECT_NAME=mos \ PROJECT_VERSION=8.0 \ PACKAGENAME=openstack/fuel-agent \ SRC_PROJECT=openstack/fuel-agent \ SOURCE_BRANCH=master \ CUSTOM_SRC_PATH=~/fuel-main/build/repos/fuel-agent \ ./build-fuel-rpm.sh 2) deb REMOTE_REPO_HOST=perestroika-repo-tst.infra.mirantis.net \ DEB_REPO_PATH=/mos-repos/ubuntu/8.0/ \ DEB_DIST_NAME=mos8.0 \ COMPONENTS='main restricted' \ PROJECT_NAME=mos \ PROJECT_VERSION=8.0 \ PACKAGENAME=openstack/fuel-agent \ SRC_PROJECT=openstack/fuel-agent \ SOURCE_BRANCH=master \ CUSTOM_SRC_PATH=~/fuel-main/build/repos/fuel-agent \ ./build-fuel-deb.sh Change-Id: I95a6fa4fe8f5d1a95b68d106bead732a8d43c85e
130 lines
5.4 KiB
Bash
Executable File
130 lines
5.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -o xtrace
|
|
set -o errexit
|
|
|
|
[ -f .fuel-default ] && source .fuel-default
|
|
BINDIR=$(dirname `readlink -e $0`)
|
|
source "${BINDIR}"/build-functions.sh
|
|
|
|
main () {
|
|
set_default_params
|
|
[ -n "$GERRIT_BRANCH" ] && SOURCE_BRANCH=$GERRIT_BRANCH && SOURCE_REFSPEC=$GERRIT_REFSPEC
|
|
[ -n "$GERRIT_PROJECT" ] && SRC_PROJECT=$GERRIT_PROJECT
|
|
PACKAGENAME=${SRC_PROJECT##*/}
|
|
local DEBSPECFILES="${PACKAGENAME}-src/debian"
|
|
|
|
# If we are triggered from gerrit env, let's keep current workflow,
|
|
# and fetch code from upstream
|
|
# otherwise let's define custom path to already prepared source code
|
|
# using $CUSTOM_SRC_PATH variable
|
|
if [ -n "${GERRIT_BRANCH}" ]; then
|
|
# Get package tree from gerrit
|
|
fetch_upstream
|
|
local _srcpath="${MYOUTDIR}/${PACKAGENAME}-src"
|
|
else
|
|
local _srcpath="${CUSTOM_SRC_PATH}"
|
|
fi
|
|
|
|
local _specpath=$_srcpath
|
|
local _debianpath=$_specpath
|
|
|
|
if [ -d "${_debianpath}/debian" ] ; then
|
|
# Unpacked sources and specs
|
|
local srcpackagename=`head -1 ${_debianpath}/debian/changelog | cut -d' ' -f1`
|
|
local version=`head -1 ${_debianpath}/debian/changelog | sed 's|^.*(||;s|).*$||' | awk -F "-" '{print $1}'`
|
|
local binpackagenames="`cat ${_debianpath}/debian/control | grep ^Package | cut -d' ' -f 2 | tr '\n' ' '`"
|
|
local epochnumber=`head -1 ${_debianpath}/debian/changelog | grep -o "(.:" | sed 's|(||'`
|
|
local distro=`head -1 ${_debianpath}/debian/changelog | awk -F'[ ;]' '{print $3}'`
|
|
|
|
# Get last commit info
|
|
# $message $author $email $cdate $commitsha $lastgitlog
|
|
get_last_commit_info ${_srcpath}
|
|
|
|
# Get revision number as commit count for src+spec projects
|
|
local _rev=`git -C $_srcpath rev-list --no-merges origin/${SOURCE_BRANCH} | wc -l`
|
|
[ "$GERRIT_CHANGE_STATUS" == "NEW" ] && _rev=$(( $_rev + 1 ))
|
|
local release="1~u14.04+mos${_rev}"
|
|
# if gitshasrc is not defined (we are not using fetch_upstream), let's do it
|
|
[ -n "${gitshasrc}" ] || local gitshasrc=$(git -C $_srcpath log -1 --pretty="%h")
|
|
[ "$GERRIT_CHANGE_STATUS" == "NEW" ] && release="${release}+git.${gitshasrc}"
|
|
local fullver=${epochnumber}${version}-${release}
|
|
# Update version and changelog
|
|
local firstline=1
|
|
local _dchopts="-c ${_debianpath}/debian/changelog"
|
|
echo "$lastgitlog" | while read LINE; do
|
|
[ $firstline == 1 ] && local cmd="dch $_dchopts -D $distro -b --force-distribution -v $fullver" || local cmd="dch $_dchopts -a"
|
|
firstline=0
|
|
local commitid=`echo "$LINE" | cut -d'|' -f1`
|
|
local email=`echo "$LINE" | cut -d'|' -f2`
|
|
local author=`echo "$LINE" | cut -d'|' -f3`
|
|
local subject=`echo "$LINE" | cut -d'|' -f4`
|
|
DEBFULLNAME="$author" DEBEMAIL="$email" $cmd "$commitid $subject"
|
|
done
|
|
|
|
TAR_NAME="${srcpackagename}_${version#*:}.orig.tar.gz"
|
|
# Update changelog
|
|
DEBFULLNAME=$author DEBEMAIL=$email dch -c ${_debianpath}/debian/changelog -a "$commitsha $message"
|
|
# Prepare source tarball
|
|
# Exclude debian dir
|
|
pushd $_srcpath &>/dev/null
|
|
cat >.gitattributes<<-EOF
|
|
/debian export-ignore
|
|
/.gitignore export-ignore
|
|
/.gitreview export-ignore
|
|
EOF
|
|
git archive --prefix=./ --format=tar.gz --worktree-attributes HEAD --output="${BUILDDIR}/${TAR_NAME}"
|
|
popd &>/dev/null
|
|
|
|
mkdir -p ${BUILDDIR}/$srcpackagename
|
|
cp -R ${_debianpath}/debian ${BUILDDIR}/${srcpackagename}/
|
|
fi
|
|
|
|
# Build stage
|
|
local REQUEST=$REQUEST_NUM
|
|
[ -n "$LP_BUG" ] && REQUEST=$LP_BUG
|
|
|
|
COMPONENTS="main restricted"
|
|
[ -n "${EXTRAREPO}" ] && EXTRAREPO="${EXTRAREPO}|"
|
|
EXTRAREPO="${EXTRAREPO}http://${REMOTE_REPO_HOST}/${DEB_REPO_PATH} ${DEB_DIST_NAME} ${COMPONENTS}"
|
|
[ "$IS_UPDATES" == 'true' ] \
|
|
&& EXTRAREPO="${EXTRAREPO}|http://${REMOTE_REPO_HOST}/${DEB_REPO_PATH} ${DEB_PROPOSED_DIST_NAME} ${COMPONENTS}"
|
|
[ "$GERRIT_CHANGE_STATUS" == "NEW" ] && [ "$IS_UPDATES" == "false" ] \
|
|
&& EXTRAREPO="${EXTRAREPO}|http://${REMOTE_REPO_HOST}/${REPO_REQUEST_PATH_PREFIX}/${REQUEST}/${DEB_REPO_PATH} ${DEB_DIST_NAME} ${COMPONENTS}"
|
|
[ "$GERRIT_CHANGE_STATUS" == "NEW" ] && [ "$IS_UPDATES" == "true" ] \
|
|
&& EXTRAREPO="${EXTRAREPO}|http://${REMOTE_REPO_HOST}/${REPO_REQUEST_PATH_PREFIX}/${REQUEST}/${DEB_REPO_PATH} ${DEB_PROPOSED_DIST_NAME} ${COMPONENTS}"
|
|
export EXTRAREPO
|
|
|
|
pushd $BUILDDIR &>/dev/null
|
|
echo "BUILD_SUCCEEDED=false" > ${WRKDIR}/buildresult.params
|
|
bash -ex ${BINDIR}/docker-builder/build-deb-package.sh
|
|
local exitstatus=`cat buildresult/exitstatus.sbuild || echo 1`
|
|
rm -f buildresult/exitstatus.sbuild
|
|
[ -f "buildresult/buildlog.sbuild" ] && mv buildresult/buildlog.sbuild ${WRKDIR}/buildlog.txt
|
|
fill_buildresult $exitstatus 0 $PACKAGENAME DEB
|
|
if [ "$exitstatus" == "0" ] && [ -n "${GERRIT_BRANCH}" ]; then
|
|
tmpdir=`mktemp -d ${PKG_DIR}/build-XXXXXXXX`
|
|
rm -f ${WRKDIR}/buildresult.params
|
|
cat >${WRKDIR}/buildresult.params<<-EOL
|
|
BUILD_HOST=`hostname -f`
|
|
PKG_PATH=$tmpdir
|
|
GERRIT_CHANGE_STATUS=$GERRIT_CHANGE_STATUS
|
|
REQUEST_NUM=$REQUEST_NUM
|
|
LP_BUG=$LP_BUG
|
|
IS_SECURITY=$IS_SECURITY
|
|
EXTRAREPO="$EXTRAREPO"
|
|
REPO_TYPE=deb
|
|
DIST=$DIST
|
|
EOL
|
|
mv buildresult/* $tmpdir/
|
|
fi
|
|
popd &>/dev/null
|
|
echo "Packages: $PACKAGENAME"
|
|
|
|
exit $exitstatus
|
|
}
|
|
|
|
main $@
|
|
|
|
exit 0
|