Philipp Schrader | 773577f | 2021-12-17 23:45:39 -0800 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Perform runfile initialization here so that child processes have a proper |
| 4 | # RUNFILES_DIR variable set. |
| 5 | |
| 6 | # --- begin runfiles.bash initialization v2 --- |
| 7 | # Copy-pasted from the Bazel Bash runfiles library v2. |
| 8 | set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash |
| 9 | source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \ |
| 10 | source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \ |
| 11 | source "$0.runfiles/$f" 2>/dev/null || \ |
| 12 | source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ |
| 13 | source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \ |
| 14 | { echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e |
| 15 | # --- end runfiles.bash initialization v2 --- |
| 16 | |
| 17 | gofmt() { |
| 18 | ./tools/lint/gofmt |
| 19 | } |
| 20 | |
| 21 | git_status_is_clean() { |
| 22 | cd "${BUILD_WORKSPACE_DIRECTORY}" |
| 23 | if ! git diff --quiet; then |
| 24 | echo "One or more linters appear to have made changes to your code!" >&2 |
| 25 | return 1 |
| 26 | fi |
| 27 | } |
| 28 | |
| 29 | # All the linters that we are going to run. |
| 30 | readonly -a LINTERS=( |
| 31 | gofmt |
| 32 | git_status_is_clean # This must the last linter. |
| 33 | ) |
| 34 | |
| 35 | failure=0 |
| 36 | for linter in "${LINTERS[@]}"; do |
| 37 | if ! (eval "${linter}"); then |
| 38 | failure=1 |
| 39 | fi |
| 40 | done |
| 41 | |
| 42 | if ((failure != 0)); then |
| 43 | echo "One or more linters failed." >&2 |
| 44 | cd "${BUILD_WORKSPACE_DIRECTORY}" |
| 45 | git --no-pager diff || : |
| 46 | exit "${failure}" |
| 47 | fi |
| 48 | |
| 49 | exit 0 |