Skip to content

Commit 288e3c4

Browse files
webstechgitster
authored andcommitted
ci (check-whitespace): suggest fixes for errors
Make the errors more visible by adding them to the job summary and display the git commands that will usually fix the problem. Signed-off-by: Chris. Webster <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c48035d commit 288e3c4

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

.github/workflows/check-whitespace.yml

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,50 @@ jobs:
2020
- name: git log --check
2121
id: check_out
2222
run: |
23-
log=
23+
problems=()
2424
commit=
25-
while read dash etc
25+
commitText=
26+
lastcommit=
27+
while read dash sha etc
2628
do
2729
case "${dash}" in
2830
"---")
29-
commit="${etc}"
31+
if test -z "${commit}"
32+
then
33+
lastcommit=${sha}
34+
fi
35+
commit="${sha}"
36+
commitText="${sha} ${etc}"
3037
;;
3138
"")
3239
;;
3340
*)
3441
if test -n "${commit}"
3542
then
36-
log="${log}\n${commit}"
43+
problems+=("" "--- ${commitText}")
3744
echo ""
38-
echo "--- ${commit}"
45+
echo "--- ${commitText}"
46+
commit=
3947
fi
40-
commit=
41-
log="${log}\n${dash} ${etc}"
42-
echo "${dash} ${etc}"
48+
problems+=("${dash} ${sha} ${etc}")
49+
echo "${problems[-1]}"
4350
;;
4451
esac
4552
done <<< $(git log --check --pretty=format:"---% h% s" ${{github.event.pull_request.base.sha}}..)
4653
47-
if test -n "${log}"
54+
if test ${#problems[*]} -gt 0
4855
then
56+
if test -z "${commit}"
57+
then
58+
lastcommit=${{github.event.pull_request.base.sha}}
59+
fi
60+
echo "A whitespace issue was found in one or more of the commits." >$GITHUB_STEP_SUMMARY
61+
echo "" >>$GITHUB_STEP_SUMMARY
62+
echo "Run \`git rebase --whitespace=fix ${lastcommit}\` and \`git push --force\` to correct the problem." >>$GITHUB_STEP_SUMMARY
63+
for i in "${problems[@]}"
64+
do
65+
echo "${i}" >>$GITHUB_STEP_SUMMARY
66+
done
67+
4968
exit 2
5069
fi

0 commit comments

Comments
 (0)