]> git.lizzy.rs Git - rust.git/blob - src/ci/scripts/should-skip-this.sh
BPF: review fixes
[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 [[ -z "${CI_ONLY_WHEN_SUBMODULES_CHANGED+x}" ]]; then
12     echo "Executing the job since there is no skip rule in effect"
13     exit 0
14 fi
15
16 git fetch "https://github.com/$GITHUB_REPOSITORY" "$GITHUB_BASE_REF"
17 BASE_COMMIT="$(git merge-base FETCH_HEAD HEAD)"
18
19 echo "Searching for toolstate changes between $BASE_COMMIT and $(git rev-parse HEAD)"
20
21 if git diff "$BASE_COMMIT" | grep --quiet "^index .* 160000"; then
22     # Submodules pseudo-files inside git have the 160000 permissions, so when
23     # those files are present in the diff a submodule was updated.
24     echo "Executing the job since submodules are updated"
25 elif ! git diff --quiet "$BASE_COMMIT" -- src/tools/clippy src/tools/rustfmt; then
26     # There is not an easy blanket search for subtrees. For now, manually list
27     # the subtrees.
28     echo "Executing the job since clippy or rustfmt subtree was updated"
29 else
30     echo "Not executing this job since no submodules nor subtrees were updated"
31     ciCommandSetEnv SKIP_JOB 1
32 fi