-
Notifications
You must be signed in to change notification settings - Fork 59
/
check.sh
executable file
·148 lines (121 loc) · 2.88 KB
/
check.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
printError () {
echo -n "- Checking ${CUR_FILE} ... "
icon="🔴"
if [ ${NO_ICON:-unset} != "unset" ]; then
icon="[ERROR]"
fi
echo ${icon}
if [ "${DEBUG:-unset}" != "unset" ]; then
echo "Command output:"
echo ""
echo "${1}" | awk '/^$/{next} {print $0}'
echo ""
fi
output "${CUR_FILE}" "${icon}" "$(echo "${1}" | awk '/^$/{next} {print $0}')"
continue
}
printWarning () {
echo -n "- Checking ${CUR_FILE} ... "
icon="🟡"
if [ ${NO_ICON:-unset} != "unset" ]; then
icon="[WARN]"
fi
echo ${icon}
if [ "${DEBUG:-unset}" != "unset" ]; then
echo "Job Warning output:"
echo ""
echo "${1}" | awk '/Job Warnings:/{flag=1} /Job Modify Index:/{flag=0} /^$/{next} flag'
echo ""
fi
output "${CUR_FILE}" "${icon}" "$(echo "${1}" | awk '/Job Warnings:/{flag=1} /Job Modify Index:/{flag=0} /^$/{next} flag')"
continue
}
printSuccess () {
if [ ${NO_SUCCESS:-unset} != "unset" ]; then
continue
fi
echo -n "- Checking ${CUR_FILE} ... "
icon="✅"
if [ ${NO_ICON:-unset} != "unset" ]; then
icon="[SUCCESS]"
fi
echo ${icon}
output "${CUR_FILE}" "${icon}" ""
continue
}
output() {
file="${1}"
status="${2}"
output="${3}"
asHTML "${file}" "${status}" "${output}"
}
setupOutput() {
startHTML
}
finishOutput() {
endHTML
}
startHTML() {
cat <<HERE > output.html
<html><head><title>Nomad Job Tester Output</title>
<style>
body {
font-family: Helvetica, sans-serif;
}
.out {
white-space: pre-wrap;
}
</style>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.12.1/css/jquery.dataTables.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.js"></script>
</head>
<body>
<table border="1" width="100%" id="results">
<thead><tr><th></th><th>Filename</th><th>Output</th></tr></thead>
<tbody>
HERE
}
asHTML() {
file="${1}"
status="${2}"
output="${3}"
maybeOut=""
if [ "${output}" != "" ]; then
maybeOut="<details><summary>Show Output</summary><pre class=out><code>${output}</code></pre></details>"
fi
echo "<tr><td style=\"width: 2em;\" align=\"center\">${status}</td><td width=\"25%\">${file}</td><td>${maybeOut}</td></tr>" >> output.html
}
endHTML() {
cat <<HERE >> output.html
</tbody>
</table>
<script>
\$(document).ready( function () {
\$('#results').DataTable({
paging: false
});
} );
</script>
HERE
}
## Main begins here
setupOutput
files=$(find -s ${1:-.} -name "*.nomad")
for file in ${files}; do
CUR_FILE=${file}
out=$(nomad plan ${CUR_FILE} 2>&1)
ec=$?
if [ "${ec}" == "255" ]; then
printError "${out}"
fi
if [ "${ec}" == "1" ]; then
dep=$(echo "${out}" | grep -c "Job Warnings:")
if [ "$dep" != 0 ]; then
printWarning "${out}"
fi
fi
printSuccess
done
finishOutput