@@ -10,16 +10,31 @@ jobs:
1010 runs-on : ubuntu-latest
1111 steps :
1212 - uses : actions/checkout@v4
13+ with :
14+ fetch-depth : 0
1315
1416 - name : Check for License Headers
17+ env :
18+ BASE_REF : ${{ github.base_ref }}
19+ EVENT_NAME : ${{ github.event_name }}
1520 run : |
1621 failed=0
17- # Find files: .sh, .go, .swift, .py
18- # Exclude hidden directories/files (like inside .git)
19- files=$(find . -type f \( -name "*.sh" -o -name "*.go" -o -name "*.swift" -o -name "*.py" -o -name "README.md" \) -not -path '*/.*')
22+ error_report_file=$(mktemp)
23+
24+ if [ "$EVENT_NAME" == "pull_request" ]; then
25+ git fetch origin "$BASE_REF"
26+ files=$(git diff --name-only "origin/$BASE_REF" HEAD | grep -E '\.(sh|go|swift|py)|README\.md$' || true)
27+ else
28+ # Find files: .sh, .go, .swift, .py
29+ # Exclude hidden directories/files (like inside .git)
30+ files=$(find . -type f \( -name "*.sh" -o -name "*.go" -o -name "*.swift" -o -name "*.py" -o -name "README.md" \) -not -path '*/.*')
31+ fi
2032
2133 for file in $files; do
22- if [ "$file" = "./README.md" ]; then
34+ if [ ! -f "$file" ]; then
35+ continue
36+ fi
37+ if [ "$file" = "./README.md" ] || [ "$file" = "README.md" ]; then
2338 continue
2439 fi
2540
2843 # Requirement 1: A line with both "Copyright" and "Jamf"
2944 # We grep for Copyright, then pipe to grep for Jamf to ensure they are on the same line.
3045 if ! grep "Copyright" "$file" | grep -q "Jamf"; then
31- echo "::error file=$file::Missing 'Copyright' and 'Jamf' on the same line."
32- echo "File: ${file}"
46+ msg="Missing 'Copyright' and 'Jamf' on the same line."
47+ echo "::error file=$file::$msg"
48+ echo "- $file: $msg" >> "$error_report_file"
3349 missing_reqs=1
3450 fi
3551
@@ -39,15 +55,17 @@ jobs:
3955 else
4056 # Requirement 2: Specific license string
4157 if ! grep -Fq "This work is licensed under the terms of the Jamf Source Available License" "$file"; then
42- echo "::error file=$file::Missing 'This work is licensed under the terms of the Jamf Source Available License'"
43- echo "File: ${file}"
58+ msg="Missing 'This work is licensed under the terms of the Jamf Source Available License'"
59+ echo "::error file=$file::$msg"
60+ echo "- $file: $msg" >> "$error_report_file"
4461 missing_reqs=1
4562 fi
4663
4764 # Requirement 3: License URL
4865 if ! grep -Fq "https://github.com/jamf/scripts/blob/main/LICENCE.md" "$file"; then
49- echo "::error file=$file::Missing 'https://github.com/jamf/scripts/blob/main/LICENCE.md'"
50- echo "File: ${file}"
66+ msg="Missing 'https://github.com/jamf/scripts/blob/main/LICENCE.md'"
67+ echo "::error file=$file::$msg"
68+ echo "- $file: $msg" >> "$error_report_file"
5169 missing_reqs=1
5270 fi
5371 fi
5876 done
5977
6078 if [ $failed -eq 1 ]; then
61- echo "One or more files are missing required license headers."
79+ echo "---------------------------------------------------"
80+ echo "License Check Summary: Failed Files"
81+ echo "---------------------------------------------------"
82+ cat "$error_report_file"
83+ echo "---------------------------------------------------"
84+ rm "$error_report_file"
6285 exit 1
6386 else
6487 echo "All scanned files contain the required license headers."
0 commit comments