-
Notifications
You must be signed in to change notification settings - Fork 302
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
DAOS-15677 cq: add copyright GHA #15552
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
585384d
DAOS-15677 cq: add copyright GHA
daltonbohning 4d45740
intentionally do not update
daltonbohning 0f9db64
more debug
daltonbohning f7ea6bd
use merge-base
daltonbohning 4112206
add lineno
daltonbohning 5609bf3
cleanup
daltonbohning e8678b5
fix fix
daltonbohning File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright 2024 Intel Corporation. | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause-Patent | ||
# | ||
# Check or update copyright date in modified files. | ||
# Usage: check_update_copyright.sh <git_target> <githook|gha> | ||
# mode "githook" will update copyright dates in place. | ||
# mode "gha" will just print a warning in a GHA-compatible format. | ||
|
||
set -e | ||
|
||
git_target="$1" | ||
mode="$2" | ||
case "$mode" in | ||
"githook" | "gha") | ||
;; | ||
*) | ||
echo "Usage: check_update_copyright.sh <githook|gha>" | ||
exit 1 | ||
esac | ||
|
||
# Navigate to repo root | ||
PARENT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | ||
cd "$PARENT_DIR"/../../ | ||
|
||
|
||
regex='(^[[:blank:]]*[\*/]*.*)((Copyright[[:blank:]]*)([0-9]{4})(-([0-9]{4}))?)([[:blank:]]*(Intel.*$))' | ||
year=$(date +%Y) | ||
errors=0 | ||
targets=( | ||
# Entries with wildcard. These must be first and start with '*' or | ||
# older versions of git will return files that were not changed. | ||
'*.c' | ||
'*.h' | ||
'*.go' | ||
'*.py' | ||
'*.proto' | ||
'*.java' | ||
'*.yml' | ||
'*.yaml' | ||
'*.sh' | ||
'*.bash' | ||
'*Dockerfile*' | ||
'*README*' | ||
'*LICENSE*' | ||
'*NOTICE*' | ||
'*.txt' | ||
'*.md' | ||
# Entries without a wildcard | ||
'Makefile' | ||
'Jenkinsfile' | ||
'SConscript' | ||
'SConstruct' | ||
'copyright' | ||
'.env' | ||
) | ||
|
||
if [ -z "$files" ]; then | ||
files=$(git diff "$git_target" --cached --diff-filter=AM --name-only -- "${targets[@]}") | ||
else | ||
echo " Checking against custom files" | ||
fi | ||
|
||
os=$(uname -s) | ||
|
||
. utils/githooks/git-version.sh | ||
|
||
for file in $files; do | ||
if [[ "$file" == *vendor* ]] || [[ "$file" == *pb.go ]] || | ||
[[ "$file" == *_string.go ]] || [[ "$file" == *pb-c* ]] || | ||
{ [ "$mode" == "githook" ] && | ||
[ "$git_vercode" -ge 2030000 ] && | ||
[ "$(git diff --cached -I Copyright "$file")" = '' ]; }; then | ||
continue | ||
fi | ||
read -r y1 y2 <<< "$(sed -nre "s/^.*$regex.*$/\4 \6/p" "$file")" | ||
if [[ -z $y1 ]] ; then | ||
# Print warning but don't error on non-existent copyright | ||
echo " Copyright Information not found in: $file" | ||
Comment on lines
+79
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's possible to propagate warnings to GHA but I'm not sure how many files would be flagged here |
||
elif [[ $y1 -ne $year && $year -ne $y2 ]] ; then | ||
if [[ "$mode" == "githook" ]]; then | ||
# Update copyright in place | ||
if ! git reset "$file"; then | ||
echo " Unable to un-stage $file" | ||
errors=$((errors + 1)) | ||
fi | ||
if [[ "$os" == 'Linux' ]]; then | ||
sed -i -re "s/$regex/\1Copyright $y1-$year \8/" "$file" | ||
else | ||
sed -i '' -re "s/$regex/\1Copyright $y1-$year \8/" "$file" | ||
fi | ||
|
||
if ! git add "$file"; then | ||
echo " Unable to re-stage $file" | ||
errors=$((errors + 1)) | ||
fi | ||
elif [[ "$mode" == "gha" ]]; then | ||
# Print error but do not update | ||
lineno="$(grep -nE "$regex" "$file" | cut -f1 -d:)" | ||
echo "::error file=$file,line=$lineno::Copyright out of date" | ||
errors=$((errors + 1)) | ||
fi | ||
fi | ||
done | ||
|
||
if [[ $errors -ne 0 ]]; then | ||
echo " $errors errors while checking/fixing copyrights." | ||
exit 1 | ||
fi |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright 2022-2024 Intel Corporation. | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause-Patent | ||
# | ||
# A git hook to validate and correct the copyright date in source files. | ||
|
||
_print_githook_header "Copyright" | ||
if [ -e .git/MERGE_HEAD ]; then | ||
echo "Merge commit. Skipping" | ||
exit 0 | ||
fi | ||
|
||
echo "Updating copyright headers" | ||
|
||
utils/cq/check_update_copyright.sh "$TARGET" githook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plan to make the GHA required after we're sure it's stable