summaryrefslogtreecommitdiff
path: root/pw-trigger.sh
diff options
context:
space:
mode:
Diffstat (limited to 'pw-trigger.sh')
-rwxr-xr-xpw-trigger.sh87
1 files changed, 87 insertions, 0 deletions
diff --git a/pw-trigger.sh b/pw-trigger.sh
new file mode 100755
index 00000000..1d8c1181
--- /dev/null
+++ b/pw-trigger.sh
@@ -0,0 +1,87 @@
+#!/bin/bash
+
+set -euf -o pipefail +x
+
+scripts=$(dirname $0)
+# shellcheck source=jenkins-helpers.sh
+. $scripts/jenkins-helpers.sh
+
+convert_args_to_variables "$@"
+
+obligatory_variables ci_bot project pw_token out_dir
+declare ci_bot project pw_token out_dir
+
+verbose="${verbose-true}"
+
+if $verbose; then
+ set -x
+fi
+
+(set +x; pw_init "$project" "$pw_token")
+
+# Delete patches from the queue bundle. The fact that we are here means
+# that the jenkins queue is empty, and no more patches will be tested.
+# This can happen if a new version of series was uploaded and we tested
+# a different top-of-series patch.
+# We avoid deleting and re-creatthe queued bundles to conserve bundle IDs.
+queued_name=$(pw_bundle_name queued "$ci_bot")
+queued_id=$(pw_bundle_id "$project" "$queued_name" || true)
+while [ "$queued_id" != "" ]; do
+ patch_id=$(pw_get_patch_from_bundle_or_series \
+ "$project" bundle "$queued_id" 0)
+ git -C "$project" pw bundle remove -f yaml "$queued_id" "$patch_id" &
+ if ! wait $!; then
+ # "bundle remove" will refuse to delete the last patch.
+ break
+ fi
+done
+
+triggered_name=$(pw_bundle_name triggered "$ci_bot")
+triggered_id=$(pw_bundle_id "$project" "$triggered_name" || true)
+
+yaml=$(mktemp)
+trap "rm -f $yaml" EXIT
+
+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
+
+ num_patch=0
+ while true; do
+ patch_id=$(pw_get_patch_from_bundle_or_series \
+ "$project" series "$series_id" "$num_patch" || true)
+ if [ "$patch_id" = "" ]; then
+ break
+ fi
+
+ if ! pw_bundle_has_patch_p "$project" "$triggered_id" "$patch_id"; then
+ break
+ fi
+ num_patch=$(($num_patch + 1))
+ done
+
+ if [ "$patch_id" = "" ]; then
+ continue
+ fi
+
+ j=$(($j + 1))
+ cat > "$out_dir/trigger-precommit-$project-$j-$series_id" <<EOF
+${project}_git=pw://series/$series_id
+EOF
+
+ pw_ci_bot_bundle_check_and_add \
+ "$project" queued "$ci_bot" "$patch_id" true
+done
+
+echo "Processed $len series and created $j pre-commit triggers"