blob: a1bc07c375fe36f87f1c3c59d57bde6f78ca917a [file] [log] [blame]
Philipp Schrader773577f2021-12-17 23:45:39 -08001#!/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.
8set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
9source "${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
17gofmt() {
18 ./tools/lint/gofmt
19}
20
21git_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.
30readonly -a LINTERS=(
31 gofmt
32 git_status_is_clean # This must the last linter.
33)
34
35failure=0
36for linter in "${LINTERS[@]}"; do
37 if ! (eval "${linter}"); then
38 failure=1
39 fi
40done
41
42if ((failure != 0)); then
43 echo "One or more linters failed." >&2
44 cd "${BUILD_WORKSPACE_DIRECTORY}"
45 git --no-pager diff || :
46 exit "${failure}"
47fi
48
49exit 0