#!/bin/sh
# report about status of build master
# shellcheck disable=SC2119,SC2120
# shellcheck source=../lib/load-configuration
. "${0%/*}/../lib/load-configuration"
tmp_dir=$(mktemp -d 'tmp.build-master-status.XXXXXXXXXX' --tmpdir)
trap 'rm -rf --one-file-system "${tmp_dir}"' EXIT
# do not block if locked
exec 9> "${sanity_check_lock_file}"
if ! verbose_flock -n 9; then
>&2 echo 'Mysql-Sanity check skipped, cannot acquire lock.'
exit
fi
# shellcheck disable=SC2119
mysql_cleanup
# update todos
find "${base_dir}/bin/" "${base_dir}/conf/" "${base_dir}/lib/" -type f \
-exec grep -nHF '' '{}' \; | \
sed 's,^'"$(str_to_regex "${base_dir}")"'/,,' | \
sed -n '
/^[^:]\+:[0-9]\+:\s*#\s*TODO:/ {
:a
$! {
N
s/\n[^:[:space:]]\+:[0-9]\+:\s*\([^#[:space:]].*\)\?$//
Ta
}
s/\n[^:[:space:]]\+:[0-9]\+:\s*#\s*/\\\\n/g
s/^\([^:]\+\):\([0-9]\+\):\s*#\s*TODO:\s*/\1\t\2\t/
p
}
' > "${tmp_dir}/todos"
if [ -s "${tmp_dir}/todos" ]; then
# shellcheck disable=SC2016
{
printf 'SHOW CREATE TABLE `todos`' | \
mysql_run_query | \
sed '
1s/^\S\+\s\+CREATE TABLE `todos` /CREATE TEMPORARY TABLE `td` /
s/ NOT NULL AUTO_INCREMENT/ NULL/
s/PRIMARY KEY/INDEX/
'
printf ';\n'
printf 'LOAD DATA LOCAL INFILE "%s" INTO TABLE `td` (`file`,`line`,`description`);\n' \
"${tmp_dir}/todos"
for matches in 'file line description' 'file description' 'file line' 'description'; do
printf 'UPDATE `td`'
printf ' JOIN `todos`'
for match in ${matches}; do
printf ' AND `td`.`%s`=`todos`.`%s`' \
"${match}" "${match}"
done | \
sed 's/^ AND / ON /'
printf ' SET `td`.`id`=`todos`.`id`'
printf ' WHERE `td`.`id` IS NULL;\n'
done
printf 'UPDATE `todos`'
printf ' JOIN `td` ON `todos`.`id`=`td`.`id`'
printf ',`todos`.`%s`=`td`.`%s`' \
'file' 'file' \
'line' 'line' \
'description' 'description' | \
sed 's/^,/ SET /'
printf ';\n'
printf 'INSERT IGNORE INTO `todos` (`file`,`line`,`description`)'
printf ' SELECT `td`.`file`,`td`.`line`,`td`.`description`'
printf ' FROM `td`'
printf ' WHERE `td`.`id` IS NULL;\n'
printf 'DELETE FROM `todos` WHERE NOT EXISTS ('
printf 'SELECT 1 FROM `td`'
printf ' AND `td`.`%s`=`todos`.`%s`' \
'file' 'file' \
'line' 'line' \
'description' 'description' | \
sed 's/^ AND / WHERE /'
printf ');\n'
printf 'DROP TEMPORARY TABLE `td`;\n'
printf 'DELETE FROM `todo_links` WHERE NOT EXISTS ('
printf 'SELECT 1 FROM `todos` '
printf 'WHERE `todos`.`id`=`todo_links`.`depending_on`'
printf ') OR NOT EXISTS ('
printf 'SELECT 1 FROM `todos` '
printf 'WHERE `todos`.`id`=`todo_links`.`dependent`'
printf ');\n'
} | \
mysql_run_query
fi
rm -f "${tmp_dir}/todos"
{
mysql_sanity_check || true
} | \
sed '
s,^-.*$,\0,
s,^+.*$,\0,
s/$/
/
1 i
sanity of the buildmaster'"'"'s mysql database
$ a
' | \
sponge "${webserver_directory}/mysql-sanity.html"
if [ -s "${webserver_directory}/mysql-sanity.html" ] && \
[ ! -s "${work_dir}/build-master-sanity" ]; then
# shellcheck disable=SC2119
{
printf 'girls, my database is dirty again ...\n'
printf 'dirty! girls, my database - so dirty :-(\n'
printf 'girls, please have a look at my dirty database'
} | \
shuf -n1 | \
irc_say
echo 'build master is insane' > \
"${work_dir}/build-master-sanity"
fi
if [ ! -s "${work_dir}/build-master-sanity" ]; then
# shellcheck disable=SC2016
{
printf 'INSERT IGNORE INTO `statistics` ('
printf '`%s`,' \
'stable_packages_count' \
'pending_tasks_count' \
'pending_packages_count' \
'staging_packages_count' \
'testing_packages_count' \
'tested_packages_count' \
'broken_tasks_count' \
'dependency_loops_count' \
'dependency_looped_tasks_count' \
'locked_tasks_count' \
'blocked_tasks_count' \
'next_tasks_count' | \
sed 's/,$//'
printf ') VALUES ('
# stable_packages_count
printf '(SELECT COUNT(DISTINCT `binary_packages`.`id`) FROM'
printf ' `binary_packages`'
mysql_join_binary_packages_binary_packages_in_repositories
mysql_join_binary_packages_in_repositories_repositories
# shellcheck disable=SC2154
printf ' WHERE `repositories`.`stability`=%s),' \
"${repository_stability_ids__stable}"
# pending_tasks_count
printf '(SELECT COUNT(DISTINCT `build_assignments`.`id`) FROM'
printf ' `build_assignments`'
mysql_join_build_assignments_binary_packages
mysql_join_binary_packages_binary_packages_in_repositories
printf ' WHERE `binary_packages_in_repositories`.`repository`=%s),' \
"${repository_ids__any_build_list}"
# pending_packages_count
printf '(SELECT COUNT(DISTINCT `binary_packages`.`id`) FROM'
printf ' `binary_packages`'
mysql_join_binary_packages_binary_packages_in_repositories
printf ' WHERE `binary_packages_in_repositories`.`repository`=%s),' \
"${repository_ids__any_build_list}"
# staging_packages_count
printf '(SELECT COUNT(DISTINCT `binary_packages`.`id`) FROM'
printf ' `binary_packages`'
mysql_join_binary_packages_binary_packages_in_repositories
mysql_join_binary_packages_in_repositories_repositories
# shellcheck disable=SC2154
printf ' WHERE `repositories`.`stability`=%s),' \
"${repository_stability_ids__staging}"
# testing_packages_count
printf '(SELECT COUNT(DISTINCT `binary_packages`.`id`) FROM'
printf ' `binary_packages`'
mysql_join_binary_packages_binary_packages_in_repositories
mysql_join_binary_packages_in_repositories_repositories
# shellcheck disable=SC2154
printf ' WHERE `repositories`.`stability`=%s' \
"${repository_stability_ids__testing}"
printf ' AND NOT `binary_packages`.`is_tested`),'
# tested_packages_count
printf '(SELECT COUNT(DISTINCT `binary_packages`.`id`) FROM'
printf ' `binary_packages`'
mysql_join_binary_packages_binary_packages_in_repositories
mysql_join_binary_packages_in_repositories_repositories
printf ' WHERE `repositories`.`stability`=%s' \
"${repository_stability_ids__testing}"
printf ' AND `binary_packages`.`is_tested`),'
# broken_tasks_count
printf '(SELECT COUNT(DISTINCT `build_assignments`.`id`) FROM'
printf ' `build_assignments`'
mysql_join_build_assignments_binary_packages
mysql_join_binary_packages_binary_packages_in_repositories
printf ' WHERE `binary_packages_in_repositories`.`repository`=%s' \
"${repository_ids__any_build_list}"
printf ' AND `build_assignments`.`is_broken`),'
# dependency_loops_count
printf '(SELECT COUNT(DISTINCT `build_dependency_loops`.`loop`) FROM'
printf ' `build_dependency_loops`),'
# dependency_looped_tasks_count
printf '(SELECT COUNT(DISTINCT `build_dependency_loops`.`build_assignment`) FROM'
printf ' `build_dependency_loops`),'
# locked_tasks_count
printf '(SELECT COUNT(DISTINCT `build_slaves`.`currently_building`) FROM'
printf ' `build_slaves`'
mysql_join_build_slaves_build_assignments
mysql_join_build_assignments_binary_packages
mysql_join_binary_packages_binary_packages_in_repositories
printf ' WHERE `binary_packages_in_repositories`.`repository`=%s),' \
"${repository_ids__any_build_list}"
# blocked_tasks_count
printf '(SELECT COUNT(DISTINCT `build_assignments`.`id`) FROM'
printf ' `build_assignments`'
mysql_join_build_assignments_binary_packages
mysql_join_binary_packages_binary_packages_in_repositories
printf ' WHERE `binary_packages_in_repositories`.`repository`=%s' \
"${repository_ids__any_build_list}"
printf ' AND `build_assignments`.`is_blocked` IS NOT NULL),'
# next_tasks_count
printf '(SELECT COUNT(DISTINCT `build_assignments`.`id`) FROM'
printf ' `build_assignments`'
mysql_join_build_assignments_binary_packages
mysql_join_binary_packages_binary_packages_in_repositories
printf ' WHERE `binary_packages_in_repositories`.`repository`=%s' \
"${repository_ids__any_build_list}"
printf ' AND ('
printf 'NOT EXISTS ('
printf 'SELECT 1 FROM `dependencies`'
mysql_join_dependencies_dependency_types
printf ' AND `dependency_types`.`relevant_for_building`'
mysql_join_dependencies_install_target_providers
mysql_join_install_target_providers_binary_packages '' 'prov_bp'
mysql_join_binary_packages_binary_packages_in_repositories 'prov_bp' 'prov_bpir'
printf ' WHERE `prov_bpir`.`repository`=%s' \
"${repository_ids__any_build_list}"
printf ' AND `dependencies`.`dependent`=`binary_packages`.`id`'
printf ') OR EXISTS ('
printf 'SELECT 1 FROM `build_dependency_loops`'
printf ' WHERE `build_dependency_loops`.`build_assignment`=`build_assignments`.`id`'
printf ')'
printf '))'
printf ');\n'
} | \
mysql_run_query
fi