1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
#!/bin/sh
set -eu
verbose=${verbose-''}
if [ "${verbose}" = "yes" ]; then
set -x
fi
usage() {
printf "usage $0:\n"
printf "\t --dir <directory> : default ${DIR}\n"
}
function info() {
if [[ -n "${verbose}" ]]; then
echo "# $@"
fi
}
BRANCHES="main travis-fedora-rawhide travis-fedora-32 \
travis-fedora-31 travis-fedora-30 \
travis-fedora-29 travis-fedora-28 \
travis-centos-8 travis-centos-7 travis-centos-6 \
travis-ubuntu-focal travis-ubuntu-bionic travis-ubuntu-xenial \
travis-debian-experimental travis-debian-sid travis-debian-bullseye \
travis-debian-buster travis-debian-stretch travis-debian-jessie"
DIR="${DIR:-/home/build/git/libreswan}"
FETCH_REMOTE=yes
function list_default_branches() {
printf "${BRANCHES}\n"
}
OPTIONS=$(getopt -o hvs: --long verbose,dir:,help,list-branches,no-fetch -- "$@")
if (( $? != 0 )); then
err 4 "Error calling getopt"
fi
eval set -- "$OPTIONS"
while true; do
case "$1" in
-h | --help )
usage
exit 0
;;
--list-branches )
list_default_branches
exit 0
;;
--no-fetch | --no-etch-remote )
FETCH_REMOTE=no
shift
;;
--dir )
DIR=$2
shift 2
;;
-- ) shift; break ;;
* )
shift
break
;;
esac
done
cd ${DIR} || exit;
TIME=$(date "+%Y%m%d-%H%M")
E_START=$(date "+%s")
LOG="Push the branches to github: "
COUNTER=0
HEAD_ID_START=$(git rev-parse --short HEAD)
HEAD_ID_END=''
LOG_FILE=${LOG_FILE:-/var/tmp/github-push-error.txt}
HIST_LOG_FILE=${HIST_LOG_FILE:-/var/tmp/github-push.txt}
log_success ()
{
HEAD_ID_END=$(git rev-parse --short HEAD)
E_END=$(date "+%s")
ELAPSED=$((E_END - E_START))
LOG="${TIME} SUCCESS ${HEAD_ID_END} pushed ${COUNTER} branches elapsed ${ELAPSED} sec"
if [ "${HEAD_ID_END}" != "${HEAD_ID_START}" ] ; then
printf "${LOG}\n" >> ${HIST_LOG_FILE}
printf "${LOG}\n" >> ${LOG_FILE}
fi
}
clean_up ()
{
ARG=$?
HEAD_ID_END=$(git rev-parse --short HEAD)
E_END=$(date "+%s")
ELAPSED=$((E_END - E_START))
LOG="${TIME} ERROR ${HEAD_ID_START} ${HEAD_ID_END} branches ${COUNTER} ${LOG} elapsed ${ELAPSED} sec"
}
count_br()
{
for BR in ${BRANCHES}; do
COUNTER=$((COUNTER + 1))
done
}
git_work()
{
(
git checkout main
HEAD_ID_START=`git rev-parse --short HEAD`
if [ "${FETCH_REMOTE}" = "yes" ]; then
git fetch origin
git reset --hard origin/main
fi
HEAD_ID_END=$(git rev-parse --short HEAD)
if [ "${HEAD_ID_END}" = "${HEAD_ID_START}" -a "${FETCH_REMOTE}" = "yes" ] ; then
echo "${TIME} IGNORE ${HEAD_ID_START} NOTHING NEW"
return 0
fi
echo "${TIME} start ${HEAD_ID_START} after ${HEAD_ID_END} ${COUNTER} branches"
for BR in ${BRANCHES}; do
LOG="${LOG} ${BR}"
git checkout ${BR} || git checkout -b ${BR}
git reset --hard main
git push --follow-tags github -f
done
return 0
echo ${LOG}
) > ${LOG_FILE} 2>&1
}
trap clean_up EXIT
count_br
git_work
log_success
|