You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Function to check if the YAML file contains the specified Go version after 'GO_VERSION:'
4
+
check_go_version() {
5
+
local yamlfile="$1"
6
+
local required_go_version="$2"
7
+
8
+
# Use grep to find lines with 'GO_VERSION:'
9
+
local go_lines=$(grep -i 'GO_VERSION:'"$yamlfile"|| true)# Ignore grep exit status
10
+
11
+
# Check if any lines specify the Go version
12
+
if [ -n"$go_lines" ];then
13
+
# Extract the Go version from the file's lines. Example matching strings:
14
+
# GO_VERSION: "1.21.0"
15
+
# GO_VERSION: '1.21.0'
16
+
# GO_VERSION: 1.21.0
17
+
# GO_VERSION:1.21.0
18
+
# GO_VERSION:1.21.0
19
+
local extracted_go_version=$(echo "$go_lines"| sed -n 's/^[[:space:]]*GO_VERSION:[[:space:]]*\(['\''"]\?\)\?\([0-9]\+\.[0-9]\+\.[0-9]\+\)\(['\''"]\?\)\?/\2/p')
20
+
21
+
# Check if the extracted Go version matches the required version
22
+
if [ "$extracted_go_version"!="$required_go_version" ];then
23
+
echo"Error: $yamlfile specifies Go version '$extracted_go_version', but not version '$required_go_version'."
24
+
exit 1
25
+
else
26
+
echo"$yamlfile specifies Go version $required_go_version."
27
+
fi
28
+
fi
29
+
}
30
+
31
+
# Check if the target Go version argument is provided
32
+
if [ $#-eq 0 ];then
33
+
echo"Usage: $0 <target_go_version>"
34
+
exit 1
35
+
fi
36
+
37
+
target_go_version="$1"
38
+
39
+
# Search for YAML files in the current directory and its subdirectories
40
+
yaml_files=$(find . -type f -name "*.yaml" -o -name "*.yml")
41
+
42
+
# Check each YAML file
43
+
forfilein$yaml_files;do
44
+
check_go_version "$file""$target_go_version"
45
+
done
46
+
47
+
echo"All YAML files pass the Go version check for Go version $target_go_version."
0 commit comments