-
Notifications
You must be signed in to change notification settings - Fork 22
66 lines (53 loc) · 1.92 KB
/
copyright_check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
---
name: copyright
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
copyright:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Run check
run: |
bash - << 'SCRIPT'
# Get the current year
current_year=$(date +"%Y")
# Ignore files and directories
ignore_files="(.git|node_modules|build|dist|temp|check_copyright.sh)"
# Directory to search
search_dir="."
# Pattern to look for: 'Copyright (c)'
pattern="Copyright (c)"
exit_code=0
# Find files containing the copyright notice
echo "Checking files in $search_dir for outdated copyright years..."
echo "Current year is $current_year."
# Iterate over files, redirecting into while loop to avoid subshell
find $search_dir -type f -print0 > tmp.$$ || exit 1
while IFS= read -r -d $'\0' file; do
# Skip files in the ignore list
if [[ "$file" =~ $ignore_files ]]; then
continue
fi
# Use grep to find the line and awk to extract the year
year_line=$(grep "$pattern" "$file")
if [[ -n "$year_line" ]]; then
# Extract year assuming the year is after 'Copyright (c)'
year=$(echo "$year_line" | grep -E -oh "[0-9]{4}-[0-9]{4}")
year=$(echo "$year" | awk -F'-' '{print $2}')
# Check if the extracted year is not equal to the current year
if [[ "$year" -ne "$current_year" ]]; then
echo "Outdated copyright year ($year) in file: $file"
exit_code=1
fi
fi
done < tmp.$$
rm tmp.$$ # Clean up temporary file
echo "Check complete."
exit $exit_code
SCRIPT