-
Notifications
You must be signed in to change notification settings - Fork 0
51 lines (40 loc) · 1.29 KB
/
check-copyright-header.yml
File metadata and controls
51 lines (40 loc) · 1.29 KB
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
name: Verify copyright year in modified files
on:
pull_request:
push:
branches: [ main ]
jobs:
copyright-check:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Verify copyright year in modified files
shell: bash
run: |
set -euo pipefail
CURRENT_YEAR="$(date +%Y)"
# Determine base ref
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BASE_REF="origin/${{ github.base_ref }}"
else
BASE_REF="$(git rev-parse HEAD~1)"
fi
MODIFIED_FILES=$(git diff --name-only "$BASE_REF"...HEAD)
FAIL=0
for file in $MODIFIED_FILES; do
# Skip deleted or non-regular files
[[ -f "$file" ]] || continue
# Only check Python files
[[ "$file" == *.py ]] || continue
# Only inspect the header (first 20 lines)
if ! head -n 1 "$file" | grep -Eqi "# Copyright.*${CURRENT_YEAR}"; then
echo "ERROR: $file does not contain a ${CURRENT_YEAR} copyright notice in the header"
FAIL=1
fi
done
if [[ "$FAIL" -ne 0 ]]; then
exit 1
fi