Browse Source

[license] keep hacky way under UPDATE

Signed-off-by: Caio Oliveira <caiooliveirafarias0@gmail.com>
pull/397/head
Caio Oliveira 6 months ago
committed by crueter
parent
commit
e8d03a13e7
  1. 37
      .ci/license-header.sh

37
.ci/license-header.sh

@ -14,8 +14,9 @@ if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
echo "This script checks and optionally fixes license headers in source, CMake and shell script files." echo "This script checks and optionally fixes license headers in source, CMake and shell script files."
echo echo
echo "Environment Variables:" echo "Environment Variables:"
echo " FIX=true Automatically add the correct license headers to offending files."
echo " COMMIT=true If FIX=true, commit the changes automatically."
echo " FIX=true | Automatically add the correct license headers to offending files."
echo " UPDATE=true | Automatically update current license headers of offending files."
echo " COMMIT=true | If FIX=true, commit the changes automatically."
echo echo
echo "Usage Examples:" echo "Usage Examples:"
echo " # Just check headers (will fail if headers are missing)" echo " # Just check headers (will fail if headers are missing)"
@ -24,8 +25,18 @@ if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
echo " # Fix headers only" echo " # Fix headers only"
echo " FIX=true .ci/license-header.sh" echo " FIX=true .ci/license-header.sh"
echo echo
echo " # Update headers only"
echo " # if COPYRIGHT_OWNER is '$COPYRIGHT_OWNER'"
echo " # or else will have 'FIX=true' behavior)"
echo " UPDATE=true .ci/license-header.sh"
echo
echo " # Fix headers and commit changes" echo " # Fix headers and commit changes"
echo " FIX=true COMMIT=true .ci/license-header.sh" echo " FIX=true COMMIT=true .ci/license-header.sh"
echo
echo " # Update headers and commit changes"
echo " # if COPYRIGHT_OWNER is '$COPYRIGHT_OWNER'"
echo " # or else will have 'FIX=true' behavior)"
echo " UPDATE=true COMMIT=true .ci/license-header.sh"
exit 0 exit 0
fi fi
@ -126,7 +137,7 @@ cat << EOF
EOF EOF
TMP_DIR=$(mktemp -d /tmp/license-header.XXXXXX) || exit 1 TMP_DIR=$(mktemp -d /tmp/license-header.XXXXXX) || exit 1
if [ "$FIX" = "true" ]; then
if [ "$FIX" = "true" ] || [ "$UPDATE" = "true" ]; then
echo echo
echo "license-header.sh: FIX set to true, fixing headers..." echo "license-header.sh: FIX set to true, fixing headers..."
@ -152,15 +163,17 @@ if [ "$FIX" = "true" ]; then
# this logic is bit hacky but sed don't work well with $VARIABLES # this logic is bit hacky but sed don't work well with $VARIABLES
# it's this or complete remove this logic and keep only the old way # it's this or complete remove this logic and keep only the old way
while IFS= read -r line || [ -n "$line" ]; do
if [ "$UPDATED" -eq 0 ] && echo "$line" | grep "$COPYRIGHT_OWNER" >/dev/null 2>&1; then
echo_header "$COMMENT_TYPE" >> "$TMP"
IFS= read -r _ || true
UPDATED=1
else
echo "$line" >> "$TMP"
fi
done < "$file"
if [ "$UPDATE" = "true" ]; then
while IFS= read -r line || [ -n "$line" ]; do
if [ "$UPDATED" -eq 0 ] && echo "$line" | grep "$COPYRIGHT_OWNER" >/dev/null 2>&1; then
echo_header "$COMMENT_TYPE" >> "$TMP"
IFS= read -r _ || true
UPDATED=1
else
echo "$line" >> "$TMP"
fi
done < "$file"
fi
if [ "$UPDATED" -eq 0 ]; then if [ "$UPDATED" -eq 0 ]; then
{ {

Loading…
Cancel
Save