-
Notifications
You must be signed in to change notification settings - Fork 22
/
qa-test
executable file
·79 lines (72 loc) · 2.26 KB
/
qa-test
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
#!/bin/bash
set -ex
export QA_TEST=1
test_shell()
{
mkdir -p .shellcheck
find . -path ./.git -prune -o -path "*.py" -prune -o -type f -exec grep -Eq '^#!(.*/|.*env +)(sh|bash|ksh)' {} \; -print |
while IFS="" read -r file
do
# collect all warnings
shellcheck --format=checkstyle "$file" > .shellcheck/$(basename ${file}).log || true
# fail on >=error
shellcheck --severity error "$file"
done
}
# fails on error and ignores other levels
test_shell_error()
{
# Shellcheck
find . -path ./.git -prune -o -path "*.py" -prune -o -type f -exec grep -Eq '^#!(.*/|.*env +)(sh|bash|ksh)' {} \; -print |
while IFS="" read -r file
do
# with recent shellcheck, "-S error" replaces this hack
# kept as this runs on machines running rudder-dev
shellcheck --format gcc "$file" | grep " error: " && exit 1 || true
done
}
# verify that each file has a correct license header
test_license_header()
{
find . -name '*.cf' -o -name '*.st' -print0 |
while IFS= read -r -d '' file; do
if ! grep -qE "# SPDX-FileCopyrightText.*" $file; then
# Ignore very small files
if [ `wc -l $file | awk '{print $1}'` -gt "10" ]; then
echo "$file is missing a correct license header"
exit 1
fi
fi
done
}
test_windows_techniques()
{
if [ ! -f rudder-templates-cli.jar ]; then
wget https://repository.rudder.io/build-dependencies/rudder-templates-cli/rudder-templates-cli.jar
fi
for technique in $(find techniques -type d -regex ".*[0-9]+.[0-9]+")
do
tmp_dir=$(mktemp -d -t qa-test-XXXXXXXXXX)
cp -r $technique/* $tmp_dir
for file in $(find $technique -name "*.ps1.st")
do
baseFile=$(basename $file .ps1.st)
renderedFile=$tmp_dir/$baseFile.ps1
java -Dfile.encoding=UTF-8 -jar rudder-templates-cli.jar --outdir $tmp_dir -p variables.json $file
done
pwsh -command "Invoke-ScriptAnalyzer -Path ${tmp_dir} -Settings ./PSScriptAnalyzerSettingsPolicy.psd1 -EnableExit -ReportSummary"
rm -rf $tmp_dir
done
}
if [ "$1" = "--shell" ]; then
test_shell
exit 0
elif [ "$1" = "--license" ]; then
test_license_header
elif [ "$1" = "--dsc" ]; then
test_windows_techniques
else
# quick tests to be launched during merge
test_shell_error
make test
fi