96efd1
#!/bin/bash -ex
96efd1
ba865b
resultdir="/var/lib/mock/javapackages-rawhide/result/"
96efd1
ba865b
# create directories
ba865b
repo=RPM/latest/
ba865b
[[ ! -d ${repo} ]] && mkdir -p ${repo}
96efd1
ba865b
# update version and release tag in spec file
ba865b
version=`sed 's/-SNAPSHOT//' VERSION`
ba865b
release=$(git describe --match="[^(jenkins)].*" --tags | sed 's/[^-]*-/0./;s/-/./;s/g/git/')
ba865b
sed -i "s/^Version:\s\+[0-9.]*$/Version: ${version}/" javapackages-tools.spec
ba865b
sed -i "s/^Release:\s\+[0-9.]*%{?dist}$/Release: ${release}/" javapackages-tools.spec
96efd1
ba865b
# make tarball
ba865b
git archive -v --prefix=javapackages-${version}/ HEAD | xz > javapackages-${version}.tar.xz
96efd1
ba865b
# print root.log and build.log in case of failure
ba865b
trap "cat ${resultdir}/root.log | tail -30; cat ${resultdir}/build.log || :" 0
ba865b
ba865b
# crate srpm
96efd1
rm -f SRPMS/*
96efd1
rpmbuild -bs --clean --define "_topdir `pwd`" --define "_sourcedir `pwd`" javapackages-tools.spec
96efd1
ba865b
# build RPM with custom mock config
ba865b
rm -Rf ${resultdir}/*
96efd1
mock -r ../..$PWD/fedora-rawhide-x86_64 SRPMS/*.src.rpm
96efd1
6ee674
# get nosetests results
5cf8ff
mock -r ../..$PWD/fedora-rawhide-x86_64 --copyout /builddir/build/BUILD/javapackages-${version}/test/nosetests.xml .
6ee674
ba865b
# remove unneeded stuff
ba865b
rm -f javapackages-*.tar.xz
96efd1
ba865b
last_bn=`grep "Build number" ${repo}/info.log | awk '{ print $3 }'`
ba865b
if [ -n "${last_bn}" ]; then
ba865b
    mkdir -p RPM/${last_bn}
ba865b
    mv ${repo}/* RPM/${last_bn}
ba865b
ba865b
    # we only want keep RPMs from last 10 builds
538d00
    blist=`find ./RPM/ -maxdepth 1 -name "[0-9]*"`
ba865b
    for bn in $blist; do
ba865b
        if [ `basename $bn` -lt `expr $last_bn - 10` ]; then
538d00
            rm -Rf $bn
ba865b
        fi
ba865b
    done
96efd1
fi
96efd1
96efd1
# copy resulting RPMs to RPM/latest
ba865b
cp ${resultdir}/* ${repo}
96efd1
ba865b
tail -n 50 ${resultdir}/build.log
96efd1
ba865b
createrepo ${repo}
96efd1
ba865b
# store current build number into the file
ba865b
echo "Build number: $BUILD_NUMBER" >> ${repo}/info.log
96efd1