-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathentrypoint.sh
executable file
·90 lines (73 loc) · 2.16 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
85
86
87
88
89
90
#!/bin/sh -l
macrofy_allow_lowercase () {
echo -n "$1" |
tr -c '[0-9A-Za-z_]' _ |
sed -e 's/^_*\(.*\)$/\1/'
}
macrofy () {
macrofy_allow_lowercase "$1" | tr '[a-z]' '[A-Z]'
}
guardify () {
path="$1"
file="$(basename "$path")"
file_ext="$(echo "$file" | sed -e 's|^.*\.||')"
file_base="$(echo "$file" | sed -e 's/^\(.*\)\.\([^\.]*\)$/\1/')"
dirs="$(dirname "$path")"
first_dir="$(echo "$dirs" | cut -d / -f 1)"
last_dir="$(echo "$dirs" | sed -e 's|^.*/||')"
echo -n "$INPUT_PATTERN" | sed \
-e 's/{path}/'"$(macrofy "$path")"'/g' \
-e 's/{file}/'"$(macrofy "$file")"'/g' \
-e 's/{file_base}/'"$(macrofy "$file_base")"'/g' \
-e 's/{file_ext}/'"$(macrofy "$file_ext")"'/g' \
-e 's/{dirs}/'"$(macrofy "$dirs")"'/g' \
-e 's/{first_dir}/'"$(macrofy "$first_dir")"'/g' \
-e 's/{last_dir}/'"$(macrofy "$last_dir")"'/g'
}
die () {
echo "::error::$1"
exit 1
}
echo "Checking pattern '$INPUT_PATTERN' ..."
dummy="dir1/dir2/dir3/base.between.ext"
actual="$(guardify dir1/dir2/dir3/base.between.ext)"
expected="$(macrofy_allow_lowercase "$actual")"
if test "$actual" != "$expected"
then
cat <<EOF
Oops! We tested the dummy file name
$dummy
and the given pattern produced
$actual
which contains invalid characters.
Removing invalid characters produces
$expected
Please fix this.
EOF
die "Pattern contains invalid characters!"
fi
cd "$GITHUB_WORKSPACE" || die "Internal error: Cannot change to GitHub workspace directory."
echo "Switching to given path '$INPUT_PATH' ..."
cd "$INPUT_PATH" || die "Cannot change directory"
ret=0
failed=""
fail () {
failed="$failed$1 "
echo "::error file={$1}::Header guard macro $2 expected in $1 but not found"
ret=1
}
for header in $(find . -regex '.\+\.\(h\|H\|hh\|hpp\|hxx\|cuh\)' |
sed -e 's/^\.\///' |
grep -e "$INPUT_ONLY" |
grep -v -e '^.git/' ${INPUT_IGNORE:+-e} ${INPUT_IGNORE:+"$INPUT_IGNORE"})
do
guard="$(guardify "$header")"
echo "Checking $header for $guard"
awk '
/^\s*#\s*ifndef\s+'"$guard"'\>/ { ifndef = 1 }
/^\s*#\s*define\s+'"$guard"'\>/ && ifndef { define = 1 }
ifndef && define { exit 1 }' "$header" &&
fail "$header" "$guard"
done
echo "fails=$failed" >> $GITHUB_OUTPUT
exit $ret