]> git.lizzy.rs Git - rust.git/blob - src/ci/docker/x86_64-gnu-tools/checktools.sh
3343716419ff459a473a69a4488f99251fcc7ab0
[rust.git] / src / ci / docker / x86_64-gnu-tools / checktools.sh
1 #!/bin/sh
2
3 set -eu
4
5 X_PY="$1"
6 TOOLSTATE_FILE="$(realpath $2)"
7 OS="$3"
8 COMMIT="$(git rev-parse HEAD)"
9 CHANGED_FILES="$(git diff --name-status HEAD HEAD^)"
10 SIX_WEEK_CYCLE="$(( ($(date +%s) / 86400 - 20) % 42 ))"
11 # ^ Number of days after the last promotion of beta.
12 #   Its value is 41 on the Tuesday where "Promote master to beta (T-2)" happens.
13 #   The Wednesday after this has value 0.
14 #   We track this value to prevent regressing tools in the last week of the 6-week cycle.
15
16 touch "$TOOLSTATE_FILE"
17
18 # Try to test all the tools and store the build/test success in the TOOLSTATE_FILE
19
20 set +e
21 python2.7 "$X_PY" test --no-fail-fast \
22     src/doc/book \
23     src/doc/nomicon \
24     src/doc/reference \
25     src/doc/rust-by-example \
26     src/doc/embedded-book \
27     src/tools/clippy \
28     src/tools/rls \
29     src/tools/rustfmt \
30     src/tools/miri \
31
32 set -e
33
34 cat "$TOOLSTATE_FILE"
35 echo
36
37 # This function checks that if a tool's submodule changed, the tool's state must improve
38 verify_status() {
39     echo "Verifying status of $1..."
40     if echo "$CHANGED_FILES" | grep -q "^M[[:blank:]]$2$"; then
41         echo "This PR updated '$2', verifying if status is 'test-pass'..."
42         if grep -vq '"'"$1"'":"test-pass"' "$TOOLSTATE_FILE"; then
43             echo
44             echo "⚠️ We detected that this PR updated '$1', but its tests failed."
45             echo
46             echo "If you do intend to update '$1', please check the error messages above and"
47             echo "commit another update."
48             echo
49             echo "If you do NOT intend to update '$1', please ensure you did not accidentally"
50             echo "change the submodule at '$2'. You may ask your reviewer for the"
51             echo "proper steps."
52             exit 3
53         fi
54     fi
55 }
56
57 # deduplicates the submodule check and the assertion that on beta some tools MUST be passing
58 check_dispatch() {
59     if [ "$1" = submodule_changed ]; then
60         # ignore $2 (branch id)
61         verify_status $3 $4
62     elif [ "$2" = beta ]; then
63         echo "Requiring test passing for $3..."
64         if grep -q '"'"$3"'":"\(test\|build\)-fail"' "$TOOLSTATE_FILE"; then
65             exit 4
66         fi
67     fi
68 }
69
70 # list all tools here
71 status_check() {
72     check_dispatch $1 beta book src/doc/book
73     check_dispatch $1 beta nomicon src/doc/nomicon
74     check_dispatch $1 beta reference src/doc/reference
75     check_dispatch $1 beta rust-by-example src/doc/rust-by-example
76     check_dispatch $1 beta rls src/tools/rls
77     check_dispatch $1 beta rustfmt src/tools/rustfmt
78     check_dispatch $1 beta clippy-driver src/tools/clippy
79     # these tools are not required for beta to successfully branch
80     check_dispatch $1 nightly miri src/tools/miri
81 }
82
83 # If this PR is intended to update one of these tools, do not let the build pass
84 # when they do not test-pass.
85
86 status_check "submodule_changed"
87
88 CHECK_NOT="$(readlink -f "$(dirname $0)/checkregression.py")"
89 change_toolstate() {
90     # only update the history
91     if python2.7 "$CHECK_NOT" "$OS" "$TOOLSTATE_FILE" "_data/latest.json" changed; then
92         echo 'Toolstate is not changed. Not updating.'
93     else
94         if [ $SIX_WEEK_CYCLE -ge 35 ]; then
95             python2.7 "$CHECK_NOT" "$OS" "$TOOLSTATE_FILE" "_data/latest.json" regressed
96         fi
97         sed -i "1 a\\
98 $COMMIT\t$(cat "$TOOLSTATE_FILE")
99 " "history/$OS.tsv"
100     fi
101 }
102
103 if [ "$RUST_RELEASE_CHANNEL" = nightly ]; then
104     if [ -n "${TOOLSTATE_REPO_ACCESS_TOKEN+is_set}" ]; then
105         . "$(dirname $0)/repo.sh"
106         MESSAGE_FILE=$(mktemp -t msg.XXXXXX)
107         echo "($OS CI update)" > "$MESSAGE_FILE"
108         commit_toolstate_change "$MESSAGE_FILE" change_toolstate
109         rm -f "$MESSAGE_FILE"
110     fi
111     exit 0
112 fi
113
114 # abort compilation if an important tool doesn't build
115 # (this code is reachable if not on the nightly channel)
116 status_check "beta_required"