#! /bin/sh

# Prepare main branch, review the list of branches below and then execute this
# script.

branches='main epel8 epel9 epel10 f39 f40 f41'

exit_handler ()
{
    git checkout main
}

trap exit_handler EXIT

set -e
set -x

koji hello

tasks=
for branch in $branches; do
    if test $branch != main; then
        git checkout "$branch"
        git merge main
    fi
    git push
    skip_nvr_check=
    if test $branch = epel7; then
        skip_nvr_check=--skip-nvr-check
    fi
    tasks="${tasks}`fedpkg build $skip_nvr_check --nowait | grep 'Created task' | cut -d: -f2`"
done

if test -n "$tasks"; then
    koji watch-task $tasks
fi

git checkout main
fedpkg update
