aboutsummaryrefslogtreecommitdiffstats
path: root/time-of-build.sh
blob: 1446bd9299596307b4dc0eafe09e0f4524c7baad (plain) (blame)
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
#!/bin/sh
set -eu

if [ ! -r .osc/_project ] ; then
    echo 'This program must be run from an OBS project directory.'
    exit 42
fi

projname="$(basename $(pwd))"
package="$1"
tempfile="$(mktemp -t time-of-build-XXXXXX)"
trap 'rm -rf "$tempfile"' EXIT

process="$package"
if [ -r "$package/_multibuild" ] ; then
    for t in $(xmlstarlet sel -t -v '//package' $package/_multibuild) ; do
        process="$process $package:$t"
    done
fi

total_time=0
for pkg in $process ; do
    osc rbl $projname $pkg openSUSE_Tumbleweed x86_64 >$tempfile
    #  begtime="Tue Dec 13 23:50:13 UTC 2022"
    # \x22 is " character; https://unix.stackexchange.com/a/230354/184648
    begstr="$(sed -E -n -e '/started \x22build/s/^.*at (.*)\.$/\1/p' $tempfile)"
    endstr="$(sed -E -n -e '/(finished|failed) \x22build/s/^.*at (.*)\.$/\1/p' $tempfile)"
    begtime="$(date --date "$begstr" +%s)"
    endtime="$(date --date "$endstr" +%s)"
    ttime=$(( endtime - begtime ))
    total_time=$(( total_time + ttime ))
done

printf "%s\t%s\n" $total_time $package