From: Junio C Hamano <gitster@pobox.com>
To: Karthik Nayak <karthik.188@gmail.com>
Cc: git@vger.kernel.org, jltobler@gmail.com, chriscool@tuxfamily.org
Subject: Re: [PATCH 7/8] ci: run style check on GitHub and GitLab
Date: Mon, 08 Jul 2024 10:15:35 -0700 [thread overview]
Message-ID: <xmqqr0c3hkjs.fsf@gitster.g> (raw)
In-Reply-To: <20240708092317.267915-8-karthik.188@gmail.com> (Karthik Nayak's message of "Mon, 8 Jul 2024 11:23:15 +0200")
Karthik Nayak <karthik.188@gmail.com> writes:
> We don't run style checks on our CI, even though we have a
> '.clang-format' setup in the repository. Let's add one, the job will
> validate only against the new commits added and will only run on merge
> requests.
I hope "against new commits" means what I think it does ;-) I am
worried about the case where a new commit touches a file that has
existing style violations but the commit does not make the situation
any worse at all.
OK, "git clang-format" is used to for this thing and it is designed
to address only lines that differ, so hopefully that would be good.
> Since we're introducing it for the first time, let's allow
> this job to fail, so we can validate if this is useful and eventually
> enforce it.
Very good idea.
> Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
> ---
> .github/workflows/check-style.yml | 29 +++++++++++++++++++++++++++++
> .gitlab-ci.yml | 12 ++++++++++++
> ci/install-dependencies.sh | 2 +-
> ci/run-style-check.sh | 8 ++++++++
> 4 files changed, 50 insertions(+), 1 deletion(-)
> create mode 100644 .github/workflows/check-style.yml
> create mode 100755 ci/run-style-check.sh
>
> diff --git a/.github/workflows/check-style.yml b/.github/workflows/check-style.yml
> new file mode 100644
> index 0000000000..27276dfe5e
> --- /dev/null
> +++ b/.github/workflows/check-style.yml
> @@ -0,0 +1,29 @@
> +name: check-style
> +
> +# Get the repository with all commits to ensure that we can analyze
> +# all of the commits contributed via the Pull Request.
> +
> +on:
> + pull_request:
> + types: [opened, synchronize]
> +
> +# Avoid unnecessary builds. Unlike the main CI jobs, these are not
> +# ci-configurable (but could be).
> +concurrency:
> + group: ${{ github.workflow }}-${{ github.ref }}
> + cancel-in-progress: true
> +
> +jobs:
> + check-style:
> + runs-on: ubuntu-latest
> + steps:
> + - uses: actions/checkout@v4
> + with:
> + fetch-depth: 0
> +
> + - name: git clang-format
> + continue-on-error: true
> + id: check_out
> + run: |
> + ./ci/run-style-check.sh \
> + "${{github.event.pull_request.base.sha}}"
> diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
> index 37b991e080..65fd261e5e 100644
> --- a/.gitlab-ci.yml
> +++ b/.gitlab-ci.yml
> @@ -123,6 +123,18 @@ check-whitespace:
> rules:
> - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
>
> +check-style:
> + image: ubuntu:latest
> + allow_failure: true
> + variables:
> + CC: clang
> + before_script:
> + - ./ci/install-dependencies.sh
> + script:
> + - ./ci/run-style-check.sh "$CI_MERGE_REQUEST_DIFF_BASE_SHA"
> + rules:
> + - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
> +
> documentation:
> image: ubuntu:latest
> variables:
> diff --git a/ci/install-dependencies.sh b/ci/install-dependencies.sh
> index 6ec0f85972..46fe12a690 100755
> --- a/ci/install-dependencies.sh
> +++ b/ci/install-dependencies.sh
> @@ -43,7 +43,7 @@ ubuntu-*)
> make libssl-dev libcurl4-openssl-dev libexpat-dev wget sudo default-jre \
> tcl tk gettext zlib1g-dev perl-modules liberror-perl libauthen-sasl-perl \
> libemail-valid-perl libio-pty-perl libio-socket-ssl-perl libnet-smtp-ssl-perl libdbd-sqlite3-perl libcgi-pm-perl \
> - ${CC_PACKAGE:-${CC:-gcc}} $PYTHON_PACKAGE
> + ${CC_PACKAGE:-${CC:-gcc}} $PYTHON_PACKAGE clang-format
>
> mkdir --parents "$CUSTOM_PATH"
> wget --quiet --directory-prefix="$CUSTOM_PATH" \
> diff --git a/ci/run-style-check.sh b/ci/run-style-check.sh
> new file mode 100755
> index 0000000000..9d4c4089c1
> --- /dev/null
> +++ b/ci/run-style-check.sh
> @@ -0,0 +1,8 @@
> +#!/usr/bin/env sh
Under ci/ hierarchy we are very inconsistent. Most use the bog
standard "#!/bin/sh" (which is my preference by the way), but
see what we have here right now:
$ git grep -e '^#![a-z/]*/bin/[a-z]*sh' -e '^#![a-z/]*bin/env ' ci |
sort -t: -k2
ci/check-directional-formatting.bash:#!/bin/bash
ci/install-dependencies.sh:#!/bin/sh
ci/make-test-artifacts.sh:#!/bin/sh
ci/mount-fileshare.sh:#!/bin/sh
ci/print-test-failures.sh:#!/bin/sh
ci/run-build-and-minimal-fuzzers.sh:#!/bin/sh
ci/run-build-and-tests.sh:#!/bin/sh
ci/run-docker-build.sh:#!/bin/sh
ci/run-docker.sh:#!/bin/sh
ci/run-static-analysis.sh:#!/bin/sh
ci/run-test-slice.sh:#!/bin/sh
ci/util/extract-trash-dirs.sh:#!/bin/sh
ci/check-whitespace.sh:#!/usr/bin/env bash
ci/test-documentation.sh:#!/usr/bin/env bash
Unless you have a strong reason to suspect that in your CI
environment /bin/sh is an unusuably broken shell, please do not
spread the inconsistencies.
I think the consensus from the last discussion we had was to allow
scripts that rely on bash-isms to say "#!/usr/bin/env bash" because
we know /bin/sh can legitimately be not bash and we assume bash may
not be installed as /bin/bash. As all of them would run in the CI
environment that we have some control over what required packages
are installed at what path, it is OK to assume that "bash" would be
found on the $PATH by using /usr/bin/env (but it does assume
everybody installs "env" there, not /bin/env or /usr/local/bin/env,
with a bit of chicken-and-egg issue).
> +#
> +# Perform style check
> +#
> +
> +baseCommit=$1
> +
> +git clang-format --style file --diff --extensions c,h "$baseCommit"
OK, "git clang-format" compares the working tree with the named
commit, so if we have the tip of the topic branch proposed to be
merged checked out and compare it with the base commit of the topic,
that would give us exactly what we want. Nice.
Thanks.
next prev parent reply other threads:[~2024-07-08 17:15 UTC|newest]
Thread overview: 127+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-08 9:23 [PATCH 0/8] clang-format: add more rules and enable on CI Karthik Nayak
2024-07-08 9:23 ` [PATCH 1/8] clang-format: indent preprocessor directives after hash Karthik Nayak
2024-07-08 10:08 ` Chris Torek
2024-07-08 16:22 ` Junio C Hamano
2024-07-08 20:33 ` Karthik Nayak
2024-07-08 16:27 ` Re* " Junio C Hamano
2024-07-08 9:23 ` [PATCH 2/8] clang-format: avoid spacing around bitfield colon Karthik Nayak
2024-07-08 9:23 ` [PATCH 3/8] clang-format: ensure files end with newlines Karthik Nayak
2024-07-08 16:32 ` Junio C Hamano
2024-07-08 9:23 ` [PATCH 4/8] clang-format: replace deprecated option with 'SpacesInParens' Karthik Nayak
2024-07-08 16:32 ` Junio C Hamano
2024-07-08 9:23 ` [PATCH 5/8] clang-format: avoid braces on simple single-statement bodies Karthik Nayak
2024-07-08 16:48 ` Junio C Hamano
2024-07-08 20:25 ` Karthik Nayak
2024-07-12 15:24 ` Phillip Wood
2024-07-13 12:30 ` Karthik Nayak
2024-07-13 13:58 ` phillip.wood123
2024-07-13 14:16 ` Karthik Nayak
2024-07-08 9:23 ` [PATCH 6/8] clang-format: formalize some of the spacing rules Karthik Nayak
2024-07-08 16:54 ` Junio C Hamano
2024-07-08 17:26 ` Karthik Nayak
2024-07-08 16:56 ` Justin Tobler
2024-07-08 17:27 ` Karthik Nayak
2024-07-08 20:53 ` Eric Sunshine
2024-07-10 13:36 ` Karthik Nayak
2024-07-08 9:23 ` [PATCH 7/8] ci: run style check on GitHub and GitLab Karthik Nayak
2024-07-08 17:15 ` Junio C Hamano [this message]
2024-07-08 21:05 ` Karthik Nayak
2024-07-08 22:52 ` Re* " Junio C Hamano
2024-07-08 23:17 ` Justin Tobler
2024-07-09 0:56 ` brian m. carlson
2024-07-08 18:10 ` Justin Tobler
2024-07-08 21:16 ` Karthik Nayak
2024-07-09 0:22 ` Justin Tobler
2024-07-09 8:44 ` Karthik Nayak
2024-07-09 14:44 ` Justin Tobler
2024-07-10 13:38 ` Karthik Nayak
2024-07-08 9:23 ` [PATCH 8/8] check-whitespace: detect if no base_commit is provided Karthik Nayak
2024-07-08 10:18 ` Chris Torek
2024-07-08 10:35 ` Georg Pfuetzenreuter
2024-07-08 10:42 ` Chris Torek
2024-07-08 17:13 ` Karthik Nayak
2024-07-08 17:19 ` Junio C Hamano
2024-07-08 17:35 ` Junio C Hamano
2024-07-10 14:06 ` Karthik Nayak
2024-07-10 16:02 ` Junio C Hamano
2024-07-11 8:27 ` Karthik Nayak
2024-07-11 14:41 ` Junio C Hamano
2024-07-08 17:58 ` Justin Tobler
2024-07-10 14:12 ` Karthik Nayak
2024-07-08 10:06 ` [PATCH 0/8] clang-format: add more rules and enable on CI Chris Torek
2024-07-11 8:30 ` [PATCH v2 " Karthik Nayak
2024-07-11 8:30 ` [PATCH v2 1/8] clang-format: indent preprocessor directives after hash Karthik Nayak
2024-07-11 8:30 ` [PATCH v2 2/8] clang-format: avoid spacing around bitfield colon Karthik Nayak
2024-07-11 8:30 ` [PATCH v2 3/8] clang-format: ensure files end with newlines Karthik Nayak
2024-07-11 8:30 ` [PATCH v2 4/8] clang-format: replace deprecated option with 'SpacesInParens' Karthik Nayak
2024-07-11 8:30 ` [PATCH v2 5/8] clang-format: avoid braces on simple single-statement bodies Karthik Nayak
2024-07-11 16:40 ` Junio C Hamano
2024-07-12 8:48 ` Karthik Nayak
2024-07-12 15:09 ` Junio C Hamano
2024-07-12 15:29 ` Phillip Wood
2024-07-11 8:30 ` [PATCH v2 6/8] clang-format: formalize some of the spacing rules Karthik Nayak
2024-07-11 8:30 ` [PATCH v2 7/8] ci: run style check on GitHub and GitLab Karthik Nayak
2024-07-11 8:30 ` [PATCH v2 8/8] check-whitespace: detect if no base_commit is provided Karthik Nayak
2024-07-11 14:48 ` Justin Tobler
2024-07-11 16:16 ` Junio C Hamano
2024-07-12 8:51 ` Karthik Nayak
2024-07-12 15:12 ` Junio C Hamano
2024-07-11 18:11 ` [PATCH v2 0/8] clang-format: add more rules and enable on CI Junio C Hamano
2024-07-13 13:45 ` [PATCH v3 " Karthik Nayak
2024-07-13 13:45 ` [PATCH v3 1/8] clang-format: indent preprocessor directives after hash Karthik Nayak
2024-07-13 13:45 ` [PATCH v3 2/8] clang-format: avoid spacing around bitfield colon Karthik Nayak
2024-07-13 13:45 ` [PATCH v3 3/8] clang-format: ensure files end with newlines Karthik Nayak
2024-07-13 13:45 ` [PATCH v3 4/8] clang-format: replace deprecated option with 'SpacesInParens' Karthik Nayak
2024-07-13 13:45 ` [PATCH v3 5/8] clang-format: formalize some of the spacing rules Karthik Nayak
2024-07-13 13:45 ` [PATCH v3 6/8] ci: run style check on GitHub and GitLab Karthik Nayak
2024-07-13 15:47 ` Junio C Hamano
2024-07-13 13:45 ` [PATCH v3 7/8] check-whitespace: detect if no base_commit is provided Karthik Nayak
2024-07-13 13:45 ` [PATCH v3 8/8] ci/style-check: add `RemoveBracesLLVM` to '.clang-format' Karthik Nayak
2024-07-13 15:37 ` Junio C Hamano
2024-07-13 16:46 ` Karthik Nayak
2024-07-13 23:18 ` Ramsay Jones
2024-07-15 8:10 ` Karthik Nayak
2024-07-15 14:46 ` Junio C Hamano
2024-07-15 16:07 ` Karthik Nayak
2024-07-15 16:36 ` Junio C Hamano
2024-07-15 19:31 ` Karthik Nayak
2024-07-15 19:45 ` Junio C Hamano
2024-07-18 8:18 ` Karthik Nayak
2024-07-18 14:05 ` Junio C Hamano
2024-07-15 9:30 ` [PATCH v4 0/8] clang-format: add more rules and enable on CI Karthik Nayak
2024-07-15 9:30 ` [PATCH v4 1/8] clang-format: indent preprocessor directives after hash Karthik Nayak
2024-07-15 9:30 ` [PATCH v4 2/8] clang-format: avoid spacing around bitfield colon Karthik Nayak
2024-07-15 9:30 ` [PATCH v4 3/8] clang-format: ensure files end with newlines Karthik Nayak
2024-07-15 9:30 ` [PATCH v4 4/8] clang-format: replace deprecated option with 'SpacesInParens' Karthik Nayak
2024-07-15 9:30 ` [PATCH v4 5/8] clang-format: formalize some of the spacing rules Karthik Nayak
2024-07-15 9:30 ` [PATCH v4 6/8] ci: run style check on GitHub and GitLab Karthik Nayak
2024-07-15 9:30 ` [PATCH v4 7/8] check-whitespace: detect if no base_commit is provided Karthik Nayak
2024-07-15 9:30 ` [PATCH v4 8/8] ci/style-check: add `RemoveBracesLLVM` to '.clang-format' Karthik Nayak
2024-07-15 17:01 ` Junio C Hamano
2024-07-15 19:33 ` Karthik Nayak
2024-07-18 8:15 ` [PATCH v5 0/6] : add more rules and enable on CI Karthik Nayak
2024-07-18 8:16 ` [PATCH v5 1/6] clang-format: indent preprocessor directives after hash Karthik Nayak
2024-07-18 8:16 ` [PATCH v5 2/6] clang-format: avoid spacing around bitfield colon Karthik Nayak
2024-07-18 8:16 ` [PATCH v5 3/6] clang-format: formalize some of the spacing rules Karthik Nayak
2024-07-18 8:16 ` [PATCH v5 4/6] ci: run style check on GitHub and GitLab Karthik Nayak
2024-07-18 14:56 ` Junio C Hamano
2024-07-18 16:04 ` Junio C Hamano
2024-07-18 8:16 ` [PATCH v5 5/6] check-whitespace: detect if no base_commit is provided Karthik Nayak
2024-07-18 15:00 ` Junio C Hamano
2024-07-19 8:33 ` Karthik Nayak
2024-07-19 15:03 ` Junio C Hamano
2024-07-22 7:22 ` Karthik Nayak
2024-07-18 8:16 ` [PATCH v5 6/6] ci/style-check: add `RemoveBracesLLVM` in CI job Karthik Nayak
2024-07-18 15:09 ` [PATCH v5 0/6] : add more rules and enable on CI Junio C Hamano
2024-07-23 8:21 ` [PATCH v6 0/6] clang-format: " Karthik Nayak
2024-07-23 8:21 ` [PATCH v6 1/6] clang-format: indent preprocessor directives after hash Karthik Nayak
2024-07-24 6:50 ` Patrick Steinhardt
2024-07-24 8:55 ` Karthik Nayak
2024-07-23 8:21 ` [PATCH v6 2/6] clang-format: avoid spacing around bitfield colon Karthik Nayak
2024-07-23 8:21 ` [PATCH v6 3/6] clang-format: formalize some of the spacing rules Karthik Nayak
2024-07-23 8:21 ` [PATCH v6 4/6] ci: run style check on GitHub and GitLab Karthik Nayak
2024-07-23 8:21 ` [PATCH v6 5/6] check-whitespace: detect if no base_commit is provided Karthik Nayak
2024-07-23 8:21 ` [PATCH v6 6/6] ci/style-check: add `RemoveBracesLLVM` in CI job Karthik Nayak
2025-06-19 15:16 ` Junio C Hamano
2025-06-19 20:25 ` Karthik Nayak
2025-06-20 0:02 ` Junio C Hamano
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=xmqqr0c3hkjs.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=jltobler@gmail.com \
--cc=karthik.188@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 NNTP newsgroup(s).