-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-lint.sh
executable file
·83 lines (71 loc) · 2.31 KB
/
run-lint.sh
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
# Reset
GO_FEATURE_FLAG_CLI_DOCKER_TAG="v1"
Color_Off='\033[0m' # Text Reset
# Regular Colors
Black='\033[0;30m' # Black
Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
Yellow='\033[0;33m' # Yellow
Blue='\033[0;34m' # Blue
Purple='\033[0;35m' # Purple
Cyan='\033[0;36m' # Cyan
White='\033[0;37m' # White
function fmtPrintln() {
case "${1}" in
"debug")
printf "${Cyan}DEBUG:${Color_Off} ${2}\n"
;;
"info")
printf "${Green}INFO:${Color_Off} ${2}\n"
;;
"warning")
printf "${Yellow}WARNING:${Color_Off} ${2}\n"
;;
"error")
printf "${Purple}ERROR:${Color_Off} ${2}\n"
;;
"critical")
printf "${Red}CRITICAL:${Color_Off} ${2}\n"
;;
*)
printf "${White}UNKNOWN:${Color_Off} ${2}\n"
;;
esac
}
## Get the image of go-feature-flag-lint from source
fmtPrintln "info" "pulling the image of go-feature-flag-cli:${GO_FEATURE_FLAG_CLI_DOCKER_TAG} from source"
docker pull gofeatureflag/go-feature-flag-cli:${GO_FEATURE_FLAG_CLI_DOCKER_TAG}
## Input arguments
fmtPrintln "info" "input arguments: $1 and $2"
## Check if the file name or filetype is passed as argument
if [[ -z "$1" || -z "$2" ]]; then
fmtPrintln "critical" "filename or filetype is not passed as argument"
exit 1
fi
## Check if the file exists in the given location
if [[ ! -f "$1" ]]; then
fmtPrintln "critical" "file does not exist in the given location"
exit 1
fi
## Check if the filetype is yaml or json
if [[ "$2" != "yaml" && "$2" != "json" && "$2" != "toml" ]]; then
fmtPrintln "critical" "filetype is not yaml, json, or toml"
exit 1
fi
flagFile="$(pwd)/$1"
configDir=$(dirname "$flagFile")
configFile=$(basename "$flagFile")
echo $configFile
## Run the linter against the config file
msg=$( { docker run -v "${configDir}":/config --rm --name gofeatureflag_lint \
gofeatureflag/go-feature-flag-cli:${GO_FEATURE_FLAG_CLI_DOCKER_TAG} \
lint \
/config/"${configFile}" \
--format="$2"; } 2>&1)
## Check if the linter has any errors
if [[ $? != 0 ]]; then
fmtPrintln "critical" "linting failed"
fmtPrintln "critical" "$msg"
exit 1
fi
fmtPrintln "info" "linting passed"