aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/run-patchmetrics
blob: fc2e23b3a177070c5a342c8f4ef8675655ae83c5 (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
#!/bin/bash
#
# SPDX-License-Identifier: GPL-2.0-only
#

set -eu

ARGS=$(getopt -o '' --long 'poky:,metrics:,repo:,layer:,branch:,results:,push' -n 'run-patchmetrics' -- "$@")
if [ $? -ne 0 ]; then
    echo 'Cannot parse arguments...' >&2
    exit 1
fi
eval set -- "$ARGS"
unset ARGS

# Location of the yocto-autobuilder-helper scripts
OURDIR=$(dirname $0)
# Where Poky is (for patchreview.py)
POKYDIR=""
# The metrics repository to use
METRICSDIR=""
# Where to copy results to
RESULTSDIR=""
# The branch we're building
BRANCH=""
# The layer/repository to scan
LAYERDIR=""
# Whether to push the metrics
PUSH=0

while true; do
    case "$1" in
        '--poky')
            POKYDIR=$(realpath $2)
            shift 2
            continue
        ;;
        '--metrics')
            METRICSDIR=$(realpath $2)
            shift 2
            continue
        ;;
        '--layer')
            LAYERDIR=$(realpath $2)
            shift 2
            continue
        ;;
        '--repo')
            REPODIR=$(realpath $2)
            shift 2
            continue
        ;;
        '--branch')
            BRANCH=$2
            shift 2
            continue
        ;;
        '--results')
            RESULTSDIR=$(realpath -m $2)
            shift 2
            continue
        ;;
        '--push')
            PUSH=1
            shift
            continue
        ;;
        '--')
            shift
            break
        ;;
        *)
            echo "Unexpected value $1" >&2
            exit 1
        ;;
    esac
done

if ! test "$POKYDIR" -a "$METRICSDIR" -a "$REPODIR" -a "$LAYERDIR" -a "$BRANCH" -a "$RESULTSDIR"; then
    echo "Not all required options specified"
    exit 1
fi

# We only monitor patch metrics on the master branch
if [ "$BRANCH" != "master" ]; then
    echo "Skipping, $BRANCH is not master"
    exit 0
fi

# Do another pull to make sure we're as up to date as possible.  This is
# preferable to committing and rebasing before pushing as it would be better to
# waste some time repeating work than commit potentially corrupted files from a
# git merge gone wrong.
git -C $METRICSDIR pull

#
# Patch Metrics
#

set -x
$OURDIR/patchmetrics-update --patchscript $POKYDIR/scripts/contrib/patchreview.py --json $METRICSDIR/patch-status.json --repo $REPODIR --layer $LAYERDIR
set +x

# Allow the commit to fail if there is nothing to commit
git -C $METRICSDIR commit -asm "Autobuilder adding new patch stats" || true

if [ "$PUSH" = "1" ]; then
    git -C $METRICSDIR push
fi

#
# Update the results
#

if [ ! -d $RESULTSDIR ]; then
    mkdir $RESULTSDIR
fi

$OURDIR/patchmetrics-generate-chartdata --json $METRICSDIR/patch-status.json --outputdir $RESULTSDIR
cp $METRICSDIR/patch-status.json $RESULTSDIR
cp -r $METRICSDIR/patch-status/* $RESULTSDIR