forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathformat_pre.sh
More file actions
executable file
·97 lines (82 loc) · 3.01 KB
/
format_pre.sh
File metadata and controls
executable file
·97 lines (82 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env bash
set -E
# Pre-checks for validation and linting
#
# These checks do not provide a fix and are quicker to run,
# allowing CI to fail quickly on basic linting or validation errors
FAILED=()
CURRENT=""
# AZP appears to make lines with this prefix red
BASH_ERR_PREFIX="##[error]: "
DIFF_OUTPUT="${DIFF_OUTPUT:-/build/fix_format.diff}"
read -ra BAZEL_STARTUP_OPTIONS <<< "${BAZEL_STARTUP_OPTION_LIST:-}"
read -ra BAZEL_BUILD_OPTIONS <<< "${BAZEL_BUILD_OPTION_LIST:-}"
trap_errors () {
local frame=0 command line sub file
if [[ -n "$CURRENT" ]]; then
command=" (${CURRENT})"
fi
set +v
while read -r line sub file < <(caller "$frame"); do
if [[ "$frame" -ne "0" ]]; then
FAILED+=(" > ${sub}@ ${file} :${line}")
else
FAILED+=("${sub}@ ${file} :${line}${command}")
if [[ "$CURRENT" == "check" ]]; then
# shellcheck disable=SC2016
FAILED+=(
""
' *Code formatting check failed*: please search above logs for `CodeChecker ERROR`'
"")
fi
fi
((frame++))
done
set -v
}
trap trap_errors ERR
trap exit 1 INT
# TODO(phlax): Remove this once migration to bzlmod is complete
CURRENT=dep-names
check_legacy_dep_names () {
local legacy="$1"
local new="$2"
local matches
matches="$(git grep -l "$legacy" -- ':!*.patch' ':!*repositories.bzl' ':!ci/format_pre.sh' || :)"
if [[ -n "$matches" ]]; then
echo "ERROR: Found references to '$legacy' that should use '@${new}' instead:"
echo ""
git grep -l "$legacy" -- ':!*.patch' ':!*repositories.bzl' ':!ci/format_pre.sh'
echo ""
echo "Please replace '@${legacy}//' with '@${new}//' in the above files."
return 1
fi
}
check_legacy_dep_names com_google_absl abseil-cpp
check_legacy_dep_names com_github_cncf_xds xds
CURRENT=check
# This test runs code check with:
# bazel run //tools/code:check -- --fix -v warn -x mobile/dist/envoy-pom.xml
# see: /tools/code/BUILD
bazel "${BAZEL_STARTUP_OPTIONS[@]}" test "${BAZEL_BUILD_OPTIONS[@]}" //tools/code:check_test
CURRENT=spelling
bazel "${BAZEL_STARTUP_OPTIONS[@]}" run "${BAZEL_BUILD_OPTIONS[@]}" //tools/spelling:check_spelling_pedantic -- --mark check --target_root="$PWD"
CURRENT=check_format
bazel "${BAZEL_STARTUP_OPTIONS[@]}" run "${BAZEL_BUILD_OPTIONS[@]}" //tools/code_format:check_format -- fix --fail_on_diff
if [[ "${#FAILED[@]}" -ne "0" ]]; then
echo "${BASH_ERR_PREFIX}TESTS FAILED:" >&2
for failed in "${FAILED[@]}"; do
echo "${BASH_ERR_PREFIX} $failed" >&2
done
if [[ $(git status --porcelain) ]]; then
git diff > "$DIFF_OUTPUT"
echo >&2
echo "Applying the following diff should fix (some) problems" >&2
echo >&2
cat "$DIFF_OUTPUT" >&2
echo >&2
echo "Diff file with (some) fixes will be uploaded. Please check the artefacts for this PR run in the azure pipeline." >&2
echo >&2
fi
exit 1
fi