[PATCH 2/2] gitlab-ci: add whitespace error check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

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@xxxxxxxxx>
---
 .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
+  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}
+
+git log --check --pretty=format:"---% h% s" ${baseSha}..
+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





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux