* [PATCH v2 1/5] ci: pre-collapse GitLab CI sections
2024-05-02 19:38 ` [PATCH v2 0/5] Add GitLab CI to check for whitespace errors Justin Tobler
@ 2024-05-02 19:38 ` Justin Tobler
2024-05-02 19:38 ` [PATCH v2 2/5] github-ci: fix link to whitespace error Justin Tobler
` (5 subsequent siblings)
6 siblings, 0 replies; 42+ messages in thread
From: Justin Tobler @ 2024-05-02 19:38 UTC (permalink / raw)
To: git; +Cc: Justin Tobler
Sections of CI output defined by `begin_group()` and `end_group()` are
expanded in GitLab pipelines by default. This can make CI job output
rather noisy and harder to navigate. Update the behavior for GitLab
pipelines to now collapse sections by default.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
ci/lib.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ci/lib.sh b/ci/lib.sh
index 0a73fc7bd1..02e5e058dd 100755
--- a/ci/lib.sh
+++ b/ci/lib.sh
@@ -18,7 +18,7 @@ elif test true = "$GITLAB_CI"
then
begin_group () {
need_to_end_group=t
- printf "\e[0Ksection_start:$(date +%s):$(echo "$1" | tr ' ' _)\r\e[0K$1\n"
+ printf "\e[0Ksection_start:$(date +%s):$(echo "$1" | tr ' ' _)[collapsed=true]\r\e[0K$1\n"
trap "end_group '$1'" EXIT
set -x
}
--
2.45.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 2/5] github-ci: fix link to whitespace error
2024-05-02 19:38 ` [PATCH v2 0/5] Add GitLab CI to check for whitespace errors Justin Tobler
2024-05-02 19:38 ` [PATCH v2 1/5] ci: pre-collapse GitLab CI sections Justin Tobler
@ 2024-05-02 19:38 ` Justin Tobler
2024-05-02 19:38 ` [PATCH v2 3/5] ci: separate whitespace check script Justin Tobler
` (4 subsequent siblings)
6 siblings, 0 replies; 42+ messages in thread
From: Justin Tobler @ 2024-05-02 19:38 UTC (permalink / raw)
To: git; +Cc: Justin Tobler
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>
---
.github/workflows/check-whitespace.yml | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/.github/workflows/check-whitespace.yml b/.github/workflows/check-whitespace.yml
index a241a63428..a3a6913ecc 100644
--- a/.github/workflows/check-whitespace.yml
+++ b/.github/workflows/check-whitespace.yml
@@ -31,14 +31,15 @@ jobs:
commit=
commitText=
commitTextmd=
- goodparent=
+ goodParent=
while read dash sha etc
do
case "${dash}" in
- "---")
- if test -z "${commit}"
+ "---") # Line contains commit information.
+ if test -z "${goodParent}"
then
- goodparent=${sha}
+ # Assume the commit has no whitespace errors until detected otherwise.
+ goodParent=${sha}
fi
commit="${sha}"
commitText="${sha} ${etc}"
@@ -46,18 +47,18 @@ jobs:
;;
"")
;;
- *)
- if test -n "${commit}"
+ *) # Line contains whitespace error information for current commit.
+ if test -n "${goodParent}"
then
problems+=("1) --- ${commitTextmd}")
echo ""
echo "--- ${commitText}"
- commit=
+ goodParent=
fi
case "${dash}" in
*:[1-9]*:) # contains file and line number information
dashend=${dash#*:}
- problems+=("[${dash}](https://github.com/${{ github.repository }}/blob/${{github.event.pull_request.head.ref}}/${dash%%:*}#L${dashend%:}) ${sha} ${etc}")
+ problems+=("[${dash}](https://github.com/${{ github.repository }}/blob/${commit}/${dash%%:*}#L${dashend%:}) ${sha} ${etc}")
;;
*)
problems+=("\`${dash} ${sha} ${etc}\`")
@@ -70,15 +71,15 @@ jobs:
if test ${#problems[*]} -gt 0
then
- if test -z "${commit}"
+ if test -z "${goodParent}"
then
- goodparent=${baseSha: 0:7}
+ goodParent=${baseSha: 0:7}
fi
echo "🛑 Please review the Summary output for further information."
echo "### :x: A whitespace issue was found in one or more of the commits." >$GITHUB_STEP_SUMMARY
echo "" >>$GITHUB_STEP_SUMMARY
echo "Run these commands to correct the problem:" >>$GITHUB_STEP_SUMMARY
- echo "1. \`git rebase --whitespace=fix ${goodparent}\`" >>$GITHUB_STEP_SUMMARY
+ echo "1. \`git rebase --whitespace=fix ${goodParent}\`" >>$GITHUB_STEP_SUMMARY
echo "1. \`git push --force\`" >>$GITHUB_STEP_SUMMARY
echo " " >>$GITHUB_STEP_SUMMARY
echo "Errors:" >>$GITHUB_STEP_SUMMARY
--
2.45.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v2 3/5] ci: separate whitespace check script
2024-05-02 19:38 ` [PATCH v2 0/5] Add GitLab CI to check for whitespace errors Justin Tobler
2024-05-02 19:38 ` [PATCH v2 1/5] ci: pre-collapse GitLab CI sections Justin Tobler
2024-05-02 19:38 ` [PATCH v2 2/5] github-ci: fix link to whitespace error Justin Tobler
@ 2024-05-02 19:38 ` Justin Tobler
2024-05-03 6:56 ` Patrick Steinhardt
2024-05-02 19:38 ` [PATCH v2 4/5] ci: make the whitespace report optional Justin Tobler
` (3 subsequent siblings)
6 siblings, 1 reply; 42+ messages in thread
From: Justin Tobler @ 2024-05-02 19:38 UTC (permalink / raw)
To: git; +Cc: Justin Tobler, Patrick Steinhardt
The `check-whitespace` CI job is only available as a GitHub action. To
help enable this job with other CI providers, first separate the logic
performing the whitespace check into its own script. In subsequent
commits, this script is further generalized allowing its reuse.
Helped-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
.github/workflows/check-whitespace.yml | 68 ++---------------------
ci/check-whitespace.sh | 74 ++++++++++++++++++++++++++
2 files changed, 78 insertions(+), 64 deletions(-)
create mode 100755 ci/check-whitespace.sh
diff --git a/.github/workflows/check-whitespace.yml b/.github/workflows/check-whitespace.yml
index a3a6913ecc..d0a78fc426 100644
--- a/.github/workflows/check-whitespace.yml
+++ b/.github/workflows/check-whitespace.yml
@@ -26,67 +26,7 @@ jobs:
- name: git log --check
id: check_out
run: |
- baseSha=${{github.event.pull_request.base.sha}}
- problems=()
- commit=
- commitText=
- commitTextmd=
- goodParent=
- while read dash sha etc
- do
- case "${dash}" in
- "---") # Line contains commit information.
- if test -z "${goodParent}"
- then
- # Assume the commit has no whitespace errors until detected otherwise.
- goodParent=${sha}
- fi
- commit="${sha}"
- commitText="${sha} ${etc}"
- commitTextmd="[${sha}](https://github.com/${{ github.repository }}/commit/${sha}) ${etc}"
- ;;
- "")
- ;;
- *) # Line contains whitespace error information for current commit.
- if test -n "${goodParent}"
- then
- problems+=("1) --- ${commitTextmd}")
- echo ""
- echo "--- ${commitText}"
- goodParent=
- fi
- case "${dash}" in
- *:[1-9]*:) # contains file and line number information
- dashend=${dash#*:}
- problems+=("[${dash}](https://github.com/${{ github.repository }}/blob/${commit}/${dash%%:*}#L${dashend%:}) ${sha} ${etc}")
- ;;
- *)
- problems+=("\`${dash} ${sha} ${etc}\`")
- ;;
- esac
- echo "${dash} ${sha} ${etc}"
- ;;
- esac
- done <<< $(git log --check --pretty=format:"---% h% s" ${baseSha}..)
-
- if test ${#problems[*]} -gt 0
- then
- if test -z "${goodParent}"
- then
- goodParent=${baseSha: 0:7}
- fi
- echo "🛑 Please review the Summary output for further information."
- echo "### :x: A whitespace issue was found in one or more of the commits." >$GITHUB_STEP_SUMMARY
- echo "" >>$GITHUB_STEP_SUMMARY
- echo "Run these commands to correct the problem:" >>$GITHUB_STEP_SUMMARY
- echo "1. \`git rebase --whitespace=fix ${goodParent}\`" >>$GITHUB_STEP_SUMMARY
- echo "1. \`git push --force\`" >>$GITHUB_STEP_SUMMARY
- echo " " >>$GITHUB_STEP_SUMMARY
- echo "Errors:" >>$GITHUB_STEP_SUMMARY
- for i in "${problems[@]}"
- do
- echo "${i}" >>$GITHUB_STEP_SUMMARY
- done
-
- exit 2
- fi
+ ./ci/check-whitespace.sh \
+ "${{github.event.pull_request.base.sha}}" \
+ "$GITHUB_STEP_SUMMARY" \
+ "https://github.com/${{github.repository}}"
diff --git a/ci/check-whitespace.sh b/ci/check-whitespace.sh
new file mode 100755
index 0000000000..f57d1ff5f0
--- /dev/null
+++ b/ci/check-whitespace.sh
@@ -0,0 +1,74 @@
+#!/bin/bash
+
+baseCommit=$1
+outputFile=$2
+url=$3
+
+problems=()
+commit=
+commitText=
+commitTextmd=
+goodParent=
+
+while read dash sha etc
+do
+ case "${dash}" in
+ "---") # Line contains commit information.
+ if test -z "${goodParent}"
+ then
+ # Assume the commit has no whitespace errors until detected otherwise.
+ goodParent=${sha}
+ fi
+
+ commit="${sha}"
+ commitText="${sha} ${etc}"
+ commitTextmd="[${sha}](${url}/commit/${sha}) ${etc}"
+ ;;
+ "")
+ ;;
+ *) # Line contains whitespace error information for current commit.
+ if test -n "${goodParent}"
+ then
+ problems+=("1) --- ${commitTextmd}")
+ echo ""
+ echo "--- ${commitText}"
+ goodParent=
+ fi
+
+ case "${dash}" in
+ *:[1-9]*:) # contains file and line number information
+ dashend=${dash#*:}
+ problems+=("[${dash}](${url}/blob/${commit}/${dash%%:*}#L${dashend%:}) ${sha} ${etc}")
+ ;;
+ *)
+ problems+=("\`${dash} ${sha} ${etc}\`")
+ ;;
+ esac
+ echo "${dash} ${sha} ${etc}"
+ ;;
+ esac
+done <<< "$(git log --check --pretty=format:"---% h% s" "${baseCommit}"..)"
+
+if test ${#problems[*]} -gt 0
+then
+ if test -z "${goodParent}"
+ then
+ goodParent=${baseCommit: 0:7}
+ fi
+
+ echo "🛑 Please review the Summary output for further information."
+ echo "### :x: A whitespace issue was found in one or more of the commits." >"$outputFile"
+ echo "" >>"$outputFile"
+ echo "Run these commands to correct the problem:" >>"$outputFile"
+ echo "1. \`git rebase --whitespace=fix ${goodParent}\`" >>"$outputFile"
+ echo "1. \`git push --force\`" >>"$outputFile"
+ echo " " >>"$outputFile"
+ echo "Errors:" >>"$outputFile"
+
+ for i in "${problems[@]}"
+ do
+ echo "${i}" >>"$outputFile"
+ done
+
+ exit 2
+fi
--
2.45.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* Re: [PATCH v2 3/5] ci: separate whitespace check script
2024-05-02 19:38 ` [PATCH v2 3/5] ci: separate whitespace check script Justin Tobler
@ 2024-05-03 6:56 ` Patrick Steinhardt
2024-05-03 15:27 ` Justin Tobler
0 siblings, 1 reply; 42+ messages in thread
From: Patrick Steinhardt @ 2024-05-03 6:56 UTC (permalink / raw)
To: Justin Tobler; +Cc: git
[-- Attachment #1: Type: text/plain, Size: 1391 bytes --]
On Thu, May 02, 2024 at 02:38:37PM -0500, Justin Tobler wrote:
> The `check-whitespace` CI job is only available as a GitHub action. To
> help enable this job with other CI providers, first separate the logic
> performing the whitespace check into its own script. In subsequent
> commits, this script is further generalized allowing its reuse.
>
> Helped-by: Patrick Steinhardt <ps@pks.im>
> Signed-off-by: Justin Tobler <jltobler@gmail.com>
> ---
[snip]
> diff --git a/ci/check-whitespace.sh b/ci/check-whitespace.sh
> new file mode 100755
> index 0000000000..f57d1ff5f0
> --- /dev/null
> +++ b/ci/check-whitespace.sh
> @@ -0,0 +1,74 @@
> +#!/bin/bash
This needs to be either "/bin/sh" or "/usr/bin/env bash".
> +baseCommit=$1
> +outputFile=$2
I think the script would be more flexible if we just didn't have an
output file in the first place and handle redirection of the output at
the caller's side. That for example also allows you to easily append to
a potential output file.
Edit: I see you change this in the next patch, so this is okay.
> +url=$3
We should check that we got 3 arguments in the first place.
Edit: I see that you add those checks in the next commit, but it does
leave the reader wondering at this point. Maybe we should have a strict
check here and then loosen it in the next commit where you make it
optional.
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 3/5] ci: separate whitespace check script
2024-05-03 6:56 ` Patrick Steinhardt
@ 2024-05-03 15:27 ` Justin Tobler
2024-05-03 16:49 ` Junio C Hamano
0 siblings, 1 reply; 42+ messages in thread
From: Justin Tobler @ 2024-05-03 15:27 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git
On 24/05/03 08:56AM, Patrick Steinhardt wrote:
> On Thu, May 02, 2024 at 02:38:37PM -0500, Justin Tobler wrote:
> > The `check-whitespace` CI job is only available as a GitHub action. To
> > help enable this job with other CI providers, first separate the logic
> > performing the whitespace check into its own script. In subsequent
> > commits, this script is further generalized allowing its reuse.
> >
> > Helped-by: Patrick Steinhardt <ps@pks.im>
> > Signed-off-by: Justin Tobler <jltobler@gmail.com>
> > ---
> [snip]
> > diff --git a/ci/check-whitespace.sh b/ci/check-whitespace.sh
> > new file mode 100755
> > index 0000000000..f57d1ff5f0
> > --- /dev/null
> > +++ b/ci/check-whitespace.sh
> > @@ -0,0 +1,74 @@
> > +#!/bin/bash
>
> This needs to be either "/bin/sh" or "/usr/bin/env bash".
Since the script is using some shell specific features, I'll update this
to "/usr/bin/env bash" in the next version.
>
> > +baseCommit=$1
> > +outputFile=$2
>
> I think the script would be more flexible if we just didn't have an
> output file in the first place and handle redirection of the output at
> the caller's side. That for example also allows you to easily append to
> a potential output file.
>
> Edit: I see you change this in the next patch, so this is okay.
>
> > +url=$3
>
> We should check that we got 3 arguments in the first place.
>
> Edit: I see that you add those checks in the next commit, but it does
> leave the reader wondering at this point. Maybe we should have a strict
> check here and then loosen it in the next commit where you make it
> optional.
For this patch specifically, I was trying to really only factor out the
whitespace check into its own script and keep changes outside of that to
a minimum. The next patch focuses on all the actual script changes and I
was hoping it might be easier to review that way. :)
-Justin
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 3/5] ci: separate whitespace check script
2024-05-03 15:27 ` Justin Tobler
@ 2024-05-03 16:49 ` Junio C Hamano
2024-05-03 17:59 ` Patrick Steinhardt
0 siblings, 1 reply; 42+ messages in thread
From: Junio C Hamano @ 2024-05-03 16:49 UTC (permalink / raw)
To: Justin Tobler; +Cc: Patrick Steinhardt, git
Justin Tobler <jltobler@gmail.com> writes:
> On 24/05/03 08:56AM, Patrick Steinhardt wrote:
>> On Thu, May 02, 2024 at 02:38:37PM -0500, Justin Tobler wrote:
>> > The `check-whitespace` CI job is only available as a GitHub action. To
>> > help enable this job with other CI providers, first separate the logic
>> > performing the whitespace check into its own script. In subsequent
>> > commits, this script is further generalized allowing its reuse.
>> >
>> > Helped-by: Patrick Steinhardt <ps@pks.im>
>> > Signed-off-by: Justin Tobler <jltobler@gmail.com>
>> > ---
>> [snip]
>> > diff --git a/ci/check-whitespace.sh b/ci/check-whitespace.sh
>> > new file mode 100755
>> > index 0000000000..f57d1ff5f0
>> > --- /dev/null
>> > +++ b/ci/check-whitespace.sh
>> > @@ -0,0 +1,74 @@
>> > +#!/bin/bash
>>
>> This needs to be either "/bin/sh" or "/usr/bin/env bash".
>
> Since the script is using some shell specific features, I'll update this
> to "/usr/bin/env bash" in the next version.
This is a question to Patrick, but what makes it bad to assume
"bash" is in "/bin" when it is OK to assume that "env" is always in
"/usr/bin"?
All other comments by Patrick I found very sensible.
Thanks, both of you.
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 3/5] ci: separate whitespace check script
2024-05-03 16:49 ` Junio C Hamano
@ 2024-05-03 17:59 ` Patrick Steinhardt
2024-05-04 6:51 ` Chris Torek
0 siblings, 1 reply; 42+ messages in thread
From: Patrick Steinhardt @ 2024-05-03 17:59 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Justin Tobler, git
[-- Attachment #1: Type: text/plain, Size: 1716 bytes --]
On Fri, May 03, 2024 at 09:49:13AM -0700, Junio C Hamano wrote:
> Justin Tobler <jltobler@gmail.com> writes:
>
> > On 24/05/03 08:56AM, Patrick Steinhardt wrote:
> >> On Thu, May 02, 2024 at 02:38:37PM -0500, Justin Tobler wrote:
> >> > The `check-whitespace` CI job is only available as a GitHub action. To
> >> > help enable this job with other CI providers, first separate the logic
> >> > performing the whitespace check into its own script. In subsequent
> >> > commits, this script is further generalized allowing its reuse.
> >> >
> >> > Helped-by: Patrick Steinhardt <ps@pks.im>
> >> > Signed-off-by: Justin Tobler <jltobler@gmail.com>
> >> > ---
> >> [snip]
> >> > diff --git a/ci/check-whitespace.sh b/ci/check-whitespace.sh
> >> > new file mode 100755
> >> > index 0000000000..f57d1ff5f0
> >> > --- /dev/null
> >> > +++ b/ci/check-whitespace.sh
> >> > @@ -0,0 +1,74 @@
> >> > +#!/bin/bash
> >>
> >> This needs to be either "/bin/sh" or "/usr/bin/env bash".
> >
> > Since the script is using some shell specific features, I'll update this
> > to "/usr/bin/env bash" in the next version.
>
> This is a question to Patrick, but what makes it bad to assume
> "bash" is in "/bin" when it is OK to assume that "env" is always in
> "/usr/bin"?
My own bias. I know of systems without "/bin/bash" (NixOS), but I don't
know of any without "/usr/bin/env". But you're right, "/usr/bin/env" is
not part of POSIX and thus not really portable, either.
Ultimately I don't think there is any way to write the shebang so that
it is fully POSIX compliant. So I'd rather go with the option which is
supported on more systems, which is to the best of my knowlede env(1).
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 3/5] ci: separate whitespace check script
2024-05-03 17:59 ` Patrick Steinhardt
@ 2024-05-04 6:51 ` Chris Torek
0 siblings, 0 replies; 42+ messages in thread
From: Chris Torek @ 2024-05-04 6:51 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: Junio C Hamano, Justin Tobler, git
On Fri, May 3, 2024 at 11:27 PM Patrick Steinhardt <ps@pks.im> wrote:
>
> On Fri, May 03, 2024 at 09:49:13AM -0700, Junio C Hamano wrote:
> > This is a question to Patrick, but what makes it bad to assume
> > "bash" is in "/bin" when it is OK to assume that "env" is always in
> > "/usr/bin"?
>
> My own bias. I know of systems without "/bin/bash" (NixOS), but I don't
> know of any without "/usr/bin/env". But you're right, "/usr/bin/env" is
> not part of POSIX and thus not really portable, either.
>
> Ultimately I don't think there is any way to write the shebang so that
> it is fully POSIX compliant. So I'd rather go with the option which is
> supported on more systems, which is to the best of my knowlede env(1).
The various BSDs mostly stick bash in /usr/local/bin; some versions
of macOS did not have a /bin/bash either, as I recall, though my current
mac-laptop does.
In any case, #! /usr/bin/env <program> is pretty darn common; it's found
in a lot of Python scripts, for instance. It works well on old SunOS, on
the various BSDs, on macOS, and on Linux, provided of course that
the given <program> is installed at all.
The *most* portable method is generally to use only POSIX /bin/sh
constructs, of course. :-)
Chris
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v2 4/5] ci: make the whitespace report optional
2024-05-02 19:38 ` [PATCH v2 0/5] Add GitLab CI to check for whitespace errors Justin Tobler
` (2 preceding siblings ...)
2024-05-02 19:38 ` [PATCH v2 3/5] ci: separate whitespace check script Justin Tobler
@ 2024-05-02 19:38 ` Justin Tobler
2024-05-03 6:56 ` Patrick Steinhardt
2024-05-02 19:38 ` [PATCH v2 5/5] gitlab-ci: add whitespace error check Justin Tobler
` (2 subsequent siblings)
6 siblings, 1 reply; 42+ messages in thread
From: Justin Tobler @ 2024-05-02 19:38 UTC (permalink / raw)
To: git; +Cc: Justin Tobler
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>
---
ci/check-whitespace.sh | 45 +++++++++++++++++++++++++++++++-----------
1 file changed, 33 insertions(+), 12 deletions(-)
diff --git a/ci/check-whitespace.sh b/ci/check-whitespace.sh
index f57d1ff5f0..fabd6ecde5 100755
--- a/ci/check-whitespace.sh
+++ b/ci/check-whitespace.sh
@@ -1,9 +1,20 @@
#!/bin/bash
+#
+# Check that commits after a specified point do not contain new or modified
+# lines with whitespace errors. An optional formatted summary can be generated
+# by providing an output file path and url as additional arguments.
+#
baseCommit=$1
outputFile=$2
url=$3
+if test "$#" -eq 0 || test "$#" -gt 3
+then
+ echo "USAGE: $0 <BASE_COMMIT> [<OUTPUT_FILE> <URL>]"
+ exit 1
+fi
+
problems=()
commit=
commitText=
@@ -56,19 +67,29 @@ then
goodParent=${baseCommit: 0:7}
fi
- echo "🛑 Please review the Summary output for further information."
- echo "### :x: A whitespace issue was found in one or more of the commits." >"$outputFile"
- echo "" >>"$outputFile"
- echo "Run these commands to correct the problem:" >>"$outputFile"
- echo "1. \`git rebase --whitespace=fix ${goodParent}\`" >>"$outputFile"
- echo "1. \`git push --force\`" >>"$outputFile"
- echo " " >>"$outputFile"
- echo "Errors:" >>"$outputFile"
+ echo "A whitespace issue was found in onen of more of the commits."
+ echo "Run the following command to resolve whitespace issues:"
+ echo "git rebase --whitespace=fix ${goodParent}"
+
+ # If target output file is provided, write formatted ouput.
+ if test -n "$outputFile"
+ then
+ echo "🛑 Please review the Summary output for further information."
+ (
+ echo "### :x: A whitespace issue was found in one or more of the commits."
+ echo ""
+ echo "Run these commands to correct the problem:"
+ echo "1. \`git rebase --whitespace=fix ${goodParent}\`"
+ echo "1. \`git push --force\`"
+ echo ""
+ echo "Errors:"
- for i in "${problems[@]}"
- do
- echo "${i}" >>"$outputFile"
- done
+ for i in "${problems[@]}"
+ do
+ echo "${i}"
+ done
+ ) >"$outputFile"
+ fi
exit 2
fi
--
2.45.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* Re: [PATCH v2 4/5] ci: make the whitespace report optional
2024-05-02 19:38 ` [PATCH v2 4/5] ci: make the whitespace report optional Justin Tobler
@ 2024-05-03 6:56 ` Patrick Steinhardt
2024-05-03 15:35 ` Justin Tobler
0 siblings, 1 reply; 42+ messages in thread
From: Patrick Steinhardt @ 2024-05-03 6:56 UTC (permalink / raw)
To: Justin Tobler; +Cc: git
[-- Attachment #1: Type: text/plain, Size: 1578 bytes --]
On Thu, May 02, 2024 at 02:38:38PM -0500, Justin Tobler wrote:
> 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>
> ---
> ci/check-whitespace.sh | 45 +++++++++++++++++++++++++++++++-----------
> 1 file changed, 33 insertions(+), 12 deletions(-)
>
> diff --git a/ci/check-whitespace.sh b/ci/check-whitespace.sh
> index f57d1ff5f0..fabd6ecde5 100755
> --- a/ci/check-whitespace.sh
> +++ b/ci/check-whitespace.sh
> @@ -1,9 +1,20 @@
> #!/bin/bash
> +#
> +# Check that commits after a specified point do not contain new or modified
> +# lines with whitespace errors. An optional formatted summary can be generated
> +# by providing an output file path and url as additional arguments.
> +#
>
> baseCommit=$1
> outputFile=$2
> url=$3
>
> +if test "$#" -eq 0 || test "$#" -gt 3
That check is wrong, isn't it? Based on the usage below you either
accept exactly 1 or exactly 3 arguments. But the condition here also
accepts 2 arguments just fine. The following may be a bit easier to
follow as it is more explicit:
if test "$#" -ne 2 && test "$#" -ne 3
then
...
fi
> +then
> + echo "USAGE: $0 <BASE_COMMIT> [<OUTPUT_FILE> <URL>]"
> + exit 1
> +fi
Ah, you make the output file optional here. Fair enough, then you can
scratch that comment from my preceding mail as it did serve a purpose.
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 4/5] ci: make the whitespace report optional
2024-05-03 6:56 ` Patrick Steinhardt
@ 2024-05-03 15:35 ` Justin Tobler
0 siblings, 0 replies; 42+ messages in thread
From: Justin Tobler @ 2024-05-03 15:35 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git
On 24/05/03 08:56AM, Patrick Steinhardt wrote:
> On Thu, May 02, 2024 at 02:38:38PM -0500, Justin Tobler wrote:
> > 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>
> > ---
> > ci/check-whitespace.sh | 45 +++++++++++++++++++++++++++++++-----------
> > 1 file changed, 33 insertions(+), 12 deletions(-)
> >
> > diff --git a/ci/check-whitespace.sh b/ci/check-whitespace.sh
> > index f57d1ff5f0..fabd6ecde5 100755
> > --- a/ci/check-whitespace.sh
> > +++ b/ci/check-whitespace.sh
> > @@ -1,9 +1,20 @@
> > #!/bin/bash
> > +#
> > +# Check that commits after a specified point do not contain new or modified
> > +# lines with whitespace errors. An optional formatted summary can be generated
> > +# by providing an output file path and url as additional arguments.
> > +#
> >
> > baseCommit=$1
> > outputFile=$2
> > url=$3
> >
> > +if test "$#" -eq 0 || test "$#" -gt 3
>
> That check is wrong, isn't it? Based on the usage below you either
> accept exactly 1 or exactly 3 arguments. But the condition here also
> accepts 2 arguments just fine. The following may be a bit easier to
> follow as it is more explicit:
>
> if test "$#" -ne 2 && test "$#" -ne 3
> then
> ...
> fi
Ya, good point. We should only accept 1 or 3 arguments as valid options.
I'll update this. Thanks!
-Justin
> > +then
> > + echo "USAGE: $0 <BASE_COMMIT> [<OUTPUT_FILE> <URL>]"
> > + exit 1
> > +fi
>
> Ah, you make the output file optional here. Fair enough, then you can
> scratch that comment from my preceding mail as it did serve a purpose.
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v2 5/5] gitlab-ci: add whitespace error check
2024-05-02 19:38 ` [PATCH v2 0/5] Add GitLab CI to check for whitespace errors Justin Tobler
` (3 preceding siblings ...)
2024-05-02 19:38 ` [PATCH v2 4/5] ci: make the whitespace report optional Justin Tobler
@ 2024-05-02 19:38 ` Justin Tobler
2024-05-03 6:56 ` Patrick Steinhardt
2024-05-02 21:45 ` [PATCH v2 0/5] Add GitLab CI to check for whitespace errors Junio C Hamano
2024-05-03 17:21 ` [PATCH v3 " Justin Tobler
6 siblings, 1 reply; 42+ messages in thread
From: Justin Tobler @ 2024-05-02 19:38 UTC (permalink / raw)
To: git; +Cc: Justin Tobler
GitLab CI does not have a job to check for whitespace errors introduced
by a set of changes. Reuse the existing generic `whitespace-check.sh` to
create the job for GitLab pipelines.
Note that the `$CI_MERGE_REQUEST_TARGET_BRANCH_SHA` variable is only
available in GitLab merge request pipelines and therefore the CI job is
configured to only run as part of those pipelines.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
.gitlab-ci.yml | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index c0fa2fe90b..6d046ce409 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -102,3 +102,12 @@ static-analysis:
script:
- ./ci/run-static-analysis.sh
- ./ci/check-directional-formatting.bash
+
+check-whitespace:
+ image: ubuntu:latest
+ before_script:
+ - ./ci/install-docker-dependencies.sh
+ script:
+ - ./ci/check-whitespace.sh "$CI_MERGE_REQUEST_TARGET_BRANCH_SHA"
+ rules:
+ - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
--
2.45.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* Re: [PATCH v2 5/5] gitlab-ci: add whitespace error check
2024-05-02 19:38 ` [PATCH v2 5/5] gitlab-ci: add whitespace error check Justin Tobler
@ 2024-05-03 6:56 ` Patrick Steinhardt
0 siblings, 0 replies; 42+ messages in thread
From: Patrick Steinhardt @ 2024-05-03 6:56 UTC (permalink / raw)
To: Justin Tobler; +Cc: git
[-- Attachment #1: Type: text/plain, Size: 1176 bytes --]
On Thu, May 02, 2024 at 02:38:39PM -0500, Justin Tobler wrote:
> GitLab CI does not have a job to check for whitespace errors introduced
> by a set of changes. Reuse the existing generic `whitespace-check.sh` to
> create the job for GitLab pipelines.
>
> Note that the `$CI_MERGE_REQUEST_TARGET_BRANCH_SHA` variable is only
> available in GitLab merge request pipelines and therefore the CI job is
> configured to only run as part of those pipelines.
>
> Signed-off-by: Justin Tobler <jltobler@gmail.com>
> ---
> .gitlab-ci.yml | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
> index c0fa2fe90b..6d046ce409 100644
> --- a/.gitlab-ci.yml
> +++ b/.gitlab-ci.yml
> @@ -102,3 +102,12 @@ static-analysis:
> script:
> - ./ci/run-static-analysis.sh
> - ./ci/check-directional-formatting.bash
> +
> +check-whitespace:
> + image: ubuntu:latest
> + before_script:
> + - ./ci/install-docker-dependencies.sh
> + script:
> + - ./ci/check-whitespace.sh "$CI_MERGE_REQUEST_TARGET_BRANCH_SHA"
> + rules:
> + - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
Nice :)
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 0/5] Add GitLab CI to check for whitespace errors
2024-05-02 19:38 ` [PATCH v2 0/5] Add GitLab CI to check for whitespace errors Justin Tobler
` (4 preceding siblings ...)
2024-05-02 19:38 ` [PATCH v2 5/5] gitlab-ci: add whitespace error check Justin Tobler
@ 2024-05-02 21:45 ` Junio C Hamano
2024-05-03 15:39 ` Justin Tobler
2024-05-03 17:21 ` [PATCH v3 " Justin Tobler
6 siblings, 1 reply; 42+ messages in thread
From: Junio C Hamano @ 2024-05-02 21:45 UTC (permalink / raw)
To: Justin Tobler; +Cc: git, ps
Justin Tobler <jltobler@gmail.com> writes:
> This is the second version of my patch series to add a GitLab CI job to
> check for whitespace errors. The main differnece with this version is
> that it first generalizes the existing GitHub whitespace check CI job
> allowing the GitLab one to reuse it.
Will queue. Thanks. The extraction and reuse of a common script is
excellent.
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v2 0/5] Add GitLab CI to check for whitespace errors
2024-05-02 21:45 ` [PATCH v2 0/5] Add GitLab CI to check for whitespace errors Junio C Hamano
@ 2024-05-03 15:39 ` Justin Tobler
0 siblings, 0 replies; 42+ messages in thread
From: Justin Tobler @ 2024-05-03 15:39 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, ps
On 24/05/02 02:45PM, Junio C Hamano wrote:
> Justin Tobler <jltobler@gmail.com> writes:
>
> > This is the second version of my patch series to add a GitLab CI job to
> > check for whitespace errors. The main differnece with this version is
> > that it first generalizes the existing GitHub whitespace check CI job
> > allowing the GitLab one to reuse it.
>
> Will queue. Thanks. The extraction and reuse of a common script is
> excellent.
Thanks! I will send a V3 here shortly which makes some small suggested
edits.
-Justin
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v3 0/5] Add GitLab CI to check for whitespace errors
2024-05-02 19:38 ` [PATCH v2 0/5] Add GitLab CI to check for whitespace errors Justin Tobler
` (5 preceding siblings ...)
2024-05-02 21:45 ` [PATCH v2 0/5] Add GitLab CI to check for whitespace errors Junio C Hamano
@ 2024-05-03 17:21 ` Justin Tobler
2024-05-03 17:21 ` [PATCH v3 1/5] ci: pre-collapse GitLab CI sections Justin Tobler
` (4 more replies)
6 siblings, 5 replies; 42+ messages in thread
From: Justin Tobler @ 2024-05-03 17:21 UTC (permalink / raw)
To: git; +Cc: Justin Tobler, ps
Hello again,
This is the third version of my patch series to add a GitLab CI job to
check for whitespace errors.
Changes since V2:
- In 35e293e6 (Merge branch 'ps/ci-test-with-jgit' into next,
2024-05-01), `install-docker-dependencies.sh` script was merged into
`install-dependencies.sh` and removed. Thus this patch series now
depends on that change and is updated to use the other script.
- Changed the shebang to "#!/usr/bin/env bash".
- Made the argument count validation more strict.
- Fixed a typo.
GitHub CI:
- https://github.com/gitgitgadget/git/actions/runs/8941666020?pr=1727
- https://github.com/gitgitgadget/git/actions/runs/8941721282?pr=1727
GitLab CI:
- https://gitlab.com/gitlab-org/git/-/jobs/6776032414
- https://gitlab.com/gitlab-org/git/-/jobs/6776038234
Thanks for the reviews,
-Justin
Justin Tobler (5):
ci: pre-collapse GitLab CI sections
github-ci: fix link to whitespace error
ci: separate whitespace check script
ci: make the whitespace report optional
gitlab-ci: add whitespace error check
.github/workflows/check-whitespace.yml | 67 ++----------------
.gitlab-ci.yml | 9 +++
ci/check-whitespace.sh | 95 ++++++++++++++++++++++++++
ci/lib.sh | 2 +-
4 files changed, 109 insertions(+), 64 deletions(-)
create mode 100755 ci/check-whitespace.sh
Range-diff against v2:
1: 924d3eb23c = 1: 924d3eb23c ci: pre-collapse GitLab CI sections
2: c8d8b444dc = 2: c8d8b444dc github-ci: fix link to whitespace error
3: 6b44b21dda ! 3: 933e0c33f9 ci: separate whitespace check script
@@ .github/workflows/check-whitespace.yml: jobs:
## ci/check-whitespace.sh (new) ##
@@
-+#!/bin/bash
++#!/usr/bin/env bash
+
+baseCommit=$1
+outputFile=$2
4: 87dfd1d5a9 ! 4: 374735c60f ci: make the whitespace report optional
@@ Commit message
## ci/check-whitespace.sh ##
@@
- #!/bin/bash
+ #!/usr/bin/env bash
+#
+# Check that commits after a specified point do not contain new or modified
+# lines with whitespace errors. An optional formatted summary can be generated
@@ ci/check-whitespace.sh
outputFile=$2
url=$3
-+if test "$#" -eq 0 || test "$#" -gt 3
++if test "$#" -ne 1 && test "$#" -ne 3
+then
+ echo "USAGE: $0 <BASE_COMMIT> [<OUTPUT_FILE> <URL>]"
+ exit 1
@@ ci/check-whitespace.sh: then
+ echo "Run the following command to resolve whitespace issues:"
+ echo "git rebase --whitespace=fix ${goodParent}"
+
-+ # If target output file is provided, write formatted ouput.
++ # If target output file is provided, write formatted output.
+ if test -n "$outputFile"
+ then
+ echo "🛑 Please review the Summary output for further information."
5: 175b300e91 ! 5: a7deaeadc7 gitlab-ci: add whitespace error check
@@ .gitlab-ci.yml: static-analysis:
+check-whitespace:
+ image: ubuntu:latest
+ before_script:
-+ - ./ci/install-docker-dependencies.sh
++ - ./ci/install-dependencies.sh
+ script:
+ - ./ci/check-whitespace.sh "$CI_MERGE_REQUEST_TARGET_BRANCH_SHA"
+ rules:
--
2.45.0
^ permalink raw reply [flat|nested] 42+ messages in thread
* [PATCH v3 1/5] ci: pre-collapse GitLab CI sections
2024-05-03 17:21 ` [PATCH v3 " Justin Tobler
@ 2024-05-03 17:21 ` Justin Tobler
2024-05-03 17:21 ` [PATCH v3 2/5] github-ci: fix link to whitespace error Justin Tobler
` (3 subsequent siblings)
4 siblings, 0 replies; 42+ messages in thread
From: Justin Tobler @ 2024-05-03 17:21 UTC (permalink / raw)
To: git; +Cc: Justin Tobler
Sections of CI output defined by `begin_group()` and `end_group()` are
expanded in GitLab pipelines by default. This can make CI job output
rather noisy and harder to navigate. Update the behavior for GitLab
pipelines to now collapse sections by default.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
ci/lib.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ci/lib.sh b/ci/lib.sh
index 0a73fc7bd1..02e5e058dd 100755
--- a/ci/lib.sh
+++ b/ci/lib.sh
@@ -18,7 +18,7 @@ elif test true = "$GITLAB_CI"
then
begin_group () {
need_to_end_group=t
- printf "\e[0Ksection_start:$(date +%s):$(echo "$1" | tr ' ' _)\r\e[0K$1\n"
+ printf "\e[0Ksection_start:$(date +%s):$(echo "$1" | tr ' ' _)[collapsed=true]\r\e[0K$1\n"
trap "end_group '$1'" EXIT
set -x
}
--
2.45.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v3 2/5] github-ci: fix link to whitespace error
2024-05-03 17:21 ` [PATCH v3 " Justin Tobler
2024-05-03 17:21 ` [PATCH v3 1/5] ci: pre-collapse GitLab CI sections Justin Tobler
@ 2024-05-03 17:21 ` Justin Tobler
2024-05-03 17:21 ` [PATCH v3 3/5] ci: separate whitespace check script Justin Tobler
` (2 subsequent siblings)
4 siblings, 0 replies; 42+ messages in thread
From: Justin Tobler @ 2024-05-03 17:21 UTC (permalink / raw)
To: git; +Cc: Justin Tobler
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>
---
.github/workflows/check-whitespace.yml | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/.github/workflows/check-whitespace.yml b/.github/workflows/check-whitespace.yml
index a241a63428..a3a6913ecc 100644
--- a/.github/workflows/check-whitespace.yml
+++ b/.github/workflows/check-whitespace.yml
@@ -31,14 +31,15 @@ jobs:
commit=
commitText=
commitTextmd=
- goodparent=
+ goodParent=
while read dash sha etc
do
case "${dash}" in
- "---")
- if test -z "${commit}"
+ "---") # Line contains commit information.
+ if test -z "${goodParent}"
then
- goodparent=${sha}
+ # Assume the commit has no whitespace errors until detected otherwise.
+ goodParent=${sha}
fi
commit="${sha}"
commitText="${sha} ${etc}"
@@ -46,18 +47,18 @@ jobs:
;;
"")
;;
- *)
- if test -n "${commit}"
+ *) # Line contains whitespace error information for current commit.
+ if test -n "${goodParent}"
then
problems+=("1) --- ${commitTextmd}")
echo ""
echo "--- ${commitText}"
- commit=
+ goodParent=
fi
case "${dash}" in
*:[1-9]*:) # contains file and line number information
dashend=${dash#*:}
- problems+=("[${dash}](https://github.com/${{ github.repository }}/blob/${{github.event.pull_request.head.ref}}/${dash%%:*}#L${dashend%:}) ${sha} ${etc}")
+ problems+=("[${dash}](https://github.com/${{ github.repository }}/blob/${commit}/${dash%%:*}#L${dashend%:}) ${sha} ${etc}")
;;
*)
problems+=("\`${dash} ${sha} ${etc}\`")
@@ -70,15 +71,15 @@ jobs:
if test ${#problems[*]} -gt 0
then
- if test -z "${commit}"
+ if test -z "${goodParent}"
then
- goodparent=${baseSha: 0:7}
+ goodParent=${baseSha: 0:7}
fi
echo "🛑 Please review the Summary output for further information."
echo "### :x: A whitespace issue was found in one or more of the commits." >$GITHUB_STEP_SUMMARY
echo "" >>$GITHUB_STEP_SUMMARY
echo "Run these commands to correct the problem:" >>$GITHUB_STEP_SUMMARY
- echo "1. \`git rebase --whitespace=fix ${goodparent}\`" >>$GITHUB_STEP_SUMMARY
+ echo "1. \`git rebase --whitespace=fix ${goodParent}\`" >>$GITHUB_STEP_SUMMARY
echo "1. \`git push --force\`" >>$GITHUB_STEP_SUMMARY
echo " " >>$GITHUB_STEP_SUMMARY
echo "Errors:" >>$GITHUB_STEP_SUMMARY
--
2.45.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v3 3/5] ci: separate whitespace check script
2024-05-03 17:21 ` [PATCH v3 " Justin Tobler
2024-05-03 17:21 ` [PATCH v3 1/5] ci: pre-collapse GitLab CI sections Justin Tobler
2024-05-03 17:21 ` [PATCH v3 2/5] github-ci: fix link to whitespace error Justin Tobler
@ 2024-05-03 17:21 ` Justin Tobler
2024-05-03 17:21 ` [PATCH v3 4/5] ci: make the whitespace report optional Justin Tobler
2024-05-03 17:21 ` [PATCH v3 5/5] gitlab-ci: add whitespace error check Justin Tobler
4 siblings, 0 replies; 42+ messages in thread
From: Justin Tobler @ 2024-05-03 17:21 UTC (permalink / raw)
To: git; +Cc: Justin Tobler, Patrick Steinhardt
The `check-whitespace` CI job is only available as a GitHub action. To
help enable this job with other CI providers, first separate the logic
performing the whitespace check into its own script. In subsequent
commits, this script is further generalized allowing its reuse.
Helped-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
.github/workflows/check-whitespace.yml | 68 ++---------------------
ci/check-whitespace.sh | 74 ++++++++++++++++++++++++++
2 files changed, 78 insertions(+), 64 deletions(-)
create mode 100755 ci/check-whitespace.sh
diff --git a/.github/workflows/check-whitespace.yml b/.github/workflows/check-whitespace.yml
index a3a6913ecc..d0a78fc426 100644
--- a/.github/workflows/check-whitespace.yml
+++ b/.github/workflows/check-whitespace.yml
@@ -26,67 +26,7 @@ jobs:
- name: git log --check
id: check_out
run: |
- baseSha=${{github.event.pull_request.base.sha}}
- problems=()
- commit=
- commitText=
- commitTextmd=
- goodParent=
- while read dash sha etc
- do
- case "${dash}" in
- "---") # Line contains commit information.
- if test -z "${goodParent}"
- then
- # Assume the commit has no whitespace errors until detected otherwise.
- goodParent=${sha}
- fi
- commit="${sha}"
- commitText="${sha} ${etc}"
- commitTextmd="[${sha}](https://github.com/${{ github.repository }}/commit/${sha}) ${etc}"
- ;;
- "")
- ;;
- *) # Line contains whitespace error information for current commit.
- if test -n "${goodParent}"
- then
- problems+=("1) --- ${commitTextmd}")
- echo ""
- echo "--- ${commitText}"
- goodParent=
- fi
- case "${dash}" in
- *:[1-9]*:) # contains file and line number information
- dashend=${dash#*:}
- problems+=("[${dash}](https://github.com/${{ github.repository }}/blob/${commit}/${dash%%:*}#L${dashend%:}) ${sha} ${etc}")
- ;;
- *)
- problems+=("\`${dash} ${sha} ${etc}\`")
- ;;
- esac
- echo "${dash} ${sha} ${etc}"
- ;;
- esac
- done <<< $(git log --check --pretty=format:"---% h% s" ${baseSha}..)
-
- if test ${#problems[*]} -gt 0
- then
- if test -z "${goodParent}"
- then
- goodParent=${baseSha: 0:7}
- fi
- echo "🛑 Please review the Summary output for further information."
- echo "### :x: A whitespace issue was found in one or more of the commits." >$GITHUB_STEP_SUMMARY
- echo "" >>$GITHUB_STEP_SUMMARY
- echo "Run these commands to correct the problem:" >>$GITHUB_STEP_SUMMARY
- echo "1. \`git rebase --whitespace=fix ${goodParent}\`" >>$GITHUB_STEP_SUMMARY
- echo "1. \`git push --force\`" >>$GITHUB_STEP_SUMMARY
- echo " " >>$GITHUB_STEP_SUMMARY
- echo "Errors:" >>$GITHUB_STEP_SUMMARY
- for i in "${problems[@]}"
- do
- echo "${i}" >>$GITHUB_STEP_SUMMARY
- done
-
- exit 2
- fi
+ ./ci/check-whitespace.sh \
+ "${{github.event.pull_request.base.sha}}" \
+ "$GITHUB_STEP_SUMMARY" \
+ "https://github.com/${{github.repository}}"
diff --git a/ci/check-whitespace.sh b/ci/check-whitespace.sh
new file mode 100755
index 0000000000..9cc496da40
--- /dev/null
+++ b/ci/check-whitespace.sh
@@ -0,0 +1,74 @@
+#!/usr/bin/env bash
+
+baseCommit=$1
+outputFile=$2
+url=$3
+
+problems=()
+commit=
+commitText=
+commitTextmd=
+goodParent=
+
+while read dash sha etc
+do
+ case "${dash}" in
+ "---") # Line contains commit information.
+ if test -z "${goodParent}"
+ then
+ # Assume the commit has no whitespace errors until detected otherwise.
+ goodParent=${sha}
+ fi
+
+ commit="${sha}"
+ commitText="${sha} ${etc}"
+ commitTextmd="[${sha}](${url}/commit/${sha}) ${etc}"
+ ;;
+ "")
+ ;;
+ *) # Line contains whitespace error information for current commit.
+ if test -n "${goodParent}"
+ then
+ problems+=("1) --- ${commitTextmd}")
+ echo ""
+ echo "--- ${commitText}"
+ goodParent=
+ fi
+
+ case "${dash}" in
+ *:[1-9]*:) # contains file and line number information
+ dashend=${dash#*:}
+ problems+=("[${dash}](${url}/blob/${commit}/${dash%%:*}#L${dashend%:}) ${sha} ${etc}")
+ ;;
+ *)
+ problems+=("\`${dash} ${sha} ${etc}\`")
+ ;;
+ esac
+ echo "${dash} ${sha} ${etc}"
+ ;;
+ esac
+done <<< "$(git log --check --pretty=format:"---% h% s" "${baseCommit}"..)"
+
+if test ${#problems[*]} -gt 0
+then
+ if test -z "${goodParent}"
+ then
+ goodParent=${baseCommit: 0:7}
+ fi
+
+ echo "🛑 Please review the Summary output for further information."
+ echo "### :x: A whitespace issue was found in one or more of the commits." >"$outputFile"
+ echo "" >>"$outputFile"
+ echo "Run these commands to correct the problem:" >>"$outputFile"
+ echo "1. \`git rebase --whitespace=fix ${goodParent}\`" >>"$outputFile"
+ echo "1. \`git push --force\`" >>"$outputFile"
+ echo " " >>"$outputFile"
+ echo "Errors:" >>"$outputFile"
+
+ for i in "${problems[@]}"
+ do
+ echo "${i}" >>"$outputFile"
+ done
+
+ exit 2
+fi
--
2.45.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v3 4/5] ci: make the whitespace report optional
2024-05-03 17:21 ` [PATCH v3 " Justin Tobler
` (2 preceding siblings ...)
2024-05-03 17:21 ` [PATCH v3 3/5] ci: separate whitespace check script Justin Tobler
@ 2024-05-03 17:21 ` Justin Tobler
2024-05-03 17:21 ` [PATCH v3 5/5] gitlab-ci: add whitespace error check Justin Tobler
4 siblings, 0 replies; 42+ messages in thread
From: Justin Tobler @ 2024-05-03 17:21 UTC (permalink / raw)
To: git; +Cc: Justin Tobler
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>
---
ci/check-whitespace.sh | 45 +++++++++++++++++++++++++++++++-----------
1 file changed, 33 insertions(+), 12 deletions(-)
diff --git a/ci/check-whitespace.sh b/ci/check-whitespace.sh
index 9cc496da40..db399097a5 100755
--- a/ci/check-whitespace.sh
+++ b/ci/check-whitespace.sh
@@ -1,9 +1,20 @@
#!/usr/bin/env bash
+#
+# Check that commits after a specified point do not contain new or modified
+# lines with whitespace errors. An optional formatted summary can be generated
+# by providing an output file path and url as additional arguments.
+#
baseCommit=$1
outputFile=$2
url=$3
+if test "$#" -ne 1 && test "$#" -ne 3
+then
+ echo "USAGE: $0 <BASE_COMMIT> [<OUTPUT_FILE> <URL>]"
+ exit 1
+fi
+
problems=()
commit=
commitText=
@@ -56,19 +67,29 @@ then
goodParent=${baseCommit: 0:7}
fi
- echo "🛑 Please review the Summary output for further information."
- echo "### :x: A whitespace issue was found in one or more of the commits." >"$outputFile"
- echo "" >>"$outputFile"
- echo "Run these commands to correct the problem:" >>"$outputFile"
- echo "1. \`git rebase --whitespace=fix ${goodParent}\`" >>"$outputFile"
- echo "1. \`git push --force\`" >>"$outputFile"
- echo " " >>"$outputFile"
- echo "Errors:" >>"$outputFile"
+ echo "A whitespace issue was found in onen of more of the commits."
+ echo "Run the following command to resolve whitespace issues:"
+ echo "git rebase --whitespace=fix ${goodParent}"
+
+ # If target output file is provided, write formatted output.
+ if test -n "$outputFile"
+ then
+ echo "🛑 Please review the Summary output for further information."
+ (
+ echo "### :x: A whitespace issue was found in one or more of the commits."
+ echo ""
+ echo "Run these commands to correct the problem:"
+ echo "1. \`git rebase --whitespace=fix ${goodParent}\`"
+ echo "1. \`git push --force\`"
+ echo ""
+ echo "Errors:"
- for i in "${problems[@]}"
- do
- echo "${i}" >>"$outputFile"
- done
+ for i in "${problems[@]}"
+ do
+ echo "${i}"
+ done
+ ) >"$outputFile"
+ fi
exit 2
fi
--
2.45.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* [PATCH v3 5/5] gitlab-ci: add whitespace error check
2024-05-03 17:21 ` [PATCH v3 " Justin Tobler
` (3 preceding siblings ...)
2024-05-03 17:21 ` [PATCH v3 4/5] ci: make the whitespace report optional Justin Tobler
@ 2024-05-03 17:21 ` Justin Tobler
2024-05-06 6:55 ` Patrick Steinhardt
4 siblings, 1 reply; 42+ messages in thread
From: Justin Tobler @ 2024-05-03 17:21 UTC (permalink / raw)
To: git; +Cc: Justin Tobler
GitLab CI does not have a job to check for whitespace errors introduced
by a set of changes. Reuse the existing generic `whitespace-check.sh` to
create the job for GitLab pipelines.
Note that the `$CI_MERGE_REQUEST_TARGET_BRANCH_SHA` variable is only
available in GitLab merge request pipelines and therefore the CI job is
configured to only run as part of those pipelines.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
.gitlab-ci.yml | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index c0fa2fe90b..619bf729fa 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -102,3 +102,12 @@ static-analysis:
script:
- ./ci/run-static-analysis.sh
- ./ci/check-directional-formatting.bash
+
+check-whitespace:
+ image: ubuntu:latest
+ before_script:
+ - ./ci/install-dependencies.sh
+ script:
+ - ./ci/check-whitespace.sh "$CI_MERGE_REQUEST_TARGET_BRANCH_SHA"
+ rules:
+ - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
--
2.45.0
^ permalink raw reply related [flat|nested] 42+ messages in thread
* Re: [PATCH v3 5/5] gitlab-ci: add whitespace error check
2024-05-03 17:21 ` [PATCH v3 5/5] gitlab-ci: add whitespace error check Justin Tobler
@ 2024-05-06 6:55 ` Patrick Steinhardt
2024-05-06 13:59 ` Justin Tobler
2024-05-06 17:17 ` Junio C Hamano
0 siblings, 2 replies; 42+ messages in thread
From: Patrick Steinhardt @ 2024-05-06 6:55 UTC (permalink / raw)
To: Justin Tobler; +Cc: git
[-- Attachment #1: Type: text/plain, Size: 1347 bytes --]
On Fri, May 03, 2024 at 12:21:07PM -0500, Justin Tobler wrote:
> GitLab CI does not have a job to check for whitespace errors introduced
> by a set of changes. Reuse the existing generic `whitespace-check.sh` to
> create the job for GitLab pipelines.
>
> Note that the `$CI_MERGE_REQUEST_TARGET_BRANCH_SHA` variable is only
> available in GitLab merge request pipelines and therefore the CI job is
> configured to only run as part of those pipelines.
>
> Signed-off-by: Justin Tobler <jltobler@gmail.com>
> ---
> .gitlab-ci.yml | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
> index c0fa2fe90b..619bf729fa 100644
> --- a/.gitlab-ci.yml
> +++ b/.gitlab-ci.yml
> @@ -102,3 +102,12 @@ static-analysis:
> script:
> - ./ci/run-static-analysis.sh
> - ./ci/check-directional-formatting.bash
> +
> +check-whitespace:
> + image: ubuntu:latest
> + before_script:
> + - ./ci/install-dependencies.sh
Do we actually need to install dependencies? I imagine all that's needed
would be Git.
Other than this question the patch series looks good to me, thanks!
Patrick
> + script:
> + - ./ci/check-whitespace.sh "$CI_MERGE_REQUEST_TARGET_BRANCH_SHA"
> + rules:
> + - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
> --
> 2.45.0
>
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v3 5/5] gitlab-ci: add whitespace error check
2024-05-06 6:55 ` Patrick Steinhardt
@ 2024-05-06 13:59 ` Justin Tobler
2024-05-06 17:17 ` Junio C Hamano
1 sibling, 0 replies; 42+ messages in thread
From: Justin Tobler @ 2024-05-06 13:59 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: git
On 24/05/06 08:55AM, Patrick Steinhardt wrote:
> On Fri, May 03, 2024 at 12:21:07PM -0500, Justin Tobler wrote:
> > GitLab CI does not have a job to check for whitespace errors introduced
> > by a set of changes. Reuse the existing generic `whitespace-check.sh` to
> > create the job for GitLab pipelines.
> >
> > Note that the `$CI_MERGE_REQUEST_TARGET_BRANCH_SHA` variable is only
> > available in GitLab merge request pipelines and therefore the CI job is
> > configured to only run as part of those pipelines.
> >
> > Signed-off-by: Justin Tobler <jltobler@gmail.com>
> > ---
> > .gitlab-ci.yml | 9 +++++++++
> > 1 file changed, 9 insertions(+)
> >
> > diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
> > index c0fa2fe90b..619bf729fa 100644
> > --- a/.gitlab-ci.yml
> > +++ b/.gitlab-ci.yml
> > @@ -102,3 +102,12 @@ static-analysis:
> > script:
> > - ./ci/run-static-analysis.sh
> > - ./ci/check-directional-formatting.bash
> > +
> > +check-whitespace:
> > + image: ubuntu:latest
> > + before_script:
> > + - ./ci/install-dependencies.sh
>
> Do we actually need to install dependencies? I imagine all that's needed
> would be Git.
You are correct. Git is really the only dependency we need. If we want
to remove the need for the install dependencies script, we could fetch
Git ourselves during the pre-script. Another option could be to use a
different container image that has Git baked in.
-Justin
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v3 5/5] gitlab-ci: add whitespace error check
2024-05-06 6:55 ` Patrick Steinhardt
2024-05-06 13:59 ` Justin Tobler
@ 2024-05-06 17:17 ` Junio C Hamano
2024-05-06 19:21 ` Justin Tobler
1 sibling, 1 reply; 42+ messages in thread
From: Junio C Hamano @ 2024-05-06 17:17 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: Justin Tobler, git
Patrick Steinhardt <ps@pks.im> writes:
>> +check-whitespace:
>> + image: ubuntu:latest
>> + before_script:
>> + - ./ci/install-dependencies.sh
>
> Do we actually need to install dependencies? I imagine all that's needed
> would be Git.
>
> Other than this question the patch series looks good to me, thanks!
I am a bit puzzled. Is the proposal to check our sources with a
pre-built Git (which by definition would be a bit older than what is
being tested)?
Not that I have serious trouble in that direction---I am just trying
to make sure what is being proposed.
Thanks.
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v3 5/5] gitlab-ci: add whitespace error check
2024-05-06 17:17 ` Junio C Hamano
@ 2024-05-06 19:21 ` Justin Tobler
2024-05-07 4:12 ` Patrick Steinhardt
0 siblings, 1 reply; 42+ messages in thread
From: Justin Tobler @ 2024-05-06 19:21 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Patrick Steinhardt, git
On 24/05/06 10:17AM, Junio C Hamano wrote:
> Patrick Steinhardt <ps@pks.im> writes:
>
> >> +check-whitespace:
> >> + image: ubuntu:latest
> >> + before_script:
> >> + - ./ci/install-dependencies.sh
> >
> > Do we actually need to install dependencies? I imagine all that's needed
> > would be Git.
> >
> > Other than this question the patch series looks good to me, thanks!
>
> I am a bit puzzled. Is the proposal to check our sources with a
> pre-built Git (which by definition would be a bit older than what is
> being tested)?
The GitLab `check-whitespace` CI job only needs Git to run and uses
`ci/install-dependencies.sh` to download a pre-built Git package via
`apt-get` since `ubuntu:latest` is the container image used. The
`ci/install-dependencies.sh` script also fetches a bunch of other
dependencies which are not needed.
I think Patrick is proposing, to further simplify, we avoid using
`ci/install-dependencies.sh` and only fetch Git. Patrick please correct
me if I misunderstand :)
-Justin
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v3 5/5] gitlab-ci: add whitespace error check
2024-05-06 19:21 ` Justin Tobler
@ 2024-05-07 4:12 ` Patrick Steinhardt
2024-05-07 18:06 ` Justin Tobler
0 siblings, 1 reply; 42+ messages in thread
From: Patrick Steinhardt @ 2024-05-07 4:12 UTC (permalink / raw)
To: Junio C Hamano, git
[-- Attachment #1: Type: text/plain, Size: 1566 bytes --]
On Mon, May 06, 2024 at 02:21:52PM -0500, Justin Tobler wrote:
> On 24/05/06 10:17AM, Junio C Hamano wrote:
> > Patrick Steinhardt <ps@pks.im> writes:
> >
> > >> +check-whitespace:
> > >> + image: ubuntu:latest
> > >> + before_script:
> > >> + - ./ci/install-dependencies.sh
> > >
> > > Do we actually need to install dependencies? I imagine all that's needed
> > > would be Git.
> > >
> > > Other than this question the patch series looks good to me, thanks!
> >
> > I am a bit puzzled. Is the proposal to check our sources with a
> > pre-built Git (which by definition would be a bit older than what is
> > being tested)?
>
> The GitLab `check-whitespace` CI job only needs Git to run and uses
> `ci/install-dependencies.sh` to download a pre-built Git package via
> `apt-get` since `ubuntu:latest` is the container image used. The
> `ci/install-dependencies.sh` script also fetches a bunch of other
> dependencies which are not needed.
>
> I think Patrick is proposing, to further simplify, we avoid using
> `ci/install-dependencies.sh` and only fetch Git. Patrick please correct
> me if I misunderstand :)
I just wondered how GitHub Workflows manages without installing any
dependencies at all. Is Git already part of the default images? If so,
there is no need to install anything and we can just execute the script
directly, which saves some time.
If there is a need to install Git we could either just manually install
it in the `before_script` or leave it as-is. I don't mind it much either
way.
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v3 5/5] gitlab-ci: add whitespace error check
2024-05-07 4:12 ` Patrick Steinhardt
@ 2024-05-07 18:06 ` Justin Tobler
2024-05-07 18:12 ` Patrick Steinhardt
0 siblings, 1 reply; 42+ messages in thread
From: Justin Tobler @ 2024-05-07 18:06 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: Junio C Hamano, git
On 24/05/07 06:12AM, Patrick Steinhardt wrote:
> I just wondered how GitHub Workflows manages without installing any
> dependencies at all. Is Git already part of the default images? If so,
> there is no need to install anything and we can just execute the script
> directly, which saves some time.
Git is not bundled by default in the "ubuntu:latest" container image. We
would have to install it ourselves. As for why GitHub Workflows do not
have to install Git, it looks like each runner has a defined set of
included software which happens to include Git.
https://github.com/actions/runner-images/blob/ubuntu22/20240422.1/images/ubuntu/Ubuntu2204-Readme.md
> If there is a need to install Git we could either just manually install
> it in the `before_script` or leave it as-is. I don't mind it much either
> way.
I don't have strong opinions, but I think I would prefer to leave it
as-is and reuse `ci/install-dependencies.sh`. I'll forgo sending another
version unless there is addional feedback. Thanks
-Justin
^ permalink raw reply [flat|nested] 42+ messages in thread
* Re: [PATCH v3 5/5] gitlab-ci: add whitespace error check
2024-05-07 18:06 ` Justin Tobler
@ 2024-05-07 18:12 ` Patrick Steinhardt
0 siblings, 0 replies; 42+ messages in thread
From: Patrick Steinhardt @ 2024-05-07 18:12 UTC (permalink / raw)
To: Junio C Hamano, git
[-- Attachment #1: Type: text/plain, Size: 1226 bytes --]
On Tue, May 07, 2024 at 01:06:04PM -0500, Justin Tobler wrote:
> On 24/05/07 06:12AM, Patrick Steinhardt wrote:
>
> > I just wondered how GitHub Workflows manages without installing any
> > dependencies at all. Is Git already part of the default images? If so,
> > there is no need to install anything and we can just execute the script
> > directly, which saves some time.
>
> Git is not bundled by default in the "ubuntu:latest" container image. We
> would have to install it ourselves. As for why GitHub Workflows do not
> have to install Git, it looks like each runner has a defined set of
> included software which happens to include Git.
Okay.
> https://github.com/actions/runner-images/blob/ubuntu22/20240422.1/images/ubuntu/Ubuntu2204-Readme.md
>
> > If there is a need to install Git we could either just manually install
> > it in the `before_script` or leave it as-is. I don't mind it much either
> > way.
>
> I don't have strong opinions, but I think I would prefer to leave it
> as-is and reuse `ci/install-dependencies.sh`. I'll forgo sending another
> version unless there is addional feedback. Thanks
Fair enough. Let's not overthink this then and get this merged.
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 42+ messages in thread