Skip to content

Commit 007a4cd

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 5e00b7e commit 007a4cd

File tree

2 files changed

+46
-34
lines changed

2 files changed

+46
-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: 46 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,45 @@ 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 [[ -n "$COMMIT_FIRST" && -n "$COMMIT_LAST" ]]; then
147+
if [[ $HEADER_FIRST -le $COMMIT_FIRST ]]; then
148+
if [[ $HEADER_LAST -eq $COMMIT_LAST ]]; then
149+
continue
150+
else
151+
if [[ ${UPDATE_DATES} -eq 1 ]]; then
152+
NEW="$HEADER_FIRST-$COMMIT_LAST"
153+
echo "Updating copyright date in $src_path: $YEARS -> $NEW"
154+
sed -i "s/Copyright ${YEARS}/Copyright ${NEW}/g" "${src_path}"
155+
else
156+
echo "$file:1: error: wrong copyright date: (is: $YEARS, should be: $HEADER_FIRST-$COMMIT_LAST)" >&2
157+
RV=1
158+
fi
159+
fi
160+
else
161+
if [[ $COMMIT_FIRST -eq $COMMIT_LAST ]]; then
162+
NEW=$COMMIT_LAST
163+
else
164+
NEW=$COMMIT_FIRST-$COMMIT_LAST
165+
fi
166+
167+
if [[ "$YEARS" == "$NEW" ]]; then
168+
continue
169+
else
170+
if [[ ${UPDATE_DATES} -eq 1 ]]; then
171+
echo "Updating copyright date in $src_path: $YEARS -> $NEW"
172+
sed -i "s/Copyright ${YEARS}/Copyright ${NEW}/g" "${src_path}"
173+
else
174+
echo "$file:1: error: wrong copyright date: (is: $YEARS, should be: $NEW)" >&2
175+
RV=1
176+
fi
177+
fi
178+
fi
179+
fi
180+
else
181+
echo "error: unknown commit dates in file: $file" >&2
182+
RV=1
183+
fi
168184
done
169185
rm -f $TMP $TMP2 $TEMPFILE
170186

0 commit comments

Comments
 (0)