ci: make the whitespace report optional

The `check-whitespace` CI job generates a formatted output file containing whitespace error information. As not all CI providers support rendering a formatted summary, make its generation optional. 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 9bef98096c1a58ec0f0e793a282374b50a43eaab
1 file changed +33 -12
ci/check-whitespace.sh
+33 -12
@@ -1,9 +1,20 @@
1 #!/usr/bin/env bash
2 +#
3 +# Check that commits after a specified point do not contain new or modified
4 +# lines with whitespace errors. An optional formatted summary can be generated
5 +# by providing an output file path and url as additional arguments.
6 +#
7
8 baseCommit=$1
9 outputFile=$2
10 url=$3
11
12 +if test "$#" -ne 1 && test "$#" -ne 3
13 +then
14 + echo "USAGE: $0 <BASE_COMMIT> [<OUTPUT_FILE> <URL>]"
15 + exit 1
16 +fi
17 +
18 problems=()
19 commit=
20 commitText=
@@ -56,19 +67,29 @@ then
67 goodParent=${baseCommit: 0:7}
68 fi
69
59 - echo "🛑 Please review the Summary output for further information."
60 - echo "### :x: A whitespace issue was found in one or more of the commits." >"$outputFile"
61 - echo "" >>"$outputFile"
62 - echo "Run these commands to correct the problem:" >>"$outputFile"
63 - echo "1. \`git rebase --whitespace=fix ${goodParent}\`" >>"$outputFile"
64 - echo "1. \`git push --force\`" >>"$outputFile"
65 - echo " " >>"$outputFile"
66 - echo "Errors:" >>"$outputFile"
70 + echo "A whitespace issue was found in onen of more of the commits."
71 + echo "Run the following command to resolve whitespace issues:"
72 + echo "git rebase --whitespace=fix ${goodParent}"
73 +
74 + # If target output file is provided, write formatted output.
75 + if test -n "$outputFile"
76 + then
77 + echo "🛑 Please review the Summary output for further information."
78 + (
79 + echo "### :x: A whitespace issue was found in one or more of the commits."
80 + echo ""
81 + echo "Run these commands to correct the problem:"
82 + echo "1. \`git rebase --whitespace=fix ${goodParent}\`"
83 + echo "1. \`git push --force\`"
84 + echo ""
85 + echo "Errors:"
86
68 - for i in "${problems[@]}"
69 - do
70 - echo "${i}" >>"$outputFile"
71 - done
87 + for i in "${problems[@]}"
88 + do
89 + echo "${i}"
90 + done
91 + ) >"$outputFile"
92 + fi
93
94 exit 2
95 fi