-
Notifications
You must be signed in to change notification settings - Fork 467
Expand file tree
/
Copy pathcheckHeader.sh
More file actions
executable file
·73 lines (66 loc) · 3.04 KB
/
checkHeader.sh
File metadata and controls
executable file
·73 lines (66 loc) · 3.04 KB
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
#!/bin/bash
# *
# * This Source Code Form is subject to the terms of the Mozilla Public
# * License, v. 2.0. If a copy of the MPL was not distributed with this
# * file, You can obtain one at http://mozilla.org/MPL/2.0/.
# *
# Checks for the existance of the MPL 2.0 header
MPL_REGEX=".*?This\W+Source\W+Code\W+Form\W+is\W+subject\W+to\W+the\W+terms\W+of\W+the\W+Mozilla\W+Public\W+License,\W+v\.\W+2\.0\.\W+If\W+a\W+copy\W+of\W+the\W+MPL\W+was\W+not\W+distributed\W+with\W+this\W+file,\W+You\W+can\W+obtain\W+one\W+at\W+http:\/\/mozilla\.org\/MPL\/2\.0\/\."
# Get a list of files tracked by Git
FILES=$(git ls-files)
# Filter out text files
FILES=$(echo "$FILES" | grep -v ".*\.md")
FILES=$(echo "$FILES" | grep -v "\.editorconfig")
FILES=$(echo "$FILES" | grep -v "\.gitattributes")
FILES=$(echo "$FILES" | grep -v ".vscode")
FILES=$(echo "$FILES" | grep -v "package\.json")
# Filter out generated files
FILES=$(echo "$FILES" | grep -v "package-lock\.json")
# Filter out images
FILES=$(echo "$FILES" | grep -v "src\/client\/public\/.*")
# Filter out test data
FILES=$(echo "$FILES" | grep -v "src\/server\/test\/db\/data\/.*")
# Filter out outside scripts
FILES=$(echo "$FILES" | grep -v "src\/scripts\/oed\.service")
FILES=$(echo "$FILES" | grep -v "src\/scripts\/updateMamacMetersOEDCron\.bash")
FILES=$(echo "$FILES" | grep -v "src\/scripts\/updateEgaugeMetersOEDCron\.bash")
FILES=$(echo "$FILES" | grep -v "src\/scripts\/sendLogEmailCron\.bash")
FILES=$(echo "$FILES" | grep -v "src\/scripts\/refreshReadingViewsCron\.bash")
FILES=$(echo "$FILES" | grep -v "src\/scripts\/refreshHourlyReadingViewsCron\.bash")
# Filter out test data for Obvius
FILES=$(echo "$FILES" | grep -v "src\/server\/test\/web\/obvius\/.*")
# Filter out test data for CSV Pipeline
FILES=$(echo "$FILES" | grep -v "src\/server\/test\/web\/csvPipeline\/.*")
# Filter out test data for units Pipeline
FILES=$(echo "$FILES" | grep -v "src\/server\/test\/web\/units\/.*")
# Filter out test data for readings
FILES=$(echo "$FILES" | grep -v "src\/server\/test\/web\/readingsData\/.*")
# Filter out .github files
FILES=$(echo "$FILES" | grep -v ".github\/**")
# Filter out unit test files
FILES=$(echo "$FILES" | grep -v "src\/server\/data\/unit\/.*")
# Filter out crossSite test files
FILES=$(echo "$FILES" | grep -v "src/server/test/crossSite/something.csv")
# Counts the files listed in FILES
NFILES=$(echo $FILES | wc -w)
if [ "$NFILES" -eq "0" ]; then
echo "[MPL2] No files to check for header, please check the checkHeader.sh script.";
exit 1;
fi
echo "[MPL2] Checking $NFILES files for a Mozilla Public License 2.0 header."
# This searches for the above regex.
# P enables Perl and z enables multi-line support
# s turns off warnings, lv lists files that don't match
MISSING_HEADER=$(grep -Pz -slv "$MPL_REGEX" $FILES)
NMISSING=$(echo $MISSING_HEADER | wc -w)
# Check if there's
if [ ! -z "$MISSING_HEADER" ]; then
echo "[MPL2] The following $NMISSING files are missing headers:"
echo "$MISSING_HEADER"
echo ""
exit 1
else
echo "[MPL2] Every source file has a Mozilla Public License 2.0 header."
echo ""
exit 0
fi