LogoKolab Groupware OBS > Projects
Log In

View File update.sh of Package phabricator (Project Infrastructure)

#!/bin/bash

function usage() {
    echo "Usage: $0 [--with-fedora-review]"
    exit 0
}

package=$(rpmspec --query --queryformat="%{NAME}\n" *.spec | head -n 1)

fedora_copr=0
fedora_review=0

copr_wait_opt="--nowait"

while [ $# -gt 0 ]; do
    case $1 in
        --wait)
                copr_wait_opt=""
                shift
            ;;

        --with-fedora-copr)
                fedora_copr=1
                shift
            ;;

        --with-fedora-review)
                fedora_review=1
                shift
            ;;

        *)
                usage
            ;;
    esac
done

if [ ! -d "${package}.git" ]; then
    git clone -b stable https://github.com/phacility/${package}.git ${package}.git
    pushd ${package}.git
else
    pushd ${package}.git
    git remote set-url origin https://github.com/phacility/${package}.git
    git fetch origin
    git reset --hard origin/stable
    git clean -d -f -x
fi

current_version=$(grep "%global git_full_version_hash" ../${package}.spec | awk '{print $3}')

git_short_version_hash=$(git rev-parse --short HEAD)
git_full_version_hash=$(git rev-parse HEAD)

commitepoch=$(git log HEAD^1..HEAD --oneline --format=%ct | head -n 1)
commitdate=$(date +%Y%m%d --date @${commitepoch})
months_behind=$(date +%Y%m%d --date @$(( ${commitepoch} - ( 31 * 24 * 3600 * 3 ) )))
months_ahead=$(date +%Y%m%d --date @$(( ${commitepoch} + ( 31 * 24 * 3600 * 3 ) )))

popd

if [ ! -f ${package}-${git_full_version_hash}.tar.gz ]; then
    rm -rf ${package}-*.tar.gz
    wget --content-disposition https://github.com/phacility/${package}/archive/${git_full_version_hash}.tar.gz#/${package}-${git_full_version_hash}.tar.gz
fi

sed -i -r \
    -e "s/git_short_version_hash .*$/git_short_version_hash ${git_short_version_hash}/g" \
    -e "s/git_full_version_hash .*$/git_full_version_hash ${git_full_version_hash}/g" \
    -e "s/revision_date [0-9]+$/revision_date ${commitdate}/g" \
    ${package}.spec

if [ "${package}" == "arcanist" ]; then
    sed -i -r \
        -e "s/Requires:(\s+)arcanist\(libphutil\) >= 0\.[0-9]+/Requires:\1arcanist\(libphutil\) >= 0\.${months_behind}/g" \
        -e "s/Requires:(\s+)arcanist\(libphutil\) <= 0\.[0-9]+/Requires:\1arcanist\(libphutil\) <= 0\.${months_ahead}/g" \
        ${package}.spec

elif [ "${package}" == "phabricator" ]; then
    sed -i -r \
        -e "s/Requires:(\s+)arcanist >= 0\.[0-9]+/Requires:\1arcanist >= 0\.${months_behind}/g" \
        -e "s/Requires:(\s+)arcanist <= 0\.[0-9]+/Requires:\1arcanist <= 0\.${months_ahead}/g" \
        -e "s/Requires:(\s+)phabricator\(libphutil\) >= 0\.[0-9]+/Requires:\1phabricator\(libphutil\) >= 0\.${months_behind}/g" \
        -e "s/Requires:(\s+)phabricator\(libphutil\) <= 0\.[0-9]+/Requires:\1phabricator\(libphutil\) <= 0\.${months_ahead}/g" \
        ${package}.spec
fi

if [ "${git_full_version_hash}" != "${current_version}" ]; then
    rpmdev-bumpspec \
        --new="0.${commitdate}.git${git_short_version_hash}" \
        --comment "Promote Week #$(date +'%V %Y' --date ${commitdate})" \
        ${package}.spec
else
    rpmdev-bumpspec \
        --comment "Rebuild" \
        ${package}.spec
fi

# Thanks, rpmdev-bumpspec ...
sed -i -r \
    -e "s/^Version:(\s+).*$/Version:\10.%{revision_date}.git%{git_short_version_hash}/g" \
    ${package}.spec

rm -rf *.src.rpm

if [ -d .osc/ ]; then
    osc ar

    osc build --no-verify CentOS_7 ${package}.spec && \
        rm -rf review-${package}/ ${package}-*.src.rpm && \
        cp /var/tmp/build-root/CentOS_7-x86_64/home/abuild/rpmbuild/SRPMS/${package}-*.src.rpm . || exit 1
fi

if [ ${fedora_review} -eq 1 ]; then
    fedora-review --verbose -n ${package}
fi

if [ ${fedora_copr} -eq 1 ]; then
    test -f ${package}-*.src.rpm || \
        rpmbuild --define "_srcdir $(pwd)" --define "_sourcedir $(pwd)" -bs ${package}.spec

    copr-cli build ${copr_wait_opt} phabricator *.src.rpm
fi