[license] keep hacky way under UPDATE
All checks were successful
eden-license / license-header (pull_request) Successful in 33s

Signed-off-by: Caio Oliveira <caiooliveirafarias0@gmail.com>
This commit is contained in:
Caio Oliveira 2025-09-14 20:42:49 -03:00
parent 9458928d30
commit 51f58c695f
Signed by: DraVee
GPG key ID: 362DA3DC1901E080

View file

@ -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
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 "Usage Examples:"
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=true .ci/license-header.sh"
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=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
fi
@ -126,7 +137,7 @@ cat << EOF
EOF
TMP_DIR=$(mktemp -d /tmp/license-header.XXXXXX) || exit 1
if [ "$FIX" = "true" ]; then
if [ "$FIX" = "true" ] || [ "$UPDATE" = "true" ]; then
echo
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
# 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
{