]> git.lizzy.rs Git - rust.git/blob - src/ci/docker/x86_64-gnu-tools/checktools.sh
checktools: unify grepping the TOOLSTATE file
[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/doc/edition-guide \
28     src/tools/clippy \
29     src/tools/rls \
30     src/tools/rustfmt \
31     src/tools/miri \
32
33 set -e
34
35 cat "$TOOLSTATE_FILE"
36 echo
37
38 # This function checks if a particular tool is *not* in status "test-pass".
39 check_tool_failed() {
40     grep -vq '"'"$1"'":"test-pass"' "$TOOLSTATE_FILE"
41 }
42
43 # This function checks that if a tool's submodule changed, the tool's state must improve
44 verify_status() {
45     echo "Verifying status of $1..."
46     if echo "$CHANGED_FILES" | grep -q "^M[[:blank:]]$2$"; then
47         echo "This PR updated '$2', verifying if status is 'test-pass'..."
48         if check_tool_failed "$1"; then
49             echo
50             echo "⚠️ We detected that this PR updated '$1', but its tests failed."
51             echo
52             echo "If you do intend to update '$1', please check the error messages above and"
53             echo "commit another update."
54             echo
55             echo "If you do NOT intend to update '$1', please ensure you did not accidentally"
56             echo "change the submodule at '$2'. You may ask your reviewer for the"
57             echo "proper steps."
58             exit 3
59         fi
60     fi
61 }
62
63 # deduplicates the submodule check and the assertion that on beta some tools MUST be passing.
64 # $1 should be "submodule_changed" to only check tools that got changed by this PR,
65 # or "beta_required" to check all tools that have $2 set to "beta".
66 check_dispatch() {
67     if [ "$1" = submodule_changed ]; then
68         # ignore $2 (branch id)
69         verify_status $3 $4
70     elif [ "$2" = beta ]; then
71         echo "Requiring test passing for $3..."
72         if check_tool_failed "$3"; then
73             exit 4
74         fi
75     fi
76 }
77
78 # list all tools here
79 status_check() {
80     check_dispatch $1 beta book src/doc/book
81     check_dispatch $1 beta nomicon src/doc/nomicon
82     check_dispatch $1 beta reference src/doc/reference
83     check_dispatch $1 beta rust-by-example src/doc/rust-by-example
84     check_dispatch $1 beta edition-guide src/doc/edition-guide
85     check_dispatch $1 beta rls src/tools/rls
86     check_dispatch $1 beta rustfmt src/tools/rustfmt
87     check_dispatch $1 beta clippy-driver src/tools/clippy
88     # these tools are not required for beta to successfully branch
89     check_dispatch $1 nightly miri src/tools/miri
90     check_dispatch $1 nightly embedded-book src/doc/embedded-book
91 }
92
93 # If this PR is intended to update one of these tools, do not let the build pass
94 # when they do not test-pass.
95
96 status_check "submodule_changed"
97
98 CHECK_NOT="$(readlink -f "$(dirname $0)/checkregression.py")"
99 change_toolstate() {
100     # only update the history
101     if python2.7 "$CHECK_NOT" "$OS" "$TOOLSTATE_FILE" "_data/latest.json" changed; then
102         echo 'Toolstate is not changed. Not updating.'
103     else
104         if [ $SIX_WEEK_CYCLE -ge 35 ]; then
105             python2.7 "$CHECK_NOT" "$OS" "$TOOLSTATE_FILE" "_data/latest.json" regressed
106         fi
107         sed -i "1 a\\
108 $COMMIT\t$(cat "$TOOLSTATE_FILE")
109 " "history/$OS.tsv"
110     fi
111 }
112
113 if [ "$RUST_RELEASE_CHANNEL" = nightly ]; then
114     if [ -n "${TOOLSTATE_REPO_ACCESS_TOKEN+is_set}" ]; then
115         . "$(dirname $0)/repo.sh"
116         MESSAGE_FILE=$(mktemp -t msg.XXXXXX)
117         echo "($OS CI update)" > "$MESSAGE_FILE"
118         commit_toolstate_change "$MESSAGE_FILE" change_toolstate
119         rm -f "$MESSAGE_FILE"
120     fi
121     exit 0
122 fi
123
124 # abort compilation if an important tool doesn't build
125 # (this code is reachable if not on the nightly channel)
126 status_check "beta_required"