@@ -13,38 +13,73 @@ jobs:
13
13
check-whitespace :
14
14
runs-on : ubuntu-latest
15
15
steps :
16
- - uses : actions/checkout@v2
16
+ - uses : actions/checkout@v3
17
17
with :
18
18
fetch-depth : 0
19
19
20
20
- name : git log --check
21
21
id : check_out
22
22
run : |
23
- log=
23
+ baseSha=${{github.event.pull_request.base.sha}}
24
+ problems=()
24
25
commit=
25
- while read dash etc
26
+ commitText=
27
+ commitTextmd=
28
+ goodparent=
29
+ while read dash sha etc
26
30
do
27
31
case "${dash}" in
28
32
"---")
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}"
30
40
;;
31
41
"")
32
42
;;
33
43
*)
34
44
if test -n "${commit}"
35
45
then
36
- log="${log}\n${commit}"
46
+ problems+=("1) --- ${commitTextmd}")
37
47
echo ""
38
- echo "--- ${commit}"
48
+ echo "--- ${commitText}"
49
+ commit=
39
50
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}"
43
61
;;
44
62
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 }..)
46
64
47
- if test -n "${log}"
65
+ if test ${#problems[*]} -gt 0
48
66
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
+
49
84
exit 2
50
85
fi
0 commit comments