]> git.lizzy.rs Git - rust.git/blob - src/ci/docker/x86_64-gnu-tools/checktools.sh
b0b88a6f3051614b842bee976eadaa9f25f8fbc7
[rust.git] / src / ci / docker / x86_64-gnu-tools / checktools.sh
1 #!/bin/sh
2
3 # Copyright 2017 The Rust Project Developers. See the COPYRIGHT
4 # file at the top-level directory of this distribution and at
5 # http://rust-lang.org/COPYRIGHT.
6 #
7 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10 # option. This file may not be copied, modified, or distributed
11 # except according to those terms.
12
13 set -eu
14
15 X_PY="$1"
16 TOOLSTATE_FILE="$(realpath $2)"
17 OS="$3"
18 COMMIT="$(git rev-parse HEAD)"
19 CHANGED_FILES="$(git diff --name-status HEAD HEAD^)"
20 SIX_WEEK_CYCLE="$(( ($(date +%s) / 604800 - 3) % 6 ))"
21 # ^ 1970 Jan 1st is a Thursday, and our release dates are also on Thursdays,
22 #   thus we could divide by 604800 (7 days in seconds) directly.
23
24 touch "$TOOLSTATE_FILE"
25
26 set +e
27 python2.7 "$X_PY" test --no-fail-fast \
28     src/doc/book \
29     src/doc/nomicon \
30     src/doc/reference \
31     src/doc/rust-by-example \
32     src/tools/rls \
33     src/tools/rustfmt \
34     src/tools/miri \
35     src/tools/clippy
36 set -e
37
38 cat "$TOOLSTATE_FILE"
39 echo
40
41 verify_status() {
42     echo "Verifying status of $1..."
43     if echo "$CHANGED_FILES" | grep -q "^M[[:blank:]]$2$"; then
44         echo "This PR updated '$2', verifying if status is 'test-pass'..."
45         if grep -vq '"'"$1"'":"test-pass"' "$TOOLSTATE_FILE"; then
46             echo
47             echo "⚠️ We detected that this PR updated '$1', but its tests failed."
48             echo
49             echo "If you do intend to update '$1', please check the error messages above and"
50             echo "commit another update."
51             echo
52             echo "If you do NOT intend to update '$1', please ensure you did not accidentally"
53             echo "change the submodule at '$2'. You may ask your reviewer for the"
54             echo "proper steps."
55             exit 3
56         fi
57     fi
58 }
59
60 check_dispatch() {
61     if [ "$1" = submodule_changed ]; then
62         # ignore $2 (branch id)
63         verify_status $3 $4
64     elif [ "$2" = beta ]; then
65         echo "Requiring test passing for $3..."
66         if grep -q '"'"$3"'":"\(test\|build\)-fail"' "$TOOLSTATE_FILE"; then
67             exit 4
68         fi
69     fi
70 }
71
72 status_check() {
73     check_dispatch $1 beta book src/doc/book
74     check_dispatch $1 beta nomicon src/doc/nomicon
75     check_dispatch $1 beta reference src/doc/reference
76     check_dispatch $1 beta rust-by-example src/doc/rust-by-example
77     check_dispatch $1 beta rls src/tool/rls
78     check_dispatch $1 beta rustfmt src/tool/rustfmt
79     # these tools are not required for beta to successfully branch
80     check_dispatch $1 nightly clippy-driver src/tool/clippy
81     check_dispatch $1 nightly miri src/tool/miri
82 }
83
84 # If this PR is intended to update one of these tools, do not let the build pass
85 # when they do not test-pass.
86
87 status_check "submodule_changed"
88
89 if [ "$RUST_RELEASE_CHANNEL" = nightly -a -n "${TOOLSTATE_REPO_ACCESS_TOKEN+is_set}" ]; then
90     . "$(dirname $0)/repo.sh"
91     MESSAGE_FILE=$(mktemp -t msg.XXXXXX)
92     echo "($OS CI update)" > "$MESSAGE_FILE"
93     commit_toolstate_change "$MESSAGE_FILE" \
94         sed -i "1 a\\
95 $COMMIT\t$(cat "$TOOLSTATE_FILE")
96 " "history/$OS.tsv"
97     # if we are at the last week in the 6-week release cycle, reject any kind of regression.
98     if [ $SIX_WEEK_CYCLE -eq 5 ]; then
99         python2.7 "$(dirname $0)/checkregression.py" \
100             "$OS" "$TOOLSTATE_FILE" "rust-toolstate/_data/latest.json"
101     fi
102     rm -f "$MESSAGE_FILE"
103     exit 0
104 fi
105
106 status_check "beta_required"