-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidate_example.bash
More file actions
executable file
·57 lines (44 loc) · 2.13 KB
/
validate_example.bash
File metadata and controls
executable file
·57 lines (44 loc) · 2.13 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
#!/usr/bin/env bash
#
# Validate example directory
set -euo pipefail
SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
source "${SCRIPT_DIR}/common.bash"
cd "${REPO_ROOT_DIR}/examples"
# Collect incompatibility flags to raise early warnings for potential migration blockers.
# URL of the YAML file containing a mapping of Bazel incompatibility flags to affected Bazel versions.
INCOMPATIBILITY_FLAGS_URL="https://raw.githubusercontent.com/bazelbuild/bazel-central-registry/main/incompatible_flags.yml"
# Extract the Bazel version in use.
BAZEL_VERSION="$(bazel --version | cut -d' ' -f2)"
# Download the YAML content
INCOMPATIBILITY_FLAGS_YAML=$(curl "${INCOMPATIBILITY_FLAGS_URL}" 2>/dev/null)
# Normalize the YAML into a flat list containing flags and versions.
INCOMPATIBILITY_FLAGS_FLATTENED=$(echo "${INCOMPATIBILITY_FLAGS_YAML}" \
| perl -ne '
next if /^\s*#/; # Skip full-line comments
s/#.*$//; # Remove trailing comments
s/^\s*-\s+//; # Remove leading dash and spaces from list items (i.e. Bazel versions)
s/^\s*"\s*([^"]+)\s*"\s*:*$/$1/; # Extract key (i.e. incompatibility flag) from quoted key
print if /\S/; # Skip empty lines
'
)
# Initialize array to collect incompatibility flags supported for the current Bazel version.
incompatibility_flags=()
# Track the current flag while iterating over the flattened lines.
current_flag=""
# Read the lines one by one.
# If the line is a flag (starts with "--"), update `current_flag`.
# If the line matches the Bazel version, add the current_flag to the results.
while IFS= read -r line; do
if [[ "${line}" == --* ]]; then
current_flag="${line}"
elif [[ "${line}" == "${BAZEL_VERSION}" ]]; then
incompatibility_flags+=("${current_flag}")
fi
done <<< "${INCOMPATIBILITY_FLAGS_FLATTENED}"
if [[ "${#incompatibility_flags[@]}" -eq 0 ]]; then
bazel test //...
else
echo "INFO: Incompatibility flags enabled:" "${incompatibility_flags[@]}"
bazel test "${incompatibility_flags[@]}" //...
fi