-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
51 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,29 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2021 the Pinniped contributors. All Rights Reserved. | ||
# Copyright 2021-2023 the Pinniped contributors. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Check if copyright statements include the current year | ||
# | ||
|
||
set -euo pipefail | ||
|
||
files=$(git diff --cached --name-only) | ||
year=$(date +"%Y") | ||
|
||
missing_copyright_files=() | ||
|
||
for f in $files; do | ||
head -10 $f | grep -i copyright 2>&1 1>/dev/null || continue | ||
head -10 "$f" | grep -i 'Copyright.*the Pinniped contributors' 2>&1 1>/dev/null || continue | ||
|
||
if ! grep -i -e "copyright.*$year" $f 2>&1 1>/dev/null; then | ||
missing_copyright_files="$missing_copyright_files $f" | ||
if ! head -10 "$f" | grep -i -e "Copyright.*$year.*the Pinniped contributors" 2>&1 1>/dev/null; then | ||
missing_copyright_files+=("$f") | ||
fi | ||
done | ||
|
||
if [ -n "$missing_copyright_files" ]; then | ||
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:" | ||
for f in $missing_copyright_files; do | ||
for f in "${missing_copyright_files[@]}"; do | ||
echo " $f" | ||
done | ||
echo "Try using hack/update-copyright-year.sh to update the copyright automatically in staged files." | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2021-2023 the Pinniped contributors. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
set -euo pipefail | ||
|
||
if [[ "$OSTYPE" != "darwin"* ]]; then | ||
echo "This script was only written for MacOS (due to differences with Linux sed flags)" | ||
exit 1 | ||
fi | ||
|
||
files=$(git diff --cached --name-only) | ||
year=$(date +"%Y") | ||
|
||
missing_copyright_files=() | ||
|
||
for f in $files; do | ||
head -10 "$f" | grep -i 'Copyright.*the Pinniped contributors' 2>&1 1>/dev/null || continue | ||
|
||
if ! head -10 "$f" | grep -i -e "Copyright.*$year.*the Pinniped contributors" 2>&1 1>/dev/null; then | ||
missing_copyright_files+=("$f") | ||
fi | ||
done | ||
|
||
if [[ "${#missing_copyright_files[@]}" -gt "0" ]]; then | ||
echo "Fixing copyright notice in the following files:" | ||
for f in "${missing_copyright_files[@]}"; do | ||
echo " $f" | ||
# The rule when updating copyrights is to always keep the starting year, | ||
# and to replace the ending year with the current year. | ||
# This uses MacOS sed flags to replace "XXXX-YYYY" with "XXXX-year" in the copyright notice. | ||
sed -E -e 's/Copyright ([0-9]{4})-([0-9]{4}) the Pinniped contributors/Copyright \1-2023 the Pinniped contributors/' -i '' "$f" | ||
# This uses MacOS sed flags to replace "XXXX" with "XXXX-year" in the copyright notice. | ||
sed -E -e 's/Copyright ([0-9]{4}) the Pinniped contributors/Copyright \1-2023 the Pinniped contributors/' -i '' "$f" | ||
done | ||
echo "Done!" | ||
exit 1 | ||
fi |