github-ci: fix link to whitespace error
When the `check-whitespace` CI job detects whitespace errors, a formatted summary of the issue is generated. This summary contains links to the commits and blobs responsible for the whitespace errors. The generated links for blobs do not work and result in a 404. Instead of using the reference name in the link, use the commit ID directly. This fixes the broken link and also helps enable future generalization of the script for other CI providers by removing one of the GitHub specific CI variables used. Signed-off-by: Justin Tobler <jltobler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Justin Tobler committed
May 3, 2024 at 12:21 UTC
ecaacbc7a278549f31d6f77d729c49fa60eec734
1 file changed
+12
-11
.github/workflows/check-whitespace.yml
+12
-11
@@ -31,14 +31,15 @@ jobs:
31
commit=
32
commitText=
33
commitTextmd=
34
- goodparent=
34
+ goodParent=
35
while read dash sha etc
36
do
37
case "${dash}" in
38
- "---")
39
- if test -z "${commit}"
38
+ "---") # Line contains commit information.
39
+ if test -z "${goodParent}"
40
then
41
- goodparent=${sha}
41
+ # Assume the commit has no whitespace errors until detected otherwise.
42
+ goodParent=${sha}
43
fi
44
commit="${sha}"
45
commitText="${sha} ${etc}"
@@ -46,18 +47,18 @@ jobs:
47
;;
48
"")
49
;;
49
- *)
50
- if test -n "${commit}"
50
+ *) # Line contains whitespace error information for current commit.
51
+ if test -n "${goodParent}"
52
then
53
problems+=("1) --- ${commitTextmd}")
54
echo ""
55
echo "--- ${commitText}"
55
- commit=
56
+ goodParent=
57
fi
58
case "${dash}" in
59
*:[1-9]*:) # contains file and line number information
60
dashend=${dash#*:}
60
- problems+=("[${dash}](https://github.com/${{ github.repository }}/blob/${{github.event.pull_request.head.ref}}/${dash%%:*}#L${dashend%:}) ${sha} ${etc}")
61
+ problems+=("[${dash}](https://github.com/${{ github.repository }}/blob/${commit}/${dash%%:*}#L${dashend%:}) ${sha} ${etc}")
62
;;
63
*)
64
problems+=("\`${dash} ${sha} ${etc}\`")
@@ -70,15 +71,15 @@ jobs:
71
72
if test ${#problems[*]} -gt 0
73
then
73
- if test -z "${commit}"
74
+ if test -z "${goodParent}"
75
then
75
- goodparent=${baseSha: 0:7}
76
+ goodParent=${baseSha: 0:7}
77
fi
78
echo "🛑 Please review the Summary output for further information."
79
echo "### :x: A whitespace issue was found in one or more of the commits." >$GITHUB_STEP_SUMMARY
80
echo "" >>$GITHUB_STEP_SUMMARY
81
echo "Run these commands to correct the problem:" >>$GITHUB_STEP_SUMMARY
81
- echo "1. \`git rebase --whitespace=fix ${goodparent}\`" >>$GITHUB_STEP_SUMMARY
82
+ echo "1. \`git rebase --whitespace=fix ${goodParent}\`" >>$GITHUB_STEP_SUMMARY
83
echo "1. \`git push --force\`" >>$GITHUB_STEP_SUMMARY
84
echo " " >>$GITHUB_STEP_SUMMARY
85
echo "Errors:" >>$GITHUB_STEP_SUMMARY