update-majors.sh and update-copyright-year.sh can use linux sed flags

This commit is contained in:
Ryan Richard
2026-01-21 12:10:39 -08:00
parent 5d9b7a3346
commit ec334d1175
2 changed files with 27 additions and 14 deletions

View File

@@ -1,15 +1,10 @@
#!/bin/bash
# Copyright 2021-2024 the Pinniped contributors. All Rights Reserved.
# Copyright 2021-2026 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")
@@ -29,10 +24,19 @@ if [[ "${#missing_copyright_files[@]}" -gt "0" ]]; then
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-'"$year"' 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-'"$year"' the Pinniped contributors/' -i '' "$f"
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!"
exit 1

View File

@@ -36,10 +36,19 @@ for m in $modules; do
found_new_version=$?
if [[ $found_new_version == 0 ]]; then
echo "Found new version $next_version. Replacing imports..."
find . -wholename './.*' -prune -o \
-path ./generated -prune -o \
-type f -name '*.go' -print0 |
xargs -0 sed -i '' "s#${m}#${next_version}#g"
if [[ "$(uname -s)" == "Linux" ]]; then
# sed on Linux uses -i'' (no space in between).
find . -wholename './.*' -prune -o \
-path ./generated -prune -o \
-type f -name '*.go' -print0 |
xargs -0 sed -i'' "s#${m}#${next_version}#g"
else
# sed on MacOS uses -i '' (with space in between).
find . -wholename './.*' -prune -o \
-path ./generated -prune -o \
-type f -name '*.go' -print0 |
xargs -0 sed -i '' "s#${m}#${next_version}#g"
fi
fi
set -e
done