ContainerImage.Pinniped/hack/check-copyright-year.sh

30 lines
949 B
Bash
Raw Normal View History

#!/bin/bash
2023-01-18 21:36:23 +00:00
# Copyright 2021-2023 the Pinniped contributors. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
2023-01-18 21:36:23 +00:00
set -euo pipefail
files=$(git diff --cached --name-only)
year=$(date +"%Y")
2023-01-18 21:36:23 +00:00
missing_copyright_files=()
for f in $files; do
2023-01-18 21:36:23 +00:00
head -10 "$f" | grep -i 'Copyright.*the Pinniped contributors' 2>&1 1>/dev/null || continue
2023-01-18 21:36:23 +00:00
if ! head -10 "$f" | grep -i -e "Copyright.*$year.*the Pinniped contributors" 2>&1 1>/dev/null; then
missing_copyright_files+=("$f")
fi
done
2023-01-18 21:36:23 +00:00
if [[ "${#missing_copyright_files[@]}" -gt "0" ]]; then
echo "Copyright notice should include the year the file was created and the year the file was last modified."
echo "$year is missing in the copyright notice of the following files:"
2023-01-18 21:36:23 +00:00
for f in "${missing_copyright_files[@]}"; do
echo " $f"
done
2023-01-18 21:36:23 +00:00
echo "Try using hack/update-copyright-year.sh to update the copyright automatically in staged files."
exit 1
fi