mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-02-14 10:00:05 +00:00
update-majors.sh and update-copyright-year.sh can use linux sed flags
This commit is contained in:
@@ -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.
|
||||
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"
|
||||
# This uses MacOS sed flags to replace "XXXX" with "XXXX-year" in the copyright notice.
|
||||
# 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
|
||||
|
||||
@@ -36,11 +36,20 @@ for m in $modules; do
|
||||
found_new_version=$?
|
||||
if [[ $found_new_version == 0 ]]; then
|
||||
echo "Found new version $next_version. Replacing imports..."
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user