-
Notifications
You must be signed in to change notification settings - Fork 51
/
copyright_line_check.sh
executable file
·46 lines (37 loc) · 1.64 KB
/
copyright_line_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
#!/usr/bin/env bash
# Copyright 2018-present Kensho Technologies, LLC.
# Fail on first error, on undefined variables, and on errors in a pipeline.
set -euo pipefail
# Enable recursive globbing, and make globs that do not match return null values.
shopt -s globstar nullglob
# Make sure the current working directory for this script is the root directory.
pushd "$(git rev-parse --show-toplevel)" > /dev/null
ensure_file_has_copyright_line() {
filename="$1"
lines_to_examine=2
copyright_regex='# Copyright 2[0-9][0-9][0-9]\-present Kensho Technologies, LLC\.'
file_head=$(head -"$lines_to_examine" "$filename")
set +e
echo "$file_head" | grep --regexp="$copyright_regex" >/dev/null
result="$?"
set -e
if [[ "$result" != "0" ]]; then
# The check will have to be more sophisticated if we
echo "The file $filename appears to be missing a copyright line, file starts:"
echo "$file_head"
echo 'Please add the following at the top of the file (right after the #! line in scripts):'
echo -e "\n # Copyright $(date +%Y)-present Kensho Technologies, LLC.\n"
exit 1
fi
}
# There may be many Python files in the root directory that are not checked into the repo:
# virtualenv files, package build files etc.
# Only check the setup.py file in the root directory.
ensure_file_has_copyright_line './setup.py'
# Check every python file in the package's source directory.
for filename in ./graphql_compiler/**/*.py; do
# Don't run copyright check for snapshot files
if [[ "$filename" != *"/snapshots/snap_"*".py" ]]; then
ensure_file_has_copyright_line "$filename"
fi
done