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 <chris@webstech.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Chris. Webster committed Dec 20, 2022 at 00:35 UTC 288e3c4e3b54b9712c10b6cee51c908664471393
1 file changed +28 -9
.github/workflows/check-whitespace.yml
+28 -9
@@ -20,31 +20,50 @@ jobs:
20 - name: git log --check
21 id: check_out
22 run: |
23 - log=
23 + problems=()
24 commit=
25 - while read dash etc
25 + commitText=
26 + lastcommit=
27 + while read dash sha etc
28 do
29 case "${dash}" in
30 "---")
29 - commit="${etc}"
31 + if test -z "${commit}"
32 + then
33 + lastcommit=${sha}
34 + fi
35 + commit="${sha}"
36 + commitText="${sha} ${etc}"
37 ;;
38 "")
39 ;;
40 *)
41 if test -n "${commit}"
42 then
36 - log="${log}\n${commit}"
43 + problems+=("" "--- ${commitText}")
44 echo ""
38 - echo "--- ${commit}"
45 + echo "--- ${commitText}"
46 + commit=
47 fi
40 - commit=
41 - log="${log}\n${dash} ${etc}"
42 - echo "${dash} ${etc}"
48 + problems+=("${dash} ${sha} ${etc}")
49 + echo "${problems[-1]}"
50 ;;
51 esac
52 done <<< $(git log --check --pretty=format:"---% h% s" ${{github.event.pull_request.base.sha}}..)
53
47 - if test -n "${log}"
54 + if test ${#problems[*]} -gt 0
55 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 +
68 exit 2
69 fi