-
Notifications
You must be signed in to change notification settings - Fork 195
79 lines (70 loc) · 2.07 KB
/
whitespace.yml
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
name: Whitespace Check
on:
pull_request:
push:
branches:
- master
jobs:
whitespace-check:
runs-on: ubuntu-latest
steps:
- name: Set commit count
shell: bash
run: echo "COMMIT_DEPTH=$((1 + ${{ github.event.pull_request.commits }}))" >> $GITHUB_ENV
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: ${{ env.COMMIT_DEPTH }}
# TODO: reintroduce this check when the library is cleaned up
# - name: Check for trailing whitespace
# run: |
# TRAILING_WHITESPACE=$(git grep -l -z -E '\s+$' | xargs -0 sed -n '/\s$/p')
# if [ -n "$TRAILING_WHITESPACE" ]; then
# echo "Trailing whitespace found. Please fix with:\
# bash ./etc/fix_trailing_whitespace.sh"
# exit 1
# fi
- name: Check that every file ends correctly
run: |
while IFS= read -r file; do
# Check if the file is a regular file
if [ -f "$file" ]; then
if [ -n "$(tail -c 1 "$file")" ]; then
echo "File $file does not end with a newline. Please fix with:\
bash ./etc/fix_end_newlines.sh"
exit 1
fi
fi
done < <(git ls-files)
# Get the repo with the commits(+1) in the series.
# Process `git log --check` output to extract just the check errors.
- name: git log --check
id: check_out
run: |
log=
commit=
while read dash etc
do
case "${dash}" in
"---")
commit="${etc}"
;;
"")
;;
*)
if test -n "${commit}"
then
log="${log}\n${commit}"
echo ""
echo "--- ${commit}"
fi
commit=
log="${log}\n${dash} ${etc}"
echo "${dash} ${etc}"
;;
esac
done <<< $(git log --check --pretty=format:"---% h% s" -${{github.event.pull_request.commits}})
if [ -n "${log}" ]; then
echo "${log}" >> $GITHUB_OUTPUT
exit 2
fi