Skip to content

Commit 47e6509

Browse files
committed
Added a condition to check the validity of the starting date and some fixes
Changes for this commit: - adding a condition to check the validity of the starting date - broken pipe fix - updating date fix
1 parent 5db7da2 commit 47e6509

File tree

2 files changed

+50
-34
lines changed

2 files changed

+50
-34
lines changed

.github/workflows/reusable_checks.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ jobs:
5656
run: |
5757
./scripts/check_license/check_headers.sh . "Apache-2.0 WITH LLVM-exception" -v
5858
59-
- name: Run copyright-format
60-
run: |
61-
./scripts/check_license/check_headers.sh . "Apache-2.0 WITH LLVM-exception" -d
62-
6359
- name: Run a spell check
6460
uses: crate-ci/typos@b63f421581dce830bda2f597a678cb7776b41877 # v1.18.2
6561
with:

scripts/check_license/check_headers.sh

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
2-
# Copyright (C) 2016-2024 Intel Corporation
3-
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
4-
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2+
# Copyright (C) 2016-2025 Intel Corporation
3+
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

66
# check-headers.sh - check copyright and license in source files
77

@@ -68,10 +68,10 @@ while [ "$1" != "" ]; do
6868
done
6969

7070
if [ $CHECK_ALL -eq 0 ]; then
71-
CURRENT_COMMIT=$($GIT log --pretty=%H -1)
72-
MERGE_BASE=$($GIT merge-base HEAD origin/master 2>/dev/null)
71+
CURRENT_COMMIT=$($GIT --no-pager log --pretty=%H -1)
72+
MERGE_BASE=$($GIT merge-base HEAD origin/main 2>/dev/null)
7373
[ -z $MERGE_BASE ] && \
74-
MERGE_BASE=$($GIT log --pretty="%cN:%H" | grep GitHub | head -n1 | cut -d: -f2)
74+
MERGE_BASE=$($GIT --no-pager log --pretty="%cN:%H" | grep GitHub 2>/dev/null | head -n1 | cut -d: -f2)
7575
[ -z $MERGE_BASE -o "$CURRENT_COMMIT" = "$MERGE_BASE" ] && \
7676
CHECK_ALL=1
7777
fi
@@ -127,7 +127,7 @@ for file in $FILES ; do
127127
LAST=` tail -n1 $TMP2`
128128

129129
YEARS=$(sed '
130-
/.*Copyright (C) \+.*[0-9-]\+ Intel Corporation/!d
130+
/.*Copyright (C) [0-9-]\+ Intel Corporation/!d
131131
s/.*Copyright (C) \([0-9]\+\)-\([0-9]\+\).*/\1-\2/
132132
s/.*Copyright (C) \([0-9]\+\).*/\1/' "$src_path")
133133
if [ -z "$YEARS" ]; then
@@ -142,29 +142,49 @@ s/.*Copyright (C) \([0-9]\+\).*/\1/' "$src_path")
142142
COMMIT_FIRST=`echo $FIRST | cut -d"-" -f1`
143143
COMMIT_LAST=` echo $LAST | cut -d"-" -f1`
144144

145-
if [ "$COMMIT_FIRST" != "" -a "$COMMIT_LAST" != "" ]; then
146-
if [[ -n "$COMMIT_FIRST" && -n "$COMMIT_LAST" ]]; then
147-
if [[ $COMMIT_FIRST -eq $COMMIT_LAST ]]; then
148-
NEW=$COMMIT_LAST
149-
else
150-
NEW=$COMMIT_FIRST-$COMMIT_LAST
151-
fi
152-
153-
if [[ "$YEARS" == "$NEW" ]]; then
154-
continue
155-
else
156-
if [[ ${UPDATE_DATES} -eq 1 ]]; then
157-
sed -i "s/Copyright ${YEARS}/Copyright ${NEW}/g" "${src_path}"
158-
else
159-
echo "$file:1: error: wrong copyright date: (is: $YEARS, should be: $NEW)" >&2
160-
RV=1
161-
fi
162-
fi
163-
fi
164-
else
165-
echo "error: unknown commit dates in file: $file" >&2
166-
RV=1
167-
fi
145+
if [ "$COMMIT_FIRST" != "" -a "$COMMIT_LAST" != "" ]; then
146+
if [ "$COMMIT_FIRST" -lt "$HEADER_FIRST" ]; then
147+
RV=1
148+
fi
149+
150+
if [[ -n "$COMMIT_FIRST" && -n "$COMMIT_LAST" ]]; then
151+
if [[ $HEADER_FIRST -le $COMMIT_FIRST ]]; then
152+
if [[ $HEADER_LAST -eq $COMMIT_LAST ]]; then
153+
continue
154+
else
155+
NEW="$HEADER_FIRST-$COMMIT_LAST"
156+
if [[ ${UPDATE_DATES} -eq 1 ]]; then
157+
echo "Updating copyright date in $src_path: $YEARS -> $NEW"
158+
sed -i "s/Copyright (C) ${YEARS}/Copyright (C) ${NEW}/g" "${src_path}"
159+
else
160+
echo "$file:1: error: wrong copyright date: (is: $YEARS, should be: $NEW)" >&2
161+
RV=1
162+
fi
163+
fi
164+
else
165+
if [[ $COMMIT_FIRST -eq $COMMIT_LAST ]]; then
166+
NEW=$COMMIT_LAST
167+
else
168+
NEW=$COMMIT_FIRST-$COMMIT_LAST
169+
fi
170+
171+
if [[ "$YEARS" == "$NEW" ]]; then
172+
continue
173+
else
174+
if [[ ${UPDATE_DATES} -eq 1 ]]; then
175+
echo "Updating copyright date in $src_path: $YEARS -> $NEW"
176+
sed -i "s/Copyright (C) ${YEARS}/Copyright (C) ${NEW}/g" "${src_path}"
177+
else
178+
echo "$file:1: error: wrong copyright date: (is: $YEARS, should be: $NEW)" >&2
179+
RV=1
180+
fi
181+
fi
182+
fi
183+
fi
184+
else
185+
echo "error: unknown commit dates in file: $file" >&2
186+
RV=1
187+
fi
168188
done
169189
rm -f $TMP $TMP2 $TEMPFILE
170190

0 commit comments

Comments
 (0)