-
-
Notifications
You must be signed in to change notification settings - Fork 8
69 lines (58 loc) · 2.27 KB
/
copyright.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
67
68
69
name: Copyright Check
on:
pull_request:
push:
jobs:
check-copyright:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Skip OM commits
if: github.event_name == 'push'
id: skip_check
run: |
COMMIT_MSG=$(git log --format=%B -n 1 ${{ github.sha }})
if [[ "$COMMIT_MSG" =~ ^OM\ PR ]]; then
echo "skip=true" >> $GITHUB_OUTPUT
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
- name: Get changed files
id: changed-files
if: github.event_name == 'pull_request' || steps.skip_check.outputs.skip != 'true'
uses: tj-actions/changed-files@v45
- name: Check copyright in modified files
if: github.event_name == 'pull_request' || steps.skip_check.outputs.skip != 'true'
shell: bash
run: |
# Get current year
CURRENT_YEAR=$(date +%Y)
# Initialize error flag
ERROR=0
# Loop through each modified file
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
# Skip if file doesn't exist (was deleted)
if [ ! -f "$file" ]; then
continue
fi
# Only check files with specific extensions
extension="${file##*.}"
if ! [[ "${extension,,}" =~ ^(css|js|php|phtml|template|xml)$ ]]; then
continue
fi
# Check if file contains the copyright string with current year
# Pattern matches either:
# @copyright Copyright (c) 2024 Maho (https://mahocommerce.com)
# @copyright Copyright (c) (2024-)2024 Maho (https://mahocommerce.com)
if ! grep -E -q "Copyright \(c\) (\(2024-\))?${CURRENT_YEAR} Maho \(https://mahocommerce\.com\)" "$file"; then
echo "❌ Copyright notice missing in: $file"
ERROR=1
fi
done
# Exit with error if any file is missing copyright
if [ $ERROR -eq 1 ]; then
echo "❌ Error: Some files are missing the required copyright notice"
exit 1
fi
echo "✅ Success: All modified files contain the required copyright notice"