diff options
Diffstat (limited to 'pw-trigger.sh')
-rwxr-xr-x | pw-trigger.sh | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/pw-trigger.sh b/pw-trigger.sh new file mode 100755 index 00000000..3d91deee --- /dev/null +++ b/pw-trigger.sh @@ -0,0 +1,111 @@ +#!/bin/bash + +set -euf -o pipefail +x + +scripts=$(dirname $0) +# shellcheck source=jenkins-helpers.sh +. $scripts/jenkins-helpers.sh +# shellcheck source=pw-helpers.sh +. $scripts/pw-helpers.sh + +convert_args_to_variables "$@" + +obligatory_variables ci_bot project out_dir +declare ci_bot project out_dir + +verbose="${verbose-true}" + +if $verbose; then + set -x +fi + +# Print a list of prerequisite bots to wait for before triggering $ci_bot. +print_prereq_bots () +{ + ( + set -euf -o pipefail + local ci_bot="$1" + + # Wait for "build" bots to succeed before triggering "check" bot. + case "$ci_bot" in + tcwg_*_check--*) + echo "$ci_bot" | sed -e "s/_check--/_build--/" + ;; + esac + + # Wait for apply_patch to succeed before triggering glibc builds. + case "$ci_bot" in + tcwg_glibc_*--*) + echo "redhat-pt-bot/TryBot-apply_patch" + ;; + esac + ) +} + +# shellcheck disable=SC2064 +trap "pw_deinit $project" EXIT +pw_init "$project" + +yaml=$(mktemp) +# shellcheck disable=SC2064 +trap "pw_deinit $project; rm -f $yaml" EXIT + +readarray -t prereq_bots < <(print_prereq_bots "$ci_bot") + +git -C "$project" pw series list -f yaml > "$yaml" +mkdir -p "$out_dir" + +len=$(shyaml get-length < "$yaml") +i=$len +j=0 +# Go through series with the oldest first. +while [ "$i" -gt "0" ]; do + i=$(($i - 1)) + series_id=$(shyaml get-value $i.id < "$yaml") + + if ! pw_series_complete_p "$project" "$series_id"; then + continue + fi + + # Look for an untested patch in the series. + num_patch=0 + while true; do + patch_id=$(pw_get_patch_from_series \ + "$project" "$series_id" "$num_patch" || true) + if [ "$patch_id" = "" ]; then + break + fi + + check_state=$(pw_patch_check_state "$patch_id" "$ci_bot") + if [ "$check_state" = "pending" ]; then + break + fi + num_patch=$(($num_patch + 1)) + done + + if [ "$patch_id" = "" ]; then + continue + fi + + # Check that prerequisite bots finished OK. + check_state="success" + for prereq_bot in "${prereq_bots[@]}"; do + check_state=$(pw_patch_check_state "$patch_id" "$prereq_bot") + if [ "$check_state" != "success" ]; then + break + fi + done + if [ "$check_state" != "success" ]; then + echo "WARNING: Waiting for $patch_id:$prereq_bot to succeed." + continue + fi + + j=$(($j + 1)) + cat > "$out_dir/trigger-precommit-$project-$j-$series_id" <<EOF +${project}_git=pw://series/$series_id +EOF +done + +rm "$yaml" + +echo "Processed $len series and created $j pre-commit triggers" |