Files
pinniped/hack/update-copyright-year.sh
Ryan Richard de32fdc304
Some checks failed
CodeQL / Analyze (go) (push) Failing after 2m0s
CodeQL / Analyze (javascript) (push) Failing after 1m24s
update-copyright-year.sh does not exit 1 on success so CI can call it
2026-01-21 12:21:56 -08:00

45 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
# Copyright 2021-2026 the Pinniped contributors. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
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.*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.
if [[ "$(uname -s)" == "Linux" ]]; then
# sed on Linux uses -i'' (no space in between).
# 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-'"$year"' the Pinniped contributors/' -i'' "$f"
# Replace "XXXX" with "XXXX-year" in the copyright notice.
sed -E -e 's/Copyright ([0-9]{4}) the Pinniped contributors/Copyright \1-'"$year"' the Pinniped contributors/' -i'' "$f"
else
# sed on MacOS uses -i '' (with space in between).
# 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-'"$year"' the Pinniped contributors/' -i '' "$f"
# Replace "XXXX" with "XXXX-year" in the copyright notice.
sed -E -e 's/Copyright ([0-9]{4}) the Pinniped contributors/Copyright \1-'"$year"' the Pinniped contributors/' -i '' "$f"
fi
done
echo "Done!"
fi