@@ -13,38 +13,73 @@ jobs:
1313 check-whitespace :
1414 runs-on : ubuntu-latest
1515 steps :
16- - uses : actions/checkout@v2
16+ - uses : actions/checkout@v3
1717 with :
1818 fetch-depth : 0
1919
2020 - name : git log --check
2121 id : check_out
2222 run : |
23- log=
23+ baseSha=${{github.event.pull_request.base.sha}}
24+ problems=()
2425 commit=
25- while read dash etc
26+ commitText=
27+ commitTextmd=
28+ goodparent=
29+ while read dash sha etc
2630 do
2731 case "${dash}" in
2832 "---")
29- commit="${etc}"
33+ if test -z "${commit}"
34+ then
35+ goodparent=${sha}
36+ fi
37+ commit="${sha}"
38+ commitText="${sha} ${etc}"
39+ commitTextmd="[${sha}](https://github.com/${{ github.repository }}/commit/${sha}) ${etc}"
3040 ;;
3141 "")
3242 ;;
3343 *)
3444 if test -n "${commit}"
3545 then
36- log="${log}\n${commit}"
46+ problems+=("1) --- ${commitTextmd}")
3747 echo ""
38- echo "--- ${commit}"
48+ echo "--- ${commitText}"
49+ commit=
3950 fi
40- commit=
41- log="${log}\n${dash} ${etc}"
42- echo "${dash} ${etc}"
51+ case "${dash}" in
52+ *:[1-9]*:) # contains file and line number information
53+ dashend=${dash#*:}
54+ problems+=("[${dash}](https://github.com/${{ github.repository }}/blob/${{github.event.pull_request.head.ref}}/${dash%%:*}#L${dashend%:}) ${sha} ${etc}")
55+ ;;
56+ *)
57+ problems+=("\`${dash} ${sha} ${etc}\`")
58+ ;;
59+ esac
60+ echo "${dash} ${sha} ${etc}"
4361 ;;
4462 esac
45- done <<< $(git log --check --pretty=format:"---% h% s" ${{github.event.pull_request.base.sha} }..)
63+ done <<< $(git log --check --pretty=format:"---% h% s" ${baseSha }..)
4664
47- if test -n "${log}"
65+ if test ${#problems[*]} -gt 0
4866 then
67+ if test -z "${commit}"
68+ then
69+ goodparent=${baseSha: 0:7}
70+ fi
71+ echo "🛑 Please review the Summary output for further information."
72+ echo "### :x: A whitespace issue was found in one or more of the commits." >$GITHUB_STEP_SUMMARY
73+ echo "" >>$GITHUB_STEP_SUMMARY
74+ echo "Run these commands to correct the problem:" >>$GITHUB_STEP_SUMMARY
75+ echo "1. \`git rebase --whitespace=fix ${goodparent}\`" >>$GITHUB_STEP_SUMMARY
76+ echo "1. \`git push --force\`" >>$GITHUB_STEP_SUMMARY
77+ echo " " >>$GITHUB_STEP_SUMMARY
78+ echo "Errors:" >>$GITHUB_STEP_SUMMARY
79+ for i in "${problems[@]}"
80+ do
81+ echo "${i}" >>$GITHUB_STEP_SUMMARY
82+ done
83+
4984 exit 2
5085 fi
0 commit comments