From 136ec71e7b6116de20795d6a384363b0b7b15259 Mon Sep 17 00:00:00 2001 From: saar-IL Date: Wed, 18 Mar 2026 10:50:18 +0200 Subject: [PATCH] Update check_license.sh --- scripts/ci/check_license.sh | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/scripts/ci/check_license.sh b/scripts/ci/check_license.sh index 697f390b096a..383620eef6d5 100755 --- a/scripts/ci/check_license.sh +++ b/scripts/ci/check_license.sh @@ -1,13 +1,30 @@ -#!/bin/bash +#!/usr/bin/env bash -set -e +set -euo pipefail -# Make sure we don't introduce accidental references to PATENTS. -EXPECTED='scripts/ci/check_license.sh' -ACTUAL=$(git grep -l PATENTS) +# File that is allowed to contain the string "PATENTS" +EXPECTED_FILE="scripts/ci/check_license.sh" -if [ "$EXPECTED" != "$ACTUAL" ]; then - echo "PATENTS crept into some new files?" - diff -u <(echo "$EXPECTED") <(echo "$ACTUAL") || true - exit 1 +# Get all files that contain "PATENTS" (ignore binary files, handle no matches safely) +mapfile -t ACTUAL_FILES < <(git grep -l --no-color -- "PATENTS" || true) + +# If exactly one file and it matches expected → OK +if [[ "${#ACTUAL_FILES[@]}" -eq 1 && "${ACTUAL_FILES[0]}" == "$EXPECTED_FILE" ]]; then + exit 0 fi + +echo "Error: Unexpected references to 'PATENTS' found." + +echo "Expected:" +echo " $EXPECTED_FILE" + +echo "Actual:" +for file in "${ACTUAL_FILES[@]:-}"; do + echo " $file" +done + +echo +echo "Diff:" +diff -u <(printf "%s\n" "$EXPECTED_FILE") <(printf "%s\n" "${ACTUAL_FILES[@]}") || true + +exit 1