forked from linuxserver/reverse-proxy-confs
-
Notifications
You must be signed in to change notification settings - Fork 0
81 lines (73 loc) · 3.66 KB
/
check_samples.yml
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
name: Check Samples
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
check-allowed-file-names:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Check Allowed File Names
run: |
NOT_SAMPLES=$(find . -not -path '*/\.*' -type f ! \( -name '*.conf.sample' -o -name 'README.md' -o -name 'LICENSE' \))
NOT_SAMPLES_COUNT=$(echo "${NOT_SAMPLES}" | wc -w)
if (( NOT_SAMPLES_COUNT > 0 )); then
for i in ${NOT_SAMPLES}; do
echo "::error file=${i},line=1,title=Disallowed filenames::This file extension is not allowed, only .sample is allowed"
done
exit 1
fi
- name: Check Executable Bit
run: |
EXECUTABLE_BIT=$(find . -not -path '*/\.*' -type f -executable)
EXECUTABLE_BIT_COUNT=$(echo "${EXECUTABLE_BIT}" | wc -w)
if (( EXECUTABLE_BIT_COUNT > 0 )); then
for i in ${EXECUTABLE_BIT}; do
echo "::error file=${i},line=1,title=Executable Bit::This file is set as exectutable, which is not allowed"
done
exit 1
fi
- name: Check Line Endings
run: |
CRLF_ENDINGS=$(find . -not -path '*/\.*' -type f -exec file "{}" ";" | grep CRLF || true)
CRLF_ENDINGS_COUNT=$(echo "${CRLF_ENDINGS}" | wc -w)
if (( CRLF_ENDINGS_COUNT > 0 )); then
for i in ${CRLF_ENDINGS}; do
echo "::error file=${i},line=1,title=Line Endings::This file has CRLF (Windows) line endings, which is not allowed"
done
exit 1
fi
- name: Check Version Date Line Exists
run: |
# Date regex based on https://www.html5pattern.com/Dates
VERSION_LINE_MISSING=$(find . -not -path '*/\.*' -type f -name '*.conf.sample' -exec grep -H -c -P '^## Version (?:19|20|21)[0-9]{2}/(?:(?:0[1-9]|1[0-2])/(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])/(?:30))|(?:(?:0[13578]|1[02])/31))$' {} \; | grep 0$ | cut -d':' -f1)
VERSION_LINE_MISSING_COUNT=$(echo "${VERSION_LINE_MISSING}" | wc -w)
if (( VERSION_LINE_MISSING_COUNT > 0 )); then
for i in ${VERSION_LINE_MISSING}; do
echo "::error file=${i},line=1,title=Version Line::This file is missing the version date line or it is not formatted correctly (YYYY/MM/DD)"
done
exit 1
fi
- name: Check Nginx Conf Validity
run: |
curl -fsL "https://raw.githubusercontent.com/linuxserver/docker-swag/master/root/defaults/nginx/proxy.conf.sample" -o proxy.conf
docker run -d --rm --name nginx -v "${GITHUB_WORKSPACE}:/testconfs:ro" ghcr.io/linuxserver/nginx
sleep 5
docker exec nginx bash -c "\
mkdir -p /config/nginx/proxy-confs && \
cp /testconfs/*.conf.sample /config/nginx/proxy-confs/ && \
cp /testconfs/proxy.conf /config/nginx/ && \
rm -rf /config/nginx/proxy-confs/{_template.sub*,heimdall.subf*,boinc.subf*,organizr.subf*,wordpress.subf*} && \
echo 'include /config/nginx/proxy-confs/*.subdomain.conf.sample;' >> /config/nginx/site-confs/default.conf && \
sed -i -r 's|(root \\\$root;)|\1\ninclude /config/nginx/proxy-confs/*.subfolder.conf.sample;|' /config/nginx/site-confs/default.conf"
VALIDITY=$(docker exec nginx nginx -t 2>&1) || :
echo "${VALIDITY}"
echo "${VALIDITY}" >> $GITHUB_STEP_SUMMARY
if ! docker exec nginx nginx -t >/dev/null 2>&1; then
docker stop nginx
exit 1
fi
docker stop nginx