diff options
Diffstat (limited to 'tcwg-update-lnt-results.sh')
-rwxr-xr-x | tcwg-update-lnt-results.sh | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/tcwg-update-lnt-results.sh b/tcwg-update-lnt-results.sh new file mode 100755 index 00000000..4f7a83f1 --- /dev/null +++ b/tcwg-update-lnt-results.sh @@ -0,0 +1,139 @@ +#!/bin/bash + +set -euf -o pipefail + +scripts=$(dirname $0) + +# shellcheck source=jenkins-helpers.sh +. $scripts/jenkins-helpers.sh + +convert_args_to_variables "$@" +shift "$SHIFT_CONVERTED_ARGS" + +obligatory_variables lnt_config ci_project ci_config +declare lnt_config ci_project ci_config + +verbose="${verbose-false}" + +gitbaseurl="ssh://bkp.tcwglab/home/tcwg-buildslave/base-artifacts" +lntserver="${lntserver-/home/tcwg-buildslave/$lnt_config/lntserver}" +lntdb="$lntserver/lnt-database" +lntimport="$lntserver/import-tmp" + +docker_lnt=(docker exec "$lnt_config-lnt" sudo -i -u tcwg-buildslave lnt.sh) + +if $verbose; then set -x; fi + +# cleanup tmp result dir in any cases. +declare -g tmpdirs=() +trap 'rm -rf "${tmpdirs[@]}"' EXIT + +# Get ${lnt_projects[@]} +# shellcheck source=tcwg-lnt/tcwg-lnt-01/config +. $scripts/tcwg-lnt/$lnt_config/config + +update_one_lnt_results_project() +{ + local project=$1 + local config=$2 + + local lnt_model="${lnt_projects[$project]-}" + if [ "$lnt_model" = "" ]; then + echo "Skipping unknown project: $project" + return 0 + fi + + # Update base-artifacts with project/config + branch="linaro-local/ci/$project/$config" + + # push each one on LNT server + local -a lnt_reports=() + readarray -t lnt_reports < \ + <(get_git_history -0 "$gitbaseurl/$project/$config.git#$branch" \ + --relative \ + notify/lnt_report.json -- manifest.sh) + + # get_git_history always returns a first line with the created tmpdir, and each + # extracted files. lnt_reports[0] is the tmpdir created, and should be cleaned afterwards. + tmpdirs+=("${lnt_reports[0]}") + + if [ ${#lnt_reports[@]} -le 1 ]; then + echo "No lnt_report to push" + return 0 + fi + + # Check if history has inconsistent rr[major].rr[minor] versions -- aka + # whether we are in the middle of rewriting history. If "yes", then + # skip updating the dashboard to avoid inconsistent results. + local manifest + manifest="$(dirname "$(dirname "${lnt_reports[0]}/${lnt_reports[1]}")")/manifest.sh" + local rr_major1 rr_minor1 i=1 rr_major2 rr_minor2 + rr_major1=$(get_manifest "$manifest" "{rr[major]-0}") + rr_minor1=$(get_manifest "$manifest" "{rr[minor]-0}") + + while [ $i != ${#lnt_reports[@]} ]; do + json="${lnt_reports[0]}/${lnt_reports[$i]}" + manifest="$(dirname "$(dirname "${lnt_reports[0]}/${lnt_reports[$i]}")")/manifest.sh" + + rr_major2=$(get_manifest "$manifest" "{rr[major]-0}") + rr_minor2=$(get_manifest "$manifest" "{rr[minor]-0}") + if [ "$rr_major1" != "$rr_major2" ] \ + || [ "$rr_minor1" != "$rr_minor2" ]; then + echo "History re-write is in progress, not updating dashboard" + return 0 + fi + + jq -f $scripts/tcwg-lnt/$lnt_config/$lnt_model.jq $json > $json.tmp + mv $json.tmp $json + + # Update the path to what it will be after rsync below. + lnt_reports[$i]="$lntimport/${lnt_reports[$i]}" + i=$((i + 1)) + done + + # Move data into $lntimport/ directory, which is shared with + # the LNT container. + rsync -a --del "${lnt_reports[0]}/" "$lntimport/" + + echo "Deleting previous reports" + # "Machine" $config may not exist, so ignore failures. + "${docker_lnt[@]}" updatedb --testsuite "$project" "$lntdb" \ + --delete-machine "$config" || true + echo "Pushing ${lnt_reports[*]:1}" + # FIXME: ${lnt_reports[@]} can have hundreds of entries, which all + # will be expanded on the command line. Consider importing data in + # chunks or by specifying a top-level directory. + "${docker_lnt[@]}" import --testsuite "$project" "$lntdb" \ + "${lnt_reports[@]:1}" + echo "Done!" + + rm -rf "${lnt_reports[0]}" +} + +# Update the results either on $ci_project/$ci_config if defined +# Or iterate over all matching $ci_project/$ci_config +if [ x"$ci_project" != x"*" ] && [ x"$ci_config" != x"*" ]; then + + update_one_lnt_results_project $ci_project $ci_config + +else + + while read -r project_config; do + + project=${project_config%/*} + config=${project_config#*/} + + if [ x"$ci_project" != x"*" ] && [ x"$ci_project" != x"$project" ]; then + continue + fi + if [ x"$ci_config" != x"*" ] && [ x"$ci_config" != x"$config" ]; then + continue + fi + + update_one_lnt_results_project $project $config || true + + done < <(ssh bkp.tcwglab 'cd /home/tcwg-buildslave/base-artifacts/; find . -type d -name "*.git"' | sed -e 's/.git$//' | cut -d/ -f2-3) + +fi + +rm -rf "${tmpdirs[@]}" |