Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common: allow check_license to apply proposed changes #6058

Merged
merged 5 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,30 @@ jobs:
sudo pip install flake8
sudo apt-get install clang-format-14

- name: Check licenses
- name: Check license
id: check_license
continue-on-error: true
env:
NDCTL_ENABLE: n # just to speed up the job
PMEMOBJ_IGNORE_DIRTY_SHUTDOWN: y # not recommended for production
PMEMOBJ_IGNORE_BAD_BLOCKS: y # not recommended for production
run: make -j$(nproc) check-license
run: |
make -j$(nproc) check-license || true
git diff > /tmp/check-license.diff
[ $(cat /tmp/check-license.diff | wc -l ) -gt 0 ] && exit 1
exit 0

- name: Upload check license diff
if: steps.check_license.outcome != 'success'
uses: actions/upload-artifact@v4
with:
name: check-license.diff
path: /tmp/check-license.diff

- name: Check license - Exit code
run: |
[ "${{steps.check_license.outcome}}" != "success" ] && exit 1
exit 0

- name: Check style
env:
Expand Down
29 changes: 21 additions & 8 deletions utils/check_license/check-headers.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2016-2023, Intel Corporation
# Copyright 2016-2024, Intel Corporation

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

Expand All @@ -26,7 +26,6 @@ shift
PATTERN=`mktemp`
TMP=`mktemp`
TMP2=`mktemp`
TEMPFILE=`mktemp`
rm -f $PATTERN $TMP $TMP2

if [ "$1" == "-h" -o "$1" == "--help" ]; then
Expand All @@ -47,6 +46,12 @@ else
SHALLOW_CLONE=0
fi

if [ $($GIT diff | wc -l) -gt 0 ]; then
DIRTY_SOURCE=1
else
DIRTY_SOURCE=0
fi

VERBOSE=0
CHECK_ALL=0
while [ "$1" != "" ]; do
Expand Down Expand Up @@ -99,9 +104,6 @@ for file in $FILES ; do
# git is called with -C flag so filepaths should be relative to SOURCE_ROOT
src_path="${SOURCE_ROOT}/$file"
[ ! -f $src_path ] && continue
# ensure that file is UTF-8 encoded
ENCODING=`file -b --mime-encoding $src_path`
iconv -f $ENCODING -t "UTF-8" $src_path > $TEMPFILE

if ! grep -q "SPDX-License-Identifier: $LICENSE" $src_path; then
echo "$src_path:1: no $LICENSE SPDX tag found " >&2
Expand Down Expand Up @@ -150,7 +152,7 @@ for file in $FILES ; do
s/.*Copyright \([0-9]\+\)-\([0-9]\+\),.*/\1-\2/
s/.*Copyright \([0-9]\+\),.*/\1-\1/' $src_path`
if [ -z "$YEARS" ]; then
echo >&2 "$src_path:1: No copyright years found"
echo >&2 "$src_path:2: No copyright years found"
RV=1
continue
fi
Expand All @@ -171,15 +173,21 @@ s/.*Copyright \([0-9]\+\),.*/\1-\1/' $src_path`
else
NEW=$COMMIT_FIRST-$COMMIT_LAST
fi
echo "$file:1: error: wrong copyright date: (is: $YEARS, should be: $NEW)" >&2
if [ $HEADER_FIRST == $HEADER_LAST ]; then
YEARS=$HEADER_LAST
fi
echo "$file:2: error: wrong copyright date: (is: $YEARS, should be: $NEW)" >&2
if [ $DIRTY_SOURCE -eq 0 ]; then
sed -i "s/\(Copyright\) $YEARS\(, Intel Corporation\)/\1 $NEW\2/" $src_path
fi
RV=1
fi
else
echo "$file:1: unknown commit dates" >&2
RV=1
fi
done
rm -f $TMP $TMP2 $TEMPFILE
rm -f $TMP $TMP2

$(dirname "$0")/check-ms-license.pl $FILES

Expand All @@ -188,5 +196,10 @@ if [ $RV -eq 0 ]; then
echo "Copyright headers are OK."
else
echo "Error(s) in copyright headers found!" >&2
if [ $DIRTY_SOURCE -eq 0 ]; then
echo "Please see the proposed changes to fix the found issues." >&2
else
echo "Since the source is dirty no changes have been proposed." >&2
fi
fi
exit $RV
Loading