-
Notifications
You must be signed in to change notification settings - Fork 3.1k
88 lines (80 loc) · 3.13 KB
/
copyright_check.yml
File metadata and controls
88 lines (80 loc) · 3.13 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: Copyright Check
on:
pull_request:
branches:
- master
- 'releases/**'
permissions:
contents: read
jobs:
check-copyright:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
- name: Get changed files
id: changed-files
run: |
# Download the PR diff directly from GitHub
curl -L "${{ github.server_url }}/${{ github.repository }}/pull/${{ github.event.pull_request.number }}.diff" -o pr.diff
# Extract changed file names from the diff
# Lines starting with +++ indicate new/modified files (skip /dev/null for deleted files)
grep '^+++' pr.diff | sed 's|^+++ b/||' | grep -v '/dev/null' > changed_files.txt
- name: Check copyright headers
id: check
run: |
python .github/scripts/check_copyright.py changed_files.txt
continue-on-error: true
- name: Upload diff artifact
if: steps.check.outcome == 'failure'
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
with:
name: copyright-fixes
path: copyright_fixes.diff
retention-days: 7
- name: Fail if copyright issues found
if: steps.check.outcome == 'failure'
run: |
echo "## ⚠️ Copyright Header Issues Found"
echo ""
echo "Found issues in the following files:"
cat copyright_issues.txt
echo ""
echo "### How to fix"
echo ""
echo "**Option 1: Download and apply the auto-generated patch**"
echo "1. Go to the 'Summary' page of this workflow run"
echo "2. Scroll down to the 'Artifacts' section"
echo "3. Download the 'copyright-fixes' artifact"
echo "4. Extract copyright_fixes.diff from the zip"
echo "5. Apply it: patch -p1 < copyright_fixes.diff"
echo "6. Commit and push the changes"
echo ""
echo "> **Note:** the patch is generated automatically and may be incorrect in"
echo "> edge cases (e.g. when the file has an unusual structure at the top)."
echo "> If the patch does not apply cleanly or produces unexpected results,"
echo "> please proceed with Option 2."
echo ""
echo "**Option 2: Fix manually using the reference headers**"
echo ""
echo "Align the top of each affected file with the reference header below."
echo ""
echo "**Python (.py):**"
echo "\`\`\`"
echo "# Copyright (C) 2018-$(date +%Y) Intel Corporation"
echo "# SPDX-License-Identifier: Apache-2.0"
echo ""
echo "\`\`\`"
echo "**C++ (.cpp / .hpp / .h):**"
echo "\`\`\`"
echo "// Copyright (C) 2018-$(date +%Y) Intel Corporation"
echo "// SPDX-License-Identifier: Apache-2.0"
echo "//"
echo ""
echo "\`\`\`"
echo ""
echo "**Diff for reference:**"
echo ""
cat copyright_fixes.diff
echo ""
exit 1