Files
kata-containers/obs-packaging/wait-obs.sh
Jose Carlos Venegas Munoz 7f94b70905 ci: Add steps to build obs packages.
- OBS packages are build based on kata head
- The OBS kata branch is created on demand
- TODO: Delete branch when is not needed anymore

Signed-off-by: Jose Carlos Venegas Munoz <jose.carlos.venegas.munoz@intel.com>
2019-06-28 23:47:32 -05:00

134 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
# Copyright (c) 2019 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
#
set -o errexit
set -o nounset
set -o pipefail
set -o errtrace
script_name="$(basename "${BASH_SOURCE[0]}")"
handle_error() {
local exit_code="${?}"
local line_number="${1:-}"
echo "Failed at $line_number: ${BASH_COMMAND}"
exit "${exit_code}"
}
trap 'handle_error $LINENO' ERR
script_dir=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
run_in_docker() {
if [ -n "${USE_DOCKER:-}" ]; then
# shellcheck source=scripts/obs-docker.sh
source "${script_dir}/scripts/obs-docker.sh"
packaging_repo_dir=$(cd "${script_dir}/.." && pwd)
docker_run "${packaging_repo_dir}/obs-packaging/wait-obs.sh" $@
exit 0
fi
}
# Check all project has finshed the build
wait_finish_building() {
while osc pr -q | grep '(building)'; do sleep 5; done
# just in case something goes wrong
while osc pr -q | grep '(building)'; do sleep 5; done
}
# obs distro final status is 'published'
# Check all distros are published
is_published() {
columns=$(osc pr -q -c | head -1 | column -t -s\;)
# print to show status
for c in ${columns}; do
if [ "${c}" == '_' ]; then
continue
fi
if ! echo "${c}" | grep 'published'; then
echo "waiting for : ${c}"
return 1
fi
done
return 0
}
# Wait that all repositories are published
wait_published() {
while ! is_published; do
echo "Waitling for all repos are published"
done
}
check_failed(){
failed_query=$(osc pr -c -s F)
regex=".*failed.*"
if [[ ${failed_query} =~ ${regex} ]];then
echo "ERROR: Build failed"
osc pr -V -s 'F'
exit 1
fi
echo "Nothing failed"
osc pr -q -c | tail -n +2 | column -t -s\;
return 0
}
usage() {
msg="${1:-}"
exit_code=$"${2:-0}"
cat <<EOT
${msg}
Usage:
${script_name} [--options]
options:
-h, --help: Show this help
--no-wait-publish : no wait that OBS publish packages
EOT
exit "${exit_code}"
}
main() {
run_in_docker $@
local no_wait_publish="false"
case "${1:-}" in
"-h"|"--help")
usage "Help" 0
;;
--no-wait-publish)
no_wait_publish="true"
shift
;;
-*)
usage "Invalid option: ${1:-}" 1
;;
esac
OBS_SUBPROJECT="${OBS_SUBPROJECT:-releases:x86_64:alpha}"
project="home:katacontainers:${OBS_SUBPROJECT}"
echo "Checkout: ${project}"
osc co "$project" || true
cd "$project" || exit 1
echo "Wait all is build"
wait_finish_building
echo "OK - build finished"
echo "Check failed"
check_failed
echo "OK - build did not fail"
if [ "${no_wait_publish}" == "true" ];then
echo " Requested not wait for publish"
exit
fi
echo "Wait for published"
wait_published
echo "OK - published"
}
main $@