File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Check for Windows Line Endings
2+
3+ on :
4+ pull_request :
5+ branches : ['*'] # Trigger on all pull requests to any branch
6+
7+ jobs :
8+ check-line-endings :
9+ runs-on : ubuntu-latest
10+
11+ steps :
12+ - name : Checkout code
13+ uses : actions/checkout@v4
14+ with :
15+ fetch-depth : 0 # Fetch all history to compare changes
16+
17+ - name : Check for Windows line endings (CRLF)
18+ run : |
19+ # Get the list of changed files in the PR
20+ CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}..HEAD)
21+
22+ # Flag to track if CRLF is found
23+ CRLF_FOUND=false
24+
25+ # Loop through each changed file
26+ for FILE in $CHANGED_FILES; do
27+ # Check if the file exists and is a text file
28+ if [ -f "$FILE" ] && file "$FILE" | grep -q "text"; then
29+ # Check for CRLF line endings
30+ if grep -UP '\r$' "$FILE"; then
31+ echo "Error: Windows line endings (CRLF) detected in $FILE"
32+ CRLF_FOUND=true
33+ fi
34+ fi
35+ done
36+
37+ # Exit with error if CRLF was found
38+ if [ "$CRLF_FOUND" = true ]; then
39+ exit 1
40+ fi
You can’t perform that action at this time.
0 commit comments