Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/bin/nit-picker
blob: 50524e96173e26a45683404f2d2ac9b3f3a94b3d (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
#!/bin/sh

# shellcheck disable=SC2119

# shellcheck source=../lib/load-configuration
. "${0%/*}/../lib/load-configuration"

# this script shall host all the tests that are too slow to be run on
# the buildmaster (thus, it runs asynchronously and must therefor be
# resilient against transient states of the buildmaster):
# - check sanity of git
# TODO:
# - check for differences of dependencies between mysql and git
# - check for differences of dependencies between mysql and packages
# - check for installability of packages

if [ $# -eq 1 ] && [ "x$1" = 'x-n' ]; then
  >&2 echo 'not joining irc'
  irc=false
  shift
else
  irc=true
fi

if [ $# -ne 0 ]; then
  >&2 echo 'usage: nit-picker [-n]'
  >&2 echo '  -n: do not join irc'
  exit 1
fi

clean_up() {
  rm -rf --one-file-system "${tmp_dir}"
}

tmp_dir=$(mktemp -d 'tmp.nit-picker.XXXXXXXXXX' --tmpdir)
trap 'clean_up' EXIT

if ${irc}; then
  if pgrep -x ii; then
    >&2 echo 'ii is already running - this will not work'
    exit 1
  fi

  rm -rf --one-file-system "${irc_dir}"

  ii -s irc.freenode.net -n nit-picker -f nit-picker >/dev/null 2>&1 &
  ii_pid=$!

  clean_up() {
    rm -rf --one-file-system "${tmp_dir}"
    kill "${ii_pid}"
  }

  # wait for nickserv complaint
  while ! grep -qF 'This nickname is registered. Please choose a different nickname' "${irc_dir}/nickserv/out"; do
    sleep 1
  done

  # register
  printf 'identify %s\n' "${irc_password}" | \
    sponge "${irc_dir}/nickserv/in"

  # wait for registering to succeed
  while ! grep -qF 'You are now identified for' "${irc_dir}/nickserv/out"; do
    sleep 1
  done

  # join channel
  echo '/j #archlinux32' | \
    sponge "${irc_dir}/in"

  while [ ! -f "${irc_dir}/#archlinux32/out" ]; do
    sleep 1
  done
else
  irc_say() {
    sed 's/^/irc: /'
  }
fi

mysql_load_min_and_max_versions

while pgrep -x ii >/dev/null \
|| ! ${irc}; do
  # shellcheck disable=SC2016
  {
    printf 'SELECT DISTINCT'
    printf ' "commit",'
    printf '`git_repositories`.`name`,'
    printf '`package_sources`.`git_revision`'
    printf ' FROM `package_sources`'
    mysql_join_package_sources_upstream_repositories
    mysql_join_upstream_repositories_git_repositories
    printf ';\n'

    printf 'SELECT DISTINCT'
    printf ' "commit",'
    printf '"archlinux32",'
    printf '`package_sources`.`mod_git_revision`'
    printf ' FROM `package_sources`'
    printf ';\n'

    printf 'SELECT DISTINCT'
    printf ' "binary-dependencies",'
    mysql_package_name_query
    printf ' FROM `binary_packages`'
    mysql_join_binary_packages_architectures
    mysql_join_binary_packages_binary_packages_in_repositories
    mysql_join_binary_packages_in_repositories_repositories
    printf ' WHERE `repositories`.`is_on_master_mirror`'
    printf ';\n'
  } | \
    mysql_run_query | \
    tr '\t' ' ' | \
    shuf | \
    while read -r action parameters; do
      if ! pgrep -x ii >/dev/null; then
        break
      fi
      case "${action}" in
        'commit') # check whether a given commit is present in the git repo
          git_repo="${parameters%% *}"
          git_rev="${parameters#${git_repo} }"
          eval "$(
            printf 'git_dir="${repo_paths__%s}"\n' \
              "${git_repo}"
          )"
          # shellcheck disable=SC2154
          if ! git -C "${git_dir}" cat-file -t "${git_rev}" 2> /dev/null | \
            grep -qxF 'commit'; then
            git -C "${git_dir}" fetch --all -p >/dev/null 2>&1
            if ! git -C "${git_dir}" cat-file -t "${git_rev}" 2> /dev/null | \
              grep -qxF 'commit'; then
              printf 'commit %s is missing from repository %s\n' \
                "${git_rev}" \
                "${git_repo}" \
              | irc_say
            fi
          fi
        ;;
        'binary-dependencies')
          ${master_mirror_rsync_command} \
            "${master_mirror_rsync_directory}/pool/${parameters}" \
            "${tmp_dir}/"
          bsdtar -Oxf "${tmp_dir}/${parameters}" '.PKGINFO' \
          | sed -n '
            s/^\(\(make\)\?depend\) = /\1 /
            T
            p
          ' \
          | sed '
            s/\(=\|[<>]=\?\)\(\S\+\)$/ \1 \2/
            t
            s/$/ >= '"${min_version}"'/
          ' \
          | sed '
            s/:\(\S\+\)$/ \1/
            t
            s/ \(\S\+\)$/ 0 \1/
          ' \
          | sort -u \
          > "${tmp_dir}/pkg-deps"
          {
            printf 'SELECT'
            printf ' IF(`dependency_types`.`name`="run","depend","makedepend"),'
            printf '`install_targets`.`name`,'
            printf '`dependencies`.`version_relation`,'
            printf '`versions`.`epoch`,'
            printf '`versions`.`version`'
            printf ' FROM `binary_packages`'
            mysql_join_binary_packages_dependencies
            mysql_join_binary_packages_architectures
            mysql_join_dependencies_dependency_types
            mysql_join_dependencies_versions
            mysql_join_dependencies_install_targets
            printf ' WHERE '
            mysql_package_name_query
            printf '="%s"' \
              "${parameters}"
            printf ' AND `dependency_types`.`name` IN ("run","make")'
            printf ';\n'
          } \
          | mysql_run_query \
          | tr '\t' ' ' \
          | sed '
            /^depend base >= '"${min_version%:*}"' '"${min_version#*:}"'$/d
            /^makedepend base-devel >= '"${min_version%:*}"' '"${min_version#*:}"'$/d
          ' \
          | sort -u \
          > "${tmp_dir}/db-deps"
          if ! diff -q "${tmp_dir}/db-deps" "${tmp_dir}/pkg-deps"; then
            printf '/j %s dependencies of %s differ between the package and our database\n' \
              'deep42thought' \
              "${parameters}" \
            | sponge "${irc_dir}/in"
            if ! ${irc}; then
              diff -u --color "${tmp_dir}/db-deps" "${tmp_dir}/pkg-deps" || true
            fi
            sleep 60
          fi
          rm \
            "${tmp_dir}/${parameters}" \
            "${tmp_dir}/db-deps" \
            "${tmp_dir}/pkg-deps"
        ;;
        *)
          >&2 printf 'action "%s" is not yet implemented ...\n' "${action}"
        ;;
      esac
    done
  sleep 120
done