diff options
author | Erich Eckner <git@eckner.net> | 2018-01-31 15:37:44 +0100 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2018-01-31 15:37:44 +0100 |
commit | b3ae76ed20e9aaaf6e45e3ac8146898d895b65b6 (patch) | |
tree | 3b1c48f67d0eabfef997b7fafa98a22ac53a3f99 | |
parent | 4b729829aa589aed54d2811ad0190a00b6914e46 (diff) | |
download | builder-b3ae76ed20e9aaaf6e45e3ac8146898d895b65b6.tar.xz |
bin/modify-package-state: solely rely on database
-rwxr-xr-x | bin/modify-package-state | 284 |
1 files changed, 118 insertions, 166 deletions
diff --git a/bin/modify-package-state b/bin/modify-package-state index b157d49..477f3c3 100755 --- a/bin/modify-package-state +++ b/bin/modify-package-state @@ -1,5 +1,7 @@ #!/bin/sh +# shellcheck disable=SC2039 + # shellcheck source=conf/default.conf . "${0%/*}/../conf/default.conf" @@ -97,12 +99,6 @@ if [ $# -ne 1 ]; then usage fi -clean_up() { - rm -rf --one-file-system "${tmp_dir}" -} -tmp_dir=$(mktemp -d 'tmp.modify-package-state.XXXXXXXXXX' --tmpdir) -trap clean_up EXIT - input_file="$1" if ${report}; then if ! [ -w "${input_file}" ]; then @@ -113,10 +109,9 @@ if ${report}; then fi move_output() { cat "${output_file}" > "${input_file}" - clean_up + rm -f "${output_file}" } - output_file="${tmp_dir}/output-file" - touch "${output_file}" + output_file=$(mktemp 'tmp.modify-package-state.XXXXXXXXXX') trap 'move_output' EXIT else output_file='/dev/null' @@ -135,163 +130,120 @@ if ! flock -s -n 9; then exit fi -if [ "${action}" = 'tested' ]; then - receive_buglist 'Testing' > \ - "${tmp_dir}/package-bug-titles" -fi +# TODO: handle bug reports, too +# receive_buglist 'Testing' -{ - err=0 - while read -r package reason; do - if echo "${package}" | \ - grep -q '\.pkg\.tar\.xz$'; then - package=$( - find "${work_dir}/package-states" -maxdepth 1 \( -name '*.tested' -o -name '*.testing' \) \ - -exec grep -qxF "${package}" '{}' \; \ - -printf '%f\n' | \ - sed 's|\.[^.]\+$||' | \ - sort -u +while read -r package reason; do + case "${action}" in + 'faulty'|'tested') + # we expect a binary package identifier (pkgname-epoch:pkgver-pkgrel.sub_pkgrel-arch[".pkg.tar.xz"]) + # and we will only operate on packages in "testing" repositories + # shellcheck disable=SC2016 + combiner=$( + printf '`binary_packages`' + printf ' JOIN `%s` ON `%s`.`id`=`%s`.`%s`' \ + 'repositories' 'repositories' 'binary_packages' 'repository' \ + 'repository_stabilities' 'repository_stabilities' 'repositories' 'stability' \ + 'architectures' 'architectures' 'binary_packages' 'architecture' ) - if [ -z "${package}" ]; then - continue - fi - fi - repo=$( - printf '%s' "${package##*.}" | \ - base64 -w0 - ) - pkgbase="${package%.*}" - mod_git_rev=$( - printf '%s' "${pkgbase##*.}" | \ - base64 -w0 - ) - pkgbase="${pkgbase%.*}" - git_rev=$( - printf '%s' "${pkgbase##*.}" | \ - base64 -w0 - ) - pkgbase=$( - printf '%s' "${pkgbase%.*}" | \ - base64 -w0 - ) - if [ "${action}" = 'block' ] || \ - [ "${action}" = 'unblock' ]; then - # these packages need to be on the build list - if ! tr ' ' '.' < \ - "${work_dir}/build-list" | \ - grep -qxF "${package}"; then - >&2 printf 'Package "%s" is not on the build-list.\n' "${package}" - err=2 - continue + # shellcheck disable=SC2016 + selector=$( + local pkgname + local epoch + local pkgver + local pkgrel + local sub_pkgrel + local arch + extract_pkgname_epoch_pkgver_pkgrel_sub_pkgrel_arch_from_package_name "${package}" + printf 'WHERE `repository_stabilities`.`name`="testing"' + printf ' AND `binary_packages`.`%s`=from_base64("%s")' \ + 'pkgname' "$(printf '%s' "${pkgname}" | base64 -w0)" \ + 'epoch' "$(printf '%s' "${epoch}" | base64 -w0)" \ + 'pkgver' "$(printf '%s' "${pkgver}" | base64 -w0)" \ + 'pkgrel' "$(printf '%s' "${pkgrel}" | base64 -w0)" \ + 'sub_pkgrel' "$(printf '%s' "${sub_pkgrel}" | base64 -w0)" + printf ' AND `architectures`.`name`=from_base64("%s")' \ + "$(printf '%s' "${arch}" | base64 -w0)" + ) + ;; + 'block'|'unblock') + # we expect a package source identifier (pkgbase.git_revision.mod_git_revision.repository) + # and we will only operate on packages in "unbuilt" repositories + # shellcheck disable=SC2016 + combiner=$( + printf '`build_assignments`' + printf ' JOIN `%s` ON `%s`.`id`=`%s`.`%s`' \ + 'package_sources' 'package_sources' 'build_assignments' 'package_source' \ + 'upstream_repositories' 'upstream_repositories' 'package_sources' 'upstream_package_repository' \ + 'binary_packages' 'build_assignments' 'binary_packages' 'build_assignment' \ + 'repositories' 'repositories' 'binary_packages' 'repository' \ + 'repository_stabilities' 'repository_stabilities' 'repositories' 'stability' + ) + # shellcheck disable=SC2016 + selector=$( + repository="${package##*.}" + pkgbase="${package%.*}" + mod_git_revision="${pkgbase##*.}" + pkgbase="${pkgbase%.*}" + git_revision="${pkgbase##*.}" + pkgbase="${pkgbase%.*}" + printf 'WHERE `repository_stabilities`.`name`="unbuilt"' + printf ' AND `upstream_repositories`.`name`=from_base64("%s")' \ + "$(printf '%s' "${repository}" | base64 -w0)" + printf ' AND `package_sources`.`%s`=from_base64("%s")' \ + 'pkgbase' "$(printf '%s' "${pkgbase}" | base64 -w0)" \ + 'git_revision' "$(printf '%s' "${git_revision}" | base64 -w0)" \ + 'mod_git_revision' "$(printf '%s' "${mod_git_revision}" | base64 -w0)" + ) + ;; + *) + >&2 printf 'Whooops, action "%s" not implemented yet.\n' "${action}" + exit 42 + ;; + esac + case "${action}" in + 'block') + if [ -z "${reason}" ]; then + >&2 printf 'No reason is given for blocking package "%s".\n' "${package}" + exit 2 fi - fi - case "${action}" in - 'block') - if [ -z "${reason}" ]; then - >&2 printf 'No reason is given for blocking package "%s".\n' "${package}" - err=2 - else - echo "${reason}" > \ - "${work_dir}/package-states/${package}.blocked" - # shellcheck disable=SC2016 - { - printf 'UPDATE `build_assignments`' - printf ' JOIN `package_sources` ON `build_assignments`.`package_source`=`package_sources`.`id`' - printf ' JOIN `upstream_repositories` ON `package_sources`.`upstream_package_repository`=`upstream_repositories`.`id`' - printf ' SET `build_assignments`.`is_blocked`=from_base64("%s")' \ - "$(printf '%s' "${reason}" | base64 -w0)" - printf ' WHERE' - printf ' `package_sources`.`%s`=from_base64("%s") AND' \ - 'pkgbase' "${pkgbase}" \ - 'git_revision' "${git_rev}" \ - 'mod_git_revision' "${mod_git_rev}" - printf ' `upstream_repositories`.`name`=from_base64("%s");\n' \ - "${repo}" - } | tee /dev/stderr | \ - ${mysql_command} - printf '%s %s\n' "${package}" "${reason}" - fi - ;; - 'faulty') - if [ -f "${work_dir}/package-states/${package}.tested" ]; then - mv \ - "${work_dir}/package-states/${package}.tested" \ - "${work_dir}/package-states/${package}.testing" - # shellcheck disable=SC2016 - { - printf 'UPDATE `binary_packages`' - printf ' JOIN `%s` ON `%s`.`id`=`%s`.`%s`' \ - 'build_assignments' 'build_assignments' 'binary_packages' 'build_assignment' \ - 'package_sources' 'package_sources' 'build_assignments' 'package_source' \ - 'upstream_repositories' 'upstream_repositories' 'package_sources' 'upstream_package_repository' - printf ' SET `binary_packages`.`has_issues`=1, `binary_packages`.`is_tested`=0' - printf ' WHERE' - printf ' `package_sources`.`%s`=from_base64("%s") AND' \ - 'pkgbase' "${pkgbase}" \ - 'git_revision' "${git_rev}" \ - 'mod_git_revision' "${mod_git_rev}" - printf ' `upstream_repositories`.`name`=from_base64("%s");\n' \ - "${repo}" - } | \ - ${mysql_command} - printf '%s\n' "${package}" - fi - ;; - 'tested') - if [ -f "${work_dir}/package-states/${package}.testing" ] && \ - ! grep -qF "[${package%.*.*.*}]" "${tmp_dir}/package-bug-titles"; then - mv \ - "${work_dir}/package-states/${package}.testing" \ - "${work_dir}/package-states/${package}.tested" - # shellcheck disable=SC2016 - { - printf 'UPDATE `binary_packages`' - printf ' JOIN `%s` ON `%s`.`id`=`%s`.`%s`' \ - 'build_assignments' 'build_assignments' 'binary_packages' 'build_assignment' \ - 'package_sources' 'package_sources' 'build_assignments' 'package_source' \ - 'upstream_repositories' 'upstream_repositories' 'package_sources' 'upstream_package_repository' - printf ' SET `binary_packages`.`is_tested`=1' - printf ' WHERE' - printf ' `package_sources`.`%s`=from_base64("%s") AND' \ - 'pkgbase' "${pkgbase}" \ - 'git_revision' "${git_rev}" \ - 'mod_git_revision' "${mod_git_rev}" - printf ' `upstream_repositories`.`name`=from_base64("%s");\n' \ - "${repo}" - } | \ - ${mysql_command} - printf '%s\n' "${package}" - fi - ;; - 'unblock') - if [ -f "${work_dir}/package-states/${package}.blocked" ]; then - rm "${work_dir}/package-states/${package}.blocked" - # shellcheck disable=SC2016 - { - printf 'UPDATE `build_assignments`' - printf ' JOIN `package_sources` ON `build_assignments`.`package_source`=`package_sources`.`id`' - printf ' JOIN `upstream_repositories` ON `package_sources`.`upstream_package_repository`=`upstream_repositories`.`id`' - printf ' SET `build_assignments`.`is_blocked`=NULL' - printf ' WHERE' - printf ' `package_sources`.`%s`=from_base64("%s") AND' \ - 'pkgbase' "${pkgbase}" \ - 'git_revision' "${git_rev}" \ - 'mod_git_revision' "${mod_git_rev}" - printf ' `upstream_repositories`.`name`=from_base64("%s");\n' \ - "${repo}" - } | \ - ${mysql_command} - printf '%s\n' "${package}" - fi - ;; - *) - >&2 printf 'Whooops, action "%s" not implemented yet.\n' "${action}" - exit 42 - ;; - esac - done > \ - "${output_file}" - - exit ${err} -} < \ - "${input_file}" + tester='1' + # shellcheck disable=SC2016 + modifier=$( + printf '`build_assignments`.`is_blocked`=from_base64("%s")' \ + "$(printf '%s' "${reason}" | base64 -w0)" + ) + ;; + 'unblock') + # shellcheck disable=SC2016 + tester='NOT `build_assignments`.`is_blocked` IS NULL' + # shellcheck disable=SC2016 + modifier='`build_assignments`.`is_blocked`=NULL' + ;; + 'faulty') + # shellcheck disable=SC2016 + tester='`binary_packages`.`has_issues`=0' + # shellcheck disable=SC2016 + modifier='`binary_packages`.`is_tested`=0,`binary_packages`.`has_issues`=1' + ;; + 'tested') + # shellcheck disable=SC2016 + tester='`binary_packages`.`is_tested`=0' + # shellcheck disable=SC2016 + modifier='`binary_packages`.`is_tested`=1' + ;; + *) + >&2 printf 'Whooops, action "%s" not implemented yet.\n' "${action}" + exit 42 + ;; + esac + if printf 'SELECT 1 FROM %s %s AND %s LIMIT 1' "${combiner}" "${selector}" "${tester}" | \ + ${mysql_command} --raw --batch | \ + sed '1d' | \ + grep -qxF '1'; then + printf 'UPDATE %s SET %s %s' "${combiner}" "${modifier}" "${selector}" | \ + ${mysql_command} + fi +done \ + < "${input_file}" \ + > "${output_file}" |