From: Karthik Nayak <karthik.188@gmail.com>
To: karthik.188@gmail.com
Cc: chriscool@tuxfamily.org, git@vger.kernel.org, jltobler@gmail.com,
phillip.wood123@gmail.com, gitster@pobox.com
Subject: [PATCH v4 0/8] clang-format: add more rules and enable on CI
Date: Mon, 15 Jul 2024 11:30:39 +0200 [thread overview]
Message-ID: <20240715093047.49321-1-karthik.188@gmail.com> (raw)
In-Reply-To: <20240713134518.773053-1-karthik.188@gmail.com>
This is v3 of my series to add clang-format to the CI.
The series was mostly inspired by a patch sent recently to 'include
kh_foreach* macros in ForEachMacros' [1]. I was wondering why we don't
run the formatting on CI and reduce some of the workload of reviewers.
We have a '.clang-format' file to provide rules for code formatting.
The commits 1-5 aims to add more rules to the file while deprecating old
ones.
Commit 6 enables CI action on GitHub and GitLab to also check for the
code formatting. Currently, it is allowed to fail. This way we can build
confidence and fine tune the values as needed and finally enforce the
check in a future patch. I'm not well versed with GitHub workflows, and
I mostly tried to copy existing work there. Expecting some feedback in
that section!
Commit 7 fixes an existing issue with the 'check-whitespace' job, which
is failing as success in the GitLab CI.
Commit 8 adds the `RemoveBracesLLVM` only in the context of the CI. If we
decide against it, we could drop this commit from the series.
1: https://lore.kernel.org/git/4e7893f5-2dd9-46cf-8a64-cf780f4e1730@web.de/
Changes against v3:
- The job was actually failing on GitHub but showing a success since we added
the allow to fail clause. This was because the dependency wasn't installed.
Have fixed that in this version.
- Simplified the bash script in the GitLab job, thanks to Junio.
- Fixed a style issue with redirection.
- Added some more details to the commit messages.
Job running on:
- GitHub: https://github.com/KarthikNayak/git/actions/runs/9936188558/job/27443871938?pr=1
- GitLab: https://gitlab.com/gitlab-org/git/-/jobs/7340770469
Karthik Nayak (8):
clang-format: indent preprocessor directives after hash
clang-format: avoid spacing around bitfield colon
clang-format: ensure files end with newlines
clang-format: replace deprecated option with 'SpacesInParens'
clang-format: formalize some of the spacing rules
ci: run style check on GitHub and GitLab
check-whitespace: detect if no base_commit is provided
ci/style-check: add `RemoveBracesLLVM` to '.clang-format'
.clang-format | 36 +++++++++++++++++++++++++-----
.github/workflows/check-style.yml | 34 ++++++++++++++++++++++++++++
.gitlab-ci.yml | 37 ++++++++++++++++++++++++++++++-
ci/check-whitespace.sh | 10 +++++++--
ci/install-dependencies.sh | 6 ++++-
ci/run-style-check.sh | 21 ++++++++++++++++++
6 files changed, 135 insertions(+), 9 deletions(-)
create mode 100644 .github/workflows/check-style.yml
create mode 100755 ci/run-style-check.sh
Range-diff against v3:
1: 6cf91ffc86 = 1: 6cf91ffc86 clang-format: indent preprocessor directives after hash
2: beb002885f = 2: beb002885f clang-format: avoid spacing around bitfield colon
3: 3031be43e7 = 3: 3031be43e7 clang-format: ensure files end with newlines
4: bc1550e300 = 4: bc1550e300 clang-format: replace deprecated option with 'SpacesInParens'
5: 4586c0094b = 5: 4586c0094b clang-format: formalize some of the spacing rules
6: c18cb23369 ! 6: f8eba92c0c ci: run style check on GitHub and GitLab
@@ Commit message
this job to fail, so we can validate if this is useful and eventually
enforce it.
- For GitLab, we use the 'CI_MERGE_REQUEST_TARGET_BRANCH_SHA' variable by
- default to obtain the base SHA of the merged pipeline (which is only
- available for merged pipelines [1]). Otherwise we use the
+ For GitHub, we allow the job to pass by adding 'continue-on-error: true'
+ to the workflow. This means the job would show as passed, even if the
+ style check failed. To know the status of the job, users have to
+ manually check the logs.
+
+ For GitLab, we allow the job to pass by adding 'allow_failure: true', to
+ the job. Unlike GitHub, here the job will show as failed with a yellow
+ warning symbol, but the pipeline would still show as passed.
+
+ Also for GitLab, we use the 'CI_MERGE_REQUEST_TARGET_BRANCH_SHA'
+ variable by default to obtain the base SHA of the merged pipeline (which
+ is only available for merged pipelines [1]). Otherwise we use the
'CI_MERGE_REQUEST_DIFF_BASE_SHA' variable.
[1]: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html#predefined-variables-for-merge-request-pipelines
+ Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
## .github/workflows/check-style.yml (new) ##
@@ .github/workflows/check-style.yml (new)
+
+jobs:
+ check-style:
++ env:
++ CC: clang
++ jobname: ClangFormat
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+
++ - run: ci/install-dependencies.sh
++
+ - name: git clang-format
+ continue-on-error: true
+ id: check_out
@@ .gitlab-ci.yml: check-whitespace:
+ allow_failure: true
+ variables:
+ CC: clang
++ jobname: ClangFormat
+ before_script:
+ - ./ci/install-dependencies.sh
+ # Since $CI_MERGE_REQUEST_TARGET_BRANCH_SHA is only defined for merged
@@ .gitlab-ci.yml: check-whitespace:
+ # be defined in all pipelines.
+ script:
+ - |
-+ if test -n "$CI_MERGE_REQUEST_TARGET_BRANCH_SHA"
-+ then
-+ ./ci/run-style-check.sh "$CI_MERGE_REQUEST_TARGET_BRANCH_SHA"
-+ elif test -n "$CI_MERGE_REQUEST_DIFF_BASE_SHA"
++ R=${CI_MERGE_REQUEST_TARGET_BRANCH_SHA-${CI_MERGE_REQUEST_DIFF_BASE_SHA?}}
++
++ if test -z "$R"
+ then
-+ ./ci/run-style-check.sh "$CI_MERGE_REQUEST_DIFF_BASE_SHA"
-+ else
-+ echo "CI_MERGE_REQUEST_DIFF_BASE_SHA should always exist!"; exit 1
++ echo "CI_MERGE_REQUEST_DIFF_BASE_SHA should always exist!"
++ exit 1
+ fi
++ ./ci/run-style-check.sh "$R"
+ rules:
+ - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
+
@@ ci/install-dependencies.sh: ubuntu-*)
mkdir --parents "$CUSTOM_PATH"
wget --quiet --directory-prefix="$CUSTOM_PATH" \
+@@ ci/install-dependencies.sh: macos-*)
+ esac
+
+ case "$jobname" in
++ClangFormat)
++ sudo apt-get -q update
++ sudo apt-get -q -y install clang-format
++ ;;
+ StaticAnalysis)
+ sudo apt-get -q update
+ sudo apt-get -q -y install coccinelle libcurl4-openssl-dev libssl-dev \
## ci/run-style-check.sh (new) ##
@@
7: 4d08c570bb ! 7: 477419fc6b check-whitespace: detect if no base_commit is provided
@@ Commit message
[1]: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html#predefined-variables-for-merge-request-pipelines
+ Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
## .gitlab-ci.yml ##
@@ .gitlab-ci.yml: check-whitespace:
script:
- - ./ci/check-whitespace.sh "$CI_MERGE_REQUEST_TARGET_BRANCH_SHA"
+ - |
-+ if test -n "$CI_MERGE_REQUEST_TARGET_BRANCH_SHA"
-+ then
-+ ./ci/check-whitespace.sh "$CI_MERGE_REQUEST_TARGET_BRANCH_SHA"
-+ elif test -n "$CI_MERGE_REQUEST_DIFF_BASE_SHA"
++ R=${CI_MERGE_REQUEST_TARGET_BRANCH_SHA-${CI_MERGE_REQUEST_DIFF_BASE_SHA?}}
++
++ if test -z "$R"
+ then
-+ ./ci/check-whitespace.sh "$CI_MERGE_REQUEST_DIFF_BASE_SHA"
-+ else
-+ echo "CI_MERGE_REQUEST_DIFF_BASE_SHA should always exist!"; exit 1
++ echo "CI_MERGE_REQUEST_DIFF_BASE_SHA should always exist!"
++ exit 1
+ fi
++ ./ci/check-whitespace.sh "$R"
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
8: 2b39431f93 ! 8: 50007c17da ci/style-check: add `RemoveBracesLLVM` to '.clang-format'
@@ Commit message
its efficacy and decide if we want to add it to '.clang-format' or
retract it entirely.
+ A more ideal solution would be if 'clang-format' allowed us to append
+ rules to the existing '.clang-format' when invoked. But such an option
+ does not exist. Since modifying the in-tree '.clang-format' is only done
+ on the CI job for style-check and doesn't affect any other jobs and is
+ not persisted in any ways, this hack should be okay.
+
[1]: https://clang.llvm.org/docs/ClangFormatStyleOptions.html#removebracesllvm
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
@@ ci/run-style-check.sh
+# While also ensuring that end-users are not affected directly.
+#
+# [1]: https://clang.llvm.org/docs/ClangFormatStyleOptions.html#removebracesllvm
-+echo "RemoveBracesLLVM: true" >> .clang-format
++echo "RemoveBracesLLVM: true" >>.clang-format
+
git clang-format --style file --diff --extensions c,h "$baseCommit"
--
2.45.2
next prev parent reply other threads:[~2024-07-15 9:30 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
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 ` Karthik Nayak [this message]
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=20240715093047.49321-1-karthik.188@gmail.com \
--to=karthik.188@gmail.com \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jltobler@gmail.com \
--cc=phillip.wood123@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).