From: Matthias Kruk Date: Sun, 26 Sep 2021 06:55:39 +0000 (+0900) Subject: dispatchbot: Send signrequest when a build succeeds X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=8528fcd01194c675fd7d7e4ce292450916b13a97;p=foundry dispatchbot: Send signrequest when a build succeeds Because handling of build notifications is not completely implemented in dispatchbot, no sign requests are emitted when a build has succeeded. This commit amends the dispatchbot implementation to correctly handle build notifications, and to send sign requests whenever a successful build has been observed. --- diff --git a/dispatchbot.sh b/dispatchbot.sh index 8de69fa..b57ecd5 100755 --- a/dispatchbot.sh +++ b/dispatchbot.sh @@ -2,30 +2,26 @@ emit_signrequest() { local endpoint="$1" - local buildmsg="$2" + local context="$2" + local artifacts=("${@:3}") local signrequest - local artifacts - local artifact - local have_artifacts - - artifacts=() - have_artifacts=false + local dst - while read -r artifact; do - artifacts+=("$artifact") - have_artifacts=true - done < <(foundry_msg_build_get_artifacts "$buildmsg") + dst="pub/signbot" - if ! "$have_artifacts"; then + if (( ${#artifacts[@]} == 0 )); then + log_warn "Nothing to be signed for $context" return 1 fi - if ! signrequest=$(foundry_msg_signrequest_new "$tid" "${artifacts[@]}"); then + if ! signrequest=$(foundry_msg_signrequest_new "$context" "${artifacts[@]}"); then + log_error "Could not make sign request for $context" return 1 fi - if ! ipc_endpoint_send "$endpoint" "pub/signbot" "$signrequest"; then + if ! ipc_endpoint_send "$endpoint" "$dst" "$signrequest"; then + log_error "Could not send signrequest to $dst" return 1 fi @@ -153,18 +149,39 @@ _handle_build() { local endpoint="$1" local msg="$2" + local context + local artifacts + local artifact local result + artifacts=() + + if ! context=$(foundry_msg_build_get_context "$msg"); then + log_warn "Dropping message without context" + return 0 + fi + if ! result=$(foundry_msg_build_get_result "$msg"); then - return 1 + log_warn "Dropping message without result" + return 0 fi - if (( result == 0 )); then - if ! emit_signrequest "$msg"; then - return 1 - fi + if (( result != 0 )); then + log_warn "Not emitting sign request for failed build $context" + return 0 fi + while read -r artifact; do + artifacts+=("$artifact") + done < <(foundry_msg_build_get_artifacts "$msg") + + if ! emit_signrequest "$endpoint" "$context" "${artifacts[@]}"; then + log_error "Could not emit sign request for $context" + return 1 + fi + + log_info "Sign request for $context emitted." + return 0 }