Skip to content

Commit 512dc07

Browse files
authored
Add newline file
1 parent b43b3aa commit 512dc07

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

.github/workflows/newlines.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Check for Newline at End of Files
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
- reopened
9+
10+
jobs:
11+
check-newlines:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v2
17+
18+
- name: Check for missing newlines
19+
run: |
20+
files=$(git ls-files)
21+
22+
newline_error=0
23+
24+
for file in $files; do
25+
if file --mime "$file" | grep -q "binary"; then
26+
#echo "Skipping binary file: $file"
27+
continue
28+
fi
29+
30+
last_char=$(tail -c 1 "$file" | xxd -p)
31+
if [[ "$last_char" != "0a" ]]; then
32+
echo "File $file does not end with a newline!"
33+
newline_error=1
34+
fi
35+
done
36+
37+
if [[ $newline_error -eq 1 ]]; then
38+
echo "One or more files do not end with a newline."
39+
exit 1
40+
else
41+
echo "All files end with a newline."
42+
fi

0 commit comments

Comments
 (0)