Git Mailing List Archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Justin Tobler <jltobler@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/2] gitlab-ci: add whitespace error check
Date: Tue, 30 Apr 2024 07:04:46 +0200	[thread overview]
Message-ID: <ZjB77nSMou0ssu-V@tanuki> (raw)
In-Reply-To: <20240430003323.6210-3-jltobler@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3391 bytes --]

On Mon, Apr 29, 2024 at 07:33:23PM -0500, Justin Tobler wrote:
> To check for whitespace errors introduced by a set of changes, there is
> the `.github/workflows/check-whitespace.yml` GitHub action. This script
> executes `git log --check` over a range containing the new commits and
> parses the output to generate a markdown formatted artifact that
> summarizes detected errors with GitHub links to the affected commits and
> blobs.
> 
> Since this script is rather specific to GitHub actions, a more general
> and simple `ci/check-whitespace.sh` is added instead that functions the
> same, but does not generate the markdown file for the action summary.
> From this, a new GitLab CI job is added to support the whitespace error
> check.

I still wonder whether we can unify these. Yes, the GitHub thing is
quite specific. But ultimately, what it does is to generate a proper
summary of where exactly the whitespaces issues are, which is something
that your version doesn't do. It's useful though for consumers of a
failed CI job to know exactly which commit has the issue.

So can't we pull out the logic into a script, refactor it such that it
knows to print both GitHub- and GitLab-style URLs, and then also print
the summary in GitLab CI?

> 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 +++++++++
>  ci/check-whitespace.sh | 16 ++++++++++++++++
>  2 files changed, 25 insertions(+)
>  create mode 100755 ci/check-whitespace.sh
> 
> diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
> index c0fa2fe90b..31cf420a11 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

Let's quote this variable.

> +  rules:
> +    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
> diff --git a/ci/check-whitespace.sh b/ci/check-whitespace.sh
> new file mode 100755
> index 0000000000..1cad2d7374
> --- /dev/null
> +++ b/ci/check-whitespace.sh
> @@ -0,0 +1,16 @@
> +#! /bin/sh
> +#
> +# Check that commits after a specified point do not contain new or modified
> +# lines with whitespace errors.
> +#
> +
> +baseSha=${1}

Two nits: first, I wouldn't call it "sha" because it really is a commit
ID that may or may not be SHA if we were ever to grow a hash function
that is not SHA. So "baseCommit" would be more descriptive.

Second, our shell variables are typically written in all-uppercase. So
that'd make it "BASE_COMMIT".

> +git log --check --pretty=format:"---% h% s" ${baseSha}..

Nit: there's no need for the curly braces here. Also, let's quote the
value.

Patrick

> +if test $? -ne 0
> +then
> +	echo "A whitespace issue was found in one or more of the commits."
> +	echo "Run the following command to resolve whitespace issues:"
> +	echo "\tgit rebase --whitespace=fix ${baseSha}"
> +	exit 2
> +fi
> -- 
> 2.44.0
> 
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2024-04-30  5:04 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-30  0:33 [PATCH 0/2] Add GitLab CI to check for whitespace errors Justin Tobler
2024-04-30  0:33 ` [PATCH 1/2] ci: pre-collapse GitLab CI sections Justin Tobler
2024-04-30  0:33 ` [PATCH 2/2] gitlab-ci: add whitespace error check Justin Tobler
2024-04-30  1:59   ` James Liu
2024-04-30  3:01     ` Justin Tobler
2024-04-30  5:04       ` Patrick Steinhardt
2024-04-30  5:04   ` Patrick Steinhardt [this message]
2024-04-30 12:14     ` Taylor Blau
2024-04-30 14:00     ` Justin Tobler
2024-04-30 14:05       ` Patrick Steinhardt
2024-04-30 14:41         ` Justin Tobler
2024-04-30 14:45           ` Patrick Steinhardt
2024-04-30 14:58             ` Justin Tobler
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   ` [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
2024-05-03 16:49         ` Junio C Hamano
2024-05-03 17:59           ` Patrick Steinhardt
2024-05-04  6:51             ` Chris Torek
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
2024-05-02 19:38   ` [PATCH v2 5/5] gitlab-ci: add whitespace error check 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 15:39     ` Justin Tobler
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     ` [PATCH v3 3/5] ci: separate whitespace check script 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
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
2024-05-07  4:12             ` Patrick Steinhardt
2024-05-07 18:06               ` Justin Tobler
2024-05-07 18:12                 ` Patrick Steinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZjB77nSMou0ssu-V@tanuki \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=jltobler@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).