summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2022-08-15 12:52:15 +0000
committerMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2022-08-15 13:10:49 +0000
commit78640888268570ae0dc3637eb78a21a7f4f425de (patch)
treefd5a61c10b13327500f54ab04fe22748e19f8229
parentaa4558cc81904d8ce26a17a66df8a32494bdf0fb (diff)
round-robin.sh (check_regression): Move parts of code to new functions
... single_commit_p(), create_mail_dir(), and create_trigger_files(). Change-Id: I3a74ccbde0de079e16b521f991c139649b810361
-rw-r--r--round-robin.sh252
1 files changed, 141 insertions, 111 deletions
diff --git a/round-robin.sh b/round-robin.sh
index e90a3f55..cd68cb3a 100644
--- a/round-robin.sh
+++ b/round-robin.sh
@@ -706,45 +706,42 @@ EOF
)
}
-# Check if current build regressed compared to the baseline
-check_regression ()
+# Exit with 0 status if given components collectively have a single commit
+# compared to baseline.
+# $@: components
+single_commit_p ()
{
- (
- set -euf -o pipefail
-
- local score
- score=$(grep -v "^#" ${rr[top_artifacts]}/results | tail -n1)
-
- if [ x"$score" = x"-$EXTERNAL_FAIL" ]; then
- echo "ERROR: We have encountered some infrastructure problem (e.g.,"
- echo " benchmarking boards are offline), and we can't finish"
- echo " the build."
- # Exit now and don't update baseline artifacts.
- # By not creating trigger-build-* files, we signal
- # round-robin-bisect.sh to skip this build/revision.
- exit $EXTERNAL_FAIL
+ if [ $# = 1 ]; then
+ local c base_rev cur_rev sha1
+ c=$1
+ base_rev=$(get_baseline_git ${c}_rev)
+ cur_rev=$(get_current_git ${c}_rev)
+ for sha1 in $(git -C $c rev-parse $cur_rev^@); do
+ if [ x"$sha1" = x"$base_rev" ]; then
+ # We have a single-commit build
+ return 0
+ fi
+ done
fi
+ return 1
+}
- local res
-
- # Generate comparison artifacts for update, reset, init and push modes.
- ${rr[no_regression_p]} base-artifacts ${rr[top_artifacts]} &
- res=0 && wait $! || res=$?
-
- # Move extra artifacts that no_regression_p generated to $top_artifacts.
- if [ -d $run_step_artifacts/top-artifacts ]; then
- rsync -a $run_step_artifacts/top-artifacts/ ${rr[top_artifacts]}/
- rm -rf $run_step_artifacts/top-artifacts
- fi
+# Output mail and jira text for the build in ${rr[top_artifacts]}/mail.
+# $1: result of no_regression_p(), 0 for successful build.
+create_mail_dir ()
+{
+ (
+ set -euf -o pipefail
+ local res="$1"
+ shift
- # Generate default notification templates
if ! [ -f $run_step_artifacts/mail-subject.txt ]; then
if [ $res != 0 ]; then
- cat <<EOF
+ cat <<EOF
Regression after \$COMMIT_COMPONENT: \$COMMIT_SUBJECT
EOF
else
- cat <<EOF
+ cat <<EOF
Successful build after \$COMMIT_COMPONENT: \$COMMIT_SUBJECT
EOF
fi > $run_step_artifacts/mail-subject.txt
@@ -771,100 +768,63 @@ EOF
local -a changed_components
IFS=" " read -r -a changed_components <<< "$(print_changed_components)"
-
- local single_commit_p=false
- if [ ${#changed_components[@]} = 1 ]; then
- local c base_rev cur_rev sha1
- c=${changed_components[0]}
+ local new_commits=0 c base_rev cur_rev c_commits
+
+ if [ ${#changed_components} = 0 ]; then
+ COMMIT_COMPONENT="baseline build"
+ COMMIT_SUBJECT="no new commits"
+ COMMIT_LOG=""
+ elif single_commit_p "${changed_components[@]}"; then
+ c=$1
base_rev=$(get_baseline_git ${c}_rev)
cur_rev=$(get_current_git ${c}_rev)
- for sha1 in $(git -C $c rev-parse $cur_rev^@); do
- if [ x"$sha1" = x"$base_rev" ]; then
- # We have a single-commit build
- single_commit_p=true
- break
- fi
- done
- fi
-
- # Generate text for COMMIT_* variables._
- (
- local new_commits=0 c base_rev cur_rev c_commits
-
- if [ ${#changed_components[@]} = 0 ]; then
- COMMIT_COMPONENT="baseline build"
- COMMIT_SUBJECT="no new commits"
- COMMIT_LOG=""
- elif $single_commit_p; then
- c=${changed_components[0]}
+ COMMIT_COMPONENT=$c
+ COMMIT_SUBJECT=$(git -C $c log --pretty=%s -n1 $cur_rev)
+ COMMIT_LOG=$(git -C $c log --pretty=short -n1 $cur_rev)
+ else
+ COMMIT_COMPONENT=$(print_changed_components "/")
+ COMMIT_LOG=""
+ for c in "${changed_components[@]}"; do
base_rev=$(get_baseline_git ${c}_rev)
cur_rev=$(get_current_git ${c}_rev)
- COMMIT_COMPONENT=$c
- COMMIT_SUBJECT=$(git -C $c log --pretty=%s -n1 $cur_rev)
- COMMIT_LOG=$(git -C $c log --pretty=short -n1 $cur_rev)
- else
- COMMIT_COMPONENT=$(print_changed_components "/")
- COMMIT_LOG=""
- for c in "${changed_components[@]}"; do
- base_rev=$(get_baseline_git ${c}_rev)
- cur_rev=$(get_current_git ${c}_rev)
- c_commits=$(git -C $c rev-list --count $base_rev..$cur_rev)
- new_commits=$(($new_commits + $c_commits))
+ c_commits=$(git -C $c rev-list --count $base_rev..$cur_rev)
+ new_commits=$(($new_commits + $c_commits))
- COMMIT_LOG="$COMMIT_LOG
+ COMMIT_LOG="$COMMIT_LOG
$(git -C $c log --pretty=oneline $base_rev..$cur_rev | head -n5 || true)"
- if [ $c_commits -gt 5 ]; then
- COMMIT_LOG="$COMMIT_LOG
+ if [ $c_commits -gt 5 ]; then
+ COMMIT_LOG="$COMMIT_LOG
... and $(($c_commits - 5)) more $c commits"
- fi
- done
-
- COMMIT_SUBJECT="$new_commits commits"
- fi
-
- export COMMIT_COMPONENT COMMIT_SUBJECT COMMIT_LOG
-
- local mail_dir=${rr[top_artifacts]}/mail
- mkdir -p $mail_dir
-
- for i in mail-subject.txt jira-body.txt mail-body.txt; do
- envsubst '$COMMIT_COMPONENT $COMMIT_SUBJECT $COMMIT_LOG' \
- < $run_step_artifacts/$i > $mail_dir/$i
+ fi
done
- )
- if [ $res = 0 ]; then
- # All good, no regression
- return
- elif [ $res = $EXTERNAL_FAIL ]; then
- # Comparison failed to produce a meaningful result
- exit $EXTERNAL_FAIL
+ COMMIT_SUBJECT="$new_commits commits"
fi
- assert_with_msg "no_regression_p should succeed in init baseline mode" \
- [ x"${rr[update_baseline]}" != x"init" ]
+ export COMMIT_COMPONENT COMMIT_SUBJECT COMMIT_LOG
- if [ -f $run_step_artifacts/results.regressions ]; then
- # Add regression info generated by no_regression_p to top-level
- # results file.
- cat $run_step_artifacts/results.regressions \
- >> ${rr[top_artifacts]}/results
- fi
+ local mail_dir=${rr[top_artifacts]}/mail
+ mkdir -p $mail_dir
- # We've got a regression. Generate trigger-* files.
- local trigger_dest
+ for i in mail-subject.txt jira-body.txt mail-body.txt; do
+ envsubst '$COMMIT_COMPONENT $COMMIT_SUBJECT $COMMIT_LOG' \
+ < $run_step_artifacts/$i > $mail_dir/$i
+ done
+ )
+}
- if [ x"${rr[update_baseline]}" != x"force" ]; then
- # We are seeing a failure, so instead of updating baseline start
- # reducing/bisecting the failure. Create trigger-* files at top level
- # where jenkins expects them -- and trigger the followup builds.
- trigger_dest="${rr[top_artifacts]}"
- else
- # We don't want to trigger follow up builds when forcing
- # the baseline. So, for the record, place trigger-* files in
- # the step's artifacts directory.
- trigger_dest="$run_step_artifacts"
- fi
+# Generate trigger-build-* and trigger-bisect files to reduce the regression.
+# $1: Directory for trigger-* files.
+# $2: Score of the build.
+create_trigger_files ()
+{
+ (
+ set -euf -o pipefail
+ local trigger_dest="$1"
+ local score="$2"
+
+ local -a changed_components
+ IFS=" " read -r -a changed_components <<< "$(print_changed_components)"
if [ ${#changed_components[@]} -gt 1 ] \
|| { [ x"${rr[mode]}" = x"bisect" ] \
@@ -894,10 +854,11 @@ $(git -C $c log --pretty=oneline $base_rev..$cur_rev | head -n5 || true)"
done < <(${rr[breakup_changed_components]})
elif [ ${#changed_components[@]} = 1 ] \
&& ! [ $score -lt 0 ] 2>/dev/null; then
+ local single_component="${changed_components[0]}"
+
# Trigger bisect failures in a single changed component in all steps
# with a positive result. If $score is less-than 0, then
# the regression is not very interesting, so don't bisect.
- local single_component="${changed_components[0]}"
local url cur_rev
url=$(get_current_git ${single_component}_url)
cur_rev=$(get_current_git ${single_component}_rev)
@@ -910,6 +871,75 @@ EOF
cat $run_step_artifacts/extra-bisect-params >> $trigger_dest/trigger-bisect
fi
fi
+ )
+}
+
+# Check if current build regressed compared to the baseline
+check_regression ()
+{
+ (
+ set -euf -o pipefail
+
+ local score
+ score=$(grep -v "^#" ${rr[top_artifacts]}/results | tail -n1)
+
+ if [ x"$score" = x"-$EXTERNAL_FAIL" ]; then
+ echo "ERROR: We have encountered some infrastructure problem (e.g.,"
+ echo " benchmarking boards are offline), and we can't finish"
+ echo " the build."
+ # Exit now and don't update baseline artifacts.
+ # By not creating trigger-build-* files, we signal
+ # round-robin-bisect.sh to skip this build/revision.
+ exit $EXTERNAL_FAIL
+ fi
+
+ local res
+
+ # Generate comparison artifacts for update, reset, init and push modes.
+ ${rr[no_regression_p]} base-artifacts ${rr[top_artifacts]} &
+ res=0 && wait $! || res=$?
+
+ # Move extra artifacts that no_regression_p generated to $top_artifacts.
+ if [ -d $run_step_artifacts/top-artifacts ]; then
+ rsync -a $run_step_artifacts/top-artifacts/ ${rr[top_artifacts]}/
+ rm -rf $run_step_artifacts/top-artifacts
+ fi
+
+ if [ -f $run_step_artifacts/results.regressions ]; then
+ # Add regression info generated by no_regression_p to top-level
+ # results file.
+ cat $run_step_artifacts/results.regressions \
+ >> ${rr[top_artifacts]}/results
+ fi
+
+ create_mail_dir "$res"
+
+ if [ $res = 0 ]; then
+ # All good, no regression
+ return
+ elif [ $res = $EXTERNAL_FAIL ]; then
+ # Comparison failed to produce a meaningful result
+ exit $EXTERNAL_FAIL
+ fi
+
+ assert_with_msg "no_regression_p should succeed in init baseline mode" \
+ [ x"${rr[update_baseline]}" != x"init" ]
+
+ # We've got a regression. Generate trigger-* files.
+ local trigger_dest
+ if [ x"${rr[update_baseline]}" != x"force" ]; then
+ # We are seeing a failure, so instead of updating baseline start
+ # reducing/bisecting the failure. Create trigger-* files at top level
+ # where jenkins expects them -- and trigger the followup builds.
+ trigger_dest="${rr[top_artifacts]}"
+ else
+ # We don't want to trigger follow up builds when forcing
+ # the baseline. So, for the record, place trigger-* files in
+ # the step's artifacts directory.
+ trigger_dest="$run_step_artifacts"
+ fi
+
+ create_trigger_files "$trigger_dest" "$score"
if [ x"${rr[update_baseline]}" != x"force" ]; then
echo "Detected a regression!"