]> git.lizzy.rs Git - rust.git/blob - src/ci/scripts/should-skip-this.sh
Merge commit '8f1ebdd18bdecc621f16baaf779898cc08cc2766' into clippyup
[rust.git] / src / ci / scripts / should-skip-this.sh
1 #!/bin/bash
2 # Set the SKIP_JOB environment variable if this job is supposed to only run
3 # when submodules are updated and they were not. The following time consuming
4 # tasks will be skipped when the environment variable is present.
5
6 set -euo pipefail
7 IFS=$'\n\t'
8
9 source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"
10
11 if [[ -n "${CI_ONLY_WHEN_SUBMODULES_CHANGED-}" ]]; then
12     git fetch "https://github.com/$GITHUB_REPOSITORY" "$GITHUB_BASE_REF"
13     BASE_COMMIT="$(git merge-base FETCH_HEAD HEAD)"
14
15     echo "Searching for toolstate changes between $BASE_COMMIT and $(git rev-parse HEAD)"
16
17     if git diff "$BASE_COMMIT" | grep --quiet "^index .* 160000"; then
18         # Submodules pseudo-files inside git have the 160000 permissions, so when
19         # those files are present in the diff a submodule was updated.
20         echo "Submodules were updated"
21     elif ! (git diff --quiet "$BASE_COMMIT" -- \
22              src/tools/clippy src/tools/rustfmt src/tools/miri); then
23         # There is not an easy blanket search for subtrees. For now, manually list
24         # the subtrees.
25         echo "Tool subtrees were updated"
26     elif ! (git diff --quiet "$BASE_COMMIT" -- \
27              src/test/rustdoc-gui \
28              src/librustdoc \
29              src/ci/docker/host-x86_64/x86_64-gnu-tools/Dockerfile \
30              src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version \
31              src/tools/rustdoc-gui); then
32         # There was a change in either rustdoc or in its GUI tests.
33         echo "Rustdoc was updated"
34     else
35         echo "Not executing this job since no submodules nor subtrees were updated"
36         ciCommandSetEnv SKIP_JOB 1
37         exit 0
38     fi
39 fi
40
41 if [[ -n "${CI_ONLY_WHEN_CHANNEL-}" ]]; then
42     if [[ "${CI_ONLY_WHEN_CHANNEL}" = "$(cat src/ci/channel)" ]]; then
43         echo "The channel is the expected one"
44     else
45         echo "Not executing this job as the channel is not the expected one"
46         ciCommandSetEnv SKIP_JOB 1
47         exit 0
48     fi
49 fi
50
51
52 echo "Executing the job since there is no skip rule preventing the execution"
53 exit 0