[build] Refactoring

This commit is contained in:
Michal Srb 2014-04-28 14:06:03 +02:00
parent e28a9f0bc3
commit f1f7e7ef28

72
build.bash Executable file → Normal file
View File

@ -1,42 +1,58 @@
#!/bin/bash -ex #!/bin/bash -ex
JSTART=`date` resultdir="/var/lib/mock/fedora-rawhide-x86_64/result"
RPMDIR="/var/lib/mock/fedora-rawhide-x86_64/result" # download spec file
curl https://raw.github.com/msrb/jenkins-configs/xmvn/xmvn.spec > xmvn.spec
VERSION=$(sed -n '/<version>/{s/.*>\(.*\)<.*/\1/;s/-SNAPSHOT$//;p;q}' pom.xml) # create directories
RELEASE=$(git describe --match="[^(jenkins)].*" --tags | sed 's/[^-]*-/0./;s/-/./;s/g/git/') repo=RPM/latest/
git archive -v --prefix=xmvn-${VERSION}/ HEAD | xz > xmvn-${VERSION}.tar.xz [[ ! -d ${repo} ]] && mkdir -p ${repo}
sed -i "s/^Version:\s\+[0-9.]*$/Version: ${VERSION}/" xmvn.spec
sed -i "s/^Release:\s\+[0-9.]*%{?dist}$/Release: ${RELEASE}/" xmvn.spec
# update version and release tag in spec file
version=$(sed -n '/<version>/{s/.*>\(.*\)<.*/\1/;s/-SNAPSHOT$//;p;q}' pom.xml)
release=$(git describe --match="[^(jenkins)].*" --tags | sed 's/[^-]*-/0./;s/-/./;s/g/git/')
sed -i "s/^Version:\s\+[0-9.]*$/Version: ${version}/" xmvn.spec
sed -i "s/^Release:\s\+[0-9.]*%{?dist}$/Release: ${release}/" xmvn.spec
# make tarball
git archive -v --prefix=javapackages-${version}/ HEAD | xz > javapackages-${version}.tar.xz
# print root.log and build.log in case of failure
trap "cat ${resultdir}/root.log | tail -30; cat ${resultdir}/build.log || :" 0
# crate srpm
rm -f SRPMS/* rm -f SRPMS/*
rpmbuild -bs --clean --define "_topdir `pwd`" --define "_sourcedir `pwd`" xmvn.spec rpmbuild -bs --clean --define "_topdir `pwd`" --define "_sourcedir `pwd`" xmvn.spec
trap "cat ${RPMDIR}/build.log || :" 0 # build RPM with custom mock config
rm -rf ${RPMDIR} rm -Rf ${resultdir}/*
mock -r fedora-rawhide-x86_64 SRPMS/*.src.rpm mock -r fedora-rawhide-x86_64 SRPMS/*.src.rpm
LAST_BN=`grep "Build number" RPM/latest/info.log | awk '{ print $3 }'` # remove unneeded stuff
mkdir -p RPM/${LAST_BN}
mv RPM/latest/* RPM/${LAST_BN}
echo $LAST_BN
# we only want keep RPMs from last 10 builds
REMOVE_BN=`expr $LAST_BN - 10`
rm -Rf RPM/${REMOVE_BN}
# copy resulting RPMs to RPM/latest
rm -Rf RPM/latest
cp -a ${RPMDIR} RPM/latest
createrepo RPM/latest/
rm -f xmvn-*.tar.xz rm -f xmvn-*.tar.xz
JEND=`date` last_bn=`grep "Build number" ${repo}/info.log | awk '{ print $3 }'`
if [ -n "${last_bn}" ]; then
mkdir -p RPM/${last_bn}
mv ${repo}/* RPM/${last_bn}
echo "Job start: $JSTART" > RPM/latest/info.log # we only want keep RPMs from last 10 builds
echo "Job end: $JEND" >> RPM/latest/info.log blist=`find ./RPM/ -maxdepth 1 -name "[0-9]*"`
echo "Build number: $BUILD_NUMBER" >> RPM/latest/info.log for bn in $blist; do
if [ `basename $bn` -lt `expr $last_bn - 10` ]; then
rm -Rf $bn
fi
done
fi
# copy resulting RPMs to RPM/latest
cp ${resultdir}/* ${repo}
tail -n 50 ${resultdir}/build.log
createrepo ${repo}
# store current build number into the file
echo "Build number: $BUILD_NUMBER" >> ${repo}/info.log