diff options
Diffstat (limited to 'pw-apply.sh')
-rwxr-xr-x | pw-apply.sh | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/pw-apply.sh b/pw-apply.sh new file mode 100755 index 00000000..a7bbc974 --- /dev/null +++ b/pw-apply.sh @@ -0,0 +1,157 @@ +#!/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 pw_url pw_token pw_dir build_url +declare ci_bot project pw_url pw_token pw_dir build_url + +verbose="${verbose-true}" + +if $verbose; then + set -x +fi + +case "$pw_url" in + "pw://series/"*) + series_id=$(echo "$pw_url" | cut -d/ -f 4) + ;; + *) assert_with_msg "pw_url does not match pw://series/*" false ;; +esac + +retrigger=false +case "$pw_url/" in + "pw://series/"*"/retrigger/"*) retrigger=true ;; +esac + +url=$(get_baseline_git "${project}_url") +rev=$(get_baseline_git "${project}_rev") +echo "Fetching baseline $url#$rev" +clone_or_update_repo "$project" "$rev" "$url" > /dev/null + +# shellcheck disable=SC2064 +trap "pw_deinit $project" EXIT +pw_init "$project" + +if ! pw_series_complete_p "$project" "$series_id"; then + echo "ERROR: Series $series_id is not complete" + exit 2 +fi + +# Look for the first 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" = "" ] || $retrigger; 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 + echo "ERROR: All patches in series $series_id are already tested" + exit 3 +fi + +# Fetch and setup glibc-cicd.git. We use check.py to send status updates +# to the patchwork instance. +clone_or_update_repo glibc-cicd main \ + https://gitlab.com/djdelorie/glibc-cicd.git > /dev/null + +pw_check_cmd=(glibc-cicd/check.py --patch_id "$patch_id" + --context "$ci_bot") +# BE CAREFUL WITH $pw_token +set +x; +if [ "$pw_token" != "" ]; then + cat >> glibc-cicd/cicd-config.py <<EOF + +patchwork_token = "$pw_token" +EOF +else + pw_check_cmd=(echo "DRYRUN:" "${pw_check_cmd[@]}") +fi +if $verbose; then + set -x +fi + +patch_url="https://patchwork.sourceware.org/patch/$patch_id" +patch_message_id=$(pw_get_patch_data "$project" "$patch_id" "Message ID") +patch_submitter=$(pw_get_patch_data "$project" "$patch_id" "Submitter" \ + | sed -e "s/.*(\(.*\)).*/\1/") + +# Create a state file for this patch. This is sourced by pw-report.sh to avoid +# passing a bunch of parameters on the command line. +mkdir -p "$pw_dir" +cat > "$pw_dir/$project" <<EOF +pw[project]='$project' +pw[${project}]='$project' +pw[${project}_patch_id]='$patch_id' +pw[${project}_check_cmd]='${pw_check_cmd[*]}' +pw[${project}_build_url]='$build_url' +pw[${project}_patch_url]='$patch_url' +pw[${project}_patch_message_id]='$patch_message_id' +pw[${project}_patch_submitter]='$patch_submitter' +EOF + +# Below calls to pw-report.sh will run their own pw_init/pw_deinit +pw_deinit "$project" +trap "" EXIT + +$scripts/pw-report.sh --check triggered --result pass --pw_dir "$pw_dir" + +prev_head=$(git -C "$project" rev-parse HEAD) + +apply_series_with_retry "$project" "$prev_head" pw "$series_id" "$series_id" & +res=0 && wait $! || res=$? +patches_applied=$(git -C "$project" rev-list --count HEAD "^$prev_head") + +if [ "$patches_applied" -le "$num_patch" ]; then + apply_result="fail" + if [ "$res" = "0" ] && [ "$patches_applied" = "0" ]; then + # "series apply" finished successfully, but no patch was applied; + # this means that the patch is already merged. + apply_result="merged" + fi + + $scripts/pw-report.sh --check apply --result "$apply_result" \ + --pw_dir "$pw_dir" + + if [ $res != 0 ]; then + exit $res + fi + + echo "WARNING: patch series applied fewer patches than expected" + echo "WARNING: applied $patches_applied vs expected $(($num_patch + 1))" + echo "WARNING: most likely the patch series is now merged into mainline" + + exit 5 +fi + +git -C "$project" checkout --detach HEAD~$num_patch + +# Some debug traces, to check which files were modified and their time stamps +( + set +e + cd "$project" + git status + git status -s | awk '{print $NF;}' | while IFS='' read -r line + do + ls -l "$line" + done +) + +$scripts/pw-report.sh --check apply --result pass --pw_dir "$pw_dir" |