forked from babarot/action-conftest
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentrypoint.sh
executable file
·84 lines (67 loc) · 1.51 KB
/
entrypoint.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
84
#!/bin/bash
# do not expand glob in this shell script
set -f
BASE="${INPUT_PATH:-.}"
POLICY="${INPUT_POLICY:-policy}"
FILES=( ${INPUT_FILES} )
MATCHES=( ${INPUT_MATCHES} )
NAMESPACE="${INPUT_NAMESPACE}"
ALL_NAMESPACES="${INPUT_ALL_NAMESPACES:-false}"
OUTPUT_FORMAT="${INPUT_OUTPUT_FORMAT}"
match() {
local arg=${1}
if [[ ${#MATCHES[@]} == 0 ]]; then
return 0
fi
local match
for match in ${MATCHES[@]}
do
if [[ ${arg} == ${match} ]]; then
return 0
fi
done
return 1
}
run_conftest() {
local file
local -a flags
local -a files
if [[ -n ${NAMESPACE} ]]; then
flags+=(--namespace ${NAMESPACE})
fi
if ${ALL_NAMESPACES}; then
flags+=(--all-namespaces)
fi
if [[ -n ${OUTPUT_FORMAT} ]]; then
flags+=(--output ${OUTPUT_FORMAT})
fi
for file in "${FILES[@]}"
do
if ! match ${file}; then
echo "[DEBUG] ${file}: against the matches condition, so skip it" >&2
continue
fi
files+=("$file")
done
if [[ ${#files[@]} == 0 ]]; then
echo "[DEBUG] no files to be passed to conftest"
return 0
fi
conftest test ${flags[@]} \
--no-color \
--policy "${POLICY}" \
"${files[@]}"
}
main() {
local -i status
run_conftest "$@" | tee -a result
status=${?}
result="$(cat result)"
# https://github.community/t5/GitHub-Actions/set-output-Truncates-Multiline-Strings/td-p/37870
echo "::set-output name=result::${result//$'\n'/'%0A'}"
echo "::set-output name=exit::${status}"
return ${status}
}
set -o pipefail
main "$@"
exit $?