summaryrefslogtreecommitdiff
path: root/tcwg-update-lnt-results.sh
blob: 56119a764998d5453e921ac08654f04baaa14a50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/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"

. $lntserver/sandbox/bin/activate

if $verbose; then set -x; fi

# cleanup tmp result dir in any cases.
declare -g tmpdirs=()
trap 'rm -rf "${tmpdirs[@]}"' EXIT

update_one_lnt_results_project()
{
    local project=$1
    local config=$2

    # Early exit if unsupported
    case "$project" in
        tcwg_binutils*|tcwg_bootstrap*|tcwg_gcc*|tcwg_gdb*|tcwg_glibc*|tcwg_gnu*)
	    lnt_model="tcwg_check"
            ;;
        tcwg_bmk*)
	    lnt_model="tcwg_bmk"
            ;;
        *)
            # Do not update anything else so far
            return
            ;;
    esac

    # Update base-artifacts with project/config
    branch="linaro-local/ci/$project/$config"

    # push each one on LNT server
    readarray -t lnt_reports < \
	      <(get_git_history -0 "$gitbaseurl/$project/$config.git#$branch" \
				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[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[$i]}"
	manifest="$(dirname "$(dirname "${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

	i=$((i + 1))
    done

    echo "Deleting previous reports"
    lnt updatedb --testsuite "$project" "$lntdb" --delete-machine "$config"
    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.
    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[@]}"