Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/build-master-status
blob: 4d7fd3e5cb484343002cdf1991b849d4142b9551 (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/bin/sh

# report about status of build master

. "${0%/*}/../conf/default.conf"

usage() {
  >&2 echo ''
  >&2 echo 'build-master-status: report about status of build master'
  >&2 echo ''
  >&2 echo 'possible options:'
  >&2 echo '  -b|--broken $output:'
  >&2 echo '    Write broken packages to $output.'
  >&2 echo '  -h|--help:'
  >&2 echo '    Show this help and exit.'
  >&2 echo '  -n|--nice:'
  >&2 echo '    Write html output.'
  >&2 echo '  -o|--output $output:'
  >&2 echo '    Write to $output instead of stdout.'
  >&2 echo '  -s|--statistics $output:'
  >&2 echo '    Write statistics to $output.'
  [ -z "$1" ] && exit 1 || exit $1
}

eval set -- "$(
  getopt -o b:hno:s: \
    --long broken: \
    --long help \
    --long nice \
    --long output: \
    --long statistics: \
    -n "$(basename "$0")" -- "$@" || \
  echo usage
)"

output() {
  cat
}

make_nice() {
  cat
}

nice=false
broken_output=''
output_file=''
statistics_output=''

while true
do
  case "$1" in
    -b|--broken)
      shift
      broken_output="$1"
    ;;
    -h|--help)
      usage 0
    ;;
    -n|--nice)
      nice=true
      make_nice() {
        sed 's|$|<br>|'
      }
    ;;
    -o|--output)
      shift
      output_file="$1"
      output() {
        cat >> "${output_file}"
      }
    ;;
    -s|--statistics)
      shift
      statistics_output="$1"
    ;;
    --)
      shift
      break
    ;;
    *)
      >&2 echo 'Whoops, forgot to implement option "'"$1"'" internally.'
      exit 42
    ;;
  esac
  shift
done

if [ $# -ne 0 ]; then
  >&2 echo 'Too many arguments.'
  usage
fi

stable="$(
  ls_master_mirror 'i686' | \
    grep -v 'testing$\|staging$\|-unstable$' | \
    while read -r dir; do
      ls_master_mirror "i686/${dir}"
    done | \
    grep -c '\.pkg\.tar\.xz$'
  )"
tasks="$(
  grep -c '^\S\+ \S\+ \S\+ \S\+$' \
    "${work_dir}/build-list"
  )" || true
pending_packages="$(
  grep '^\S\+ \S\+ \S\+ \S\+$' "${work_dir}/build-list" | \
    tr ' ' '.' | \
    while read -r package; do
      generate_package_metadata "${package}" 2>&1 > /dev/null
      cat "${work_dir}/package-infos/${package}.packages"
    done |
    wc -l
)"
staging="$(
  ls_master_mirror 'i686' | \
    grep 'staging$' | \
    while read -r dir; do
      ls_master_mirror "i686/${dir}"
    done | \
    grep -c '\.pkg\.tar\.xz$'
  )"
testing="$(
  ls_master_mirror 'i686' | \
    grep 'testing$' | \
    while read -r dir; do
      ls_master_mirror "i686/${dir}"
    done | \
    grep -c '\.pkg\.tar\.xz$'
  )"
broken="$(
  ls "${work_dir}/package-states/" | \
    grep -c '\.broken$'
  )" || true
blocked="$(
  ls "${work_dir}/package-states/" | \
    grep -c '\.blocked$'
  )" || true
locked="$(
  ls "${work_dir}/package-states/" | \
    grep -c '\.locked$'
  )" || true
loops="$(
  ls "${work_dir}/build-list.loops" | \
    grep -c '^loop_[0-9]\+$'
  )" || true
looped_packages="$(
  ls "${work_dir}/build-list.loops" | \
    grep '^loop_[0-9]\+$' | \
    sed "s|^|${work_dir}/build-list.loops/|" | \
    xargs -r cat | \
    sort -u | \
    wc -l
  )"

if [ -n "${output_file}" ]; then
  : > "${output_file}"
fi

printf 'The mirror master contains %d stable packages (vs. ca. %d planned).\n' \
  "${stable}" \
  "$((${staging}+${testing}+${pending_packages}))" | \
  make_nice | \
  output
printf 'The build list contains %d tasks (incl. broken: %d, leading to %d packages).\n' \
  "$((${tasks}-${broken}))" \
  "${tasks}" \
  "${pending_packages}" | \
  make_nice | \
  output
printf 'There are %d testing and %d staging packages.\n' \
  "${testing}" \
  "${staging}" | \
  output
printf 'There are %d broken package builds.\n' \
  "${broken}" | \
  make_nice | \
  output
if [ "${loops}" -ne 0 ]; then
  printf 'There are %d loops containing %d package builds.\n' \
    "${loops}" \
    "${looped_packages}" | \
    make_nice | \
    output
fi
if [ $((${broken}+${testing}+${staging})) -ne 0 ]; then
  printf '%.1f%% of all packages are broken.\n' \
    "$(
      echo "scale=10; 100*${broken}/(${broken}+${testing}+${staging})" | \
        bc
    )" | \
    make_nice | \
    output
fi
if [ $((${testing}+${staging}+${pending_packages}-${broken})) -ne 0 ]; then
  printf '%.1f%% of the planned work has been done.\n' \
    "$(
      echo "scale=10; 100*(${testing}+${staging})/(${testing}+${staging}+${pending_packages}-${broken})" | \
        bc
    )" | \
    make_nice | \
    output
fi

if [ -n "${statistics_output}" ]; then
  (
    [ -f "${statistics_output}" ] && \
      cat "${statistics_output}"
    printf '%s ' \
      "$(date +%s)" \
      "${stable}" \
      "${tasks}" \
      "${pending_packages}" \
      "${staging}" \
      "${testing}" \
      "${broken}" \
      "${loops}" \
      "${looped_packages}" \
      "${locked}" \
      "${blocked}" | \
      sed 's| $|\n|'
  ) | \
  tail -n 10080 | \
  sponge "${statistics_output}"
fi

if [ -n "${broken_output}" ]; then
  (
    if ${nice}; then
      printf '<html>\n<body>\n<a href="build-logs/">build logs</a><br>\n<table>\n<tr>'
      printf '<th>%s</th>' \
        'package' \
        'git revision' \
        'modification git revision' \
        'package repository' \
        'compilations' \
        'blocked'
      printf '</tr>\n'
    fi
    ls "${work_dir}/package-states" | \
      grep '\.broken$' | \
      sed 's|\.broken$||' | \
      if ${nice}; then
        sed 's|^\(\(.\+\)\.\([^.]\+\)\.\([^.]\+\)\.\([^.]\+\)\)$|\1 \2 \3 \4 \5|' | \
          while read -r sf pkg rev mod_rev repo; do
            printf '%s ' \
              "${pkg}" \
              "${rev}" \
              "${mod_rev}" \
              "${repo}" \
              "$(wc -l < "${work_dir}/package-states/${sf}.broken")"
            if [ -f "${work_dir}/package-states/${sf}.blocked" ]; then
              tr '\n' ' ' < "${work_dir}/package-states/${sf}.blocked" | \
                sed 's|FS#\([0-9]\+\)|<a href="https://bugs.archlinux.org/task/\1">FS#\1</a>|'
            else
              printf '&nbsp;'
            fi
            printf '\n'
          done | \
          sort -k5n,5 | \
          while read -r pkg rev mod_rev repo count reason; do
            printf '<tr>'
            printf '<td>%s</td>' \
              '<a href="graphs/'"${pkg}"'.png">'"${pkg}"'</a>' \
              "${rev}" \
              "${mod_rev}" \
              "${repo}" \
              "${count}" \
              "${reason}"
            printf '</tr>\n'
          done
      else
        cat
      fi
    if ${nice}; then
      printf '</table>\n</body>\n</html>\n'
    fi
  ) | \
    sponge "${broken_output}"
fi